This commit is contained in:
xds
2025-10-16 15:06:20 +03:00
commit 040da34ff7
78 changed files with 3934 additions and 0 deletions

View File

@@ -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()
}
}