init
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package space.luminic.finance.services
|
||||
|
||||
|
||||
import kotlinx.coroutines.reactor.awaitSingle
|
||||
import kotlinx.coroutines.reactor.awaitSingleOrNull
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.cache.annotation.Cacheable
|
||||
import org.springframework.stereotype.Service
|
||||
import space.luminic.finance.mappers.UserMapper
|
||||
import space.luminic.finance.models.NotFoundException
|
||||
import space.luminic.finance.models.User
|
||||
import space.luminic.finance.repos.UserRepo
|
||||
|
||||
@Service
|
||||
class UserService(val userRepo: UserRepo) {
|
||||
val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
|
||||
@Cacheable("users", key = "#username")
|
||||
suspend fun getByUsername(username: String): User {
|
||||
return userRepo.findByUsername(username).awaitSingleOrNull()
|
||||
?: throw NotFoundException("User with username: $username not found")
|
||||
|
||||
}
|
||||
|
||||
suspend fun getById(id: String): User {
|
||||
return userRepo.findById(id).awaitSingleOrNull()
|
||||
?: throw NotFoundException("User with id: $id not found")
|
||||
}
|
||||
|
||||
suspend fun getUserByTelegramId(telegramId: Long): User {
|
||||
return userRepo.findByTgId(telegramId.toString()).awaitSingleOrNull()
|
||||
?: throw NotFoundException("User with telegramId: $telegramId not found")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Cacheable("users", key = "#username")
|
||||
suspend fun getByUserNameWoPass(username: String): User {
|
||||
return userRepo.findByUsernameWOPassword(username).awaitSingleOrNull()
|
||||
?: throw NotFoundException("User with username: $username not found")
|
||||
|
||||
}
|
||||
|
||||
@Cacheable("usersList")
|
||||
suspend fun getUsers(): List<User> {
|
||||
return userRepo.findAll()
|
||||
.collectList()
|
||||
.awaitSingle()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user