This commit is contained in:
xds
2025-10-31 15:31:55 +03:00
parent 040da34ff7
commit 7972ea0fdf
117 changed files with 3691 additions and 2013 deletions

View File

@@ -1,12 +1,9 @@
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
@@ -17,36 +14,30 @@ class UserService(val userRepo: UserRepo) {
@Cacheable("users", key = "#username")
suspend fun getByUsername(username: String): User {
return userRepo.findByUsername(username).awaitSingleOrNull()
?: throw NotFoundException("User with username: $username not found")
fun getByUsername(username: String): User {
return userRepo.findByUsername(username) ?: 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")
fun getById(id: Int): User {
return userRepo.findById(id) ?: 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")
fun getUserByTelegramId(telegramId: Long): User {
return userRepo.findByTgId(telegramId.toString())?: 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")
fun getByUserNameWoPass(username: String): User {
return userRepo.findByUsername(username) ?: throw NotFoundException("User with username: $username not found")
}
@Cacheable("usersList")
suspend fun getUsers(): List<User> {
fun getUsers(): List<User> {
return userRepo.findAll()
.collectList()
.awaitSingle()
}
}