This commit is contained in:
xds
2025-10-31 17:11:40 +03:00
parent 5b9d2366db
commit d2458633db
11 changed files with 128 additions and 26 deletions

View File

@@ -4,18 +4,20 @@ import org.springframework.jdbc.core.RowMapper
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
import org.springframework.stereotype.Repository
import space.luminic.finance.models.User
@Repository
class UserRepoImpl(
private val jdbcTemplate: NamedParameterJdbcTemplate
) : UserRepo{
) : UserRepo {
private fun userRowMapper() = RowMapper { rs, _ ->
User(
id = rs.getInt("id"),
username = rs.getString("username"),
firstName = rs.getString("first_name"),
tgId = rs.getString("tg_id"),
tgId = rs.getLong("tg_id"),
tgUserName = rs.getString("tg_user_name"),
photoUrl = rs.getString("photo_url"),
password = rs.getString("password"),
isActive = rs.getBoolean("is_active"),
regDate = rs.getDate("reg_date").toLocalDate(),
@@ -41,11 +43,12 @@ class UserRepoImpl(
}
override fun findParticipantsBySpace(spaceId: Int): Set<User> {
val sql = "select * from finance.users u join finance.spaces_participants sp on sp.participants_id = u.id where sp.space_id = :spaceId"
val sql =
"select * from finance.users u join finance.spaces_participants sp on sp.participants_id = u.id where sp.space_id = :spaceId"
return jdbcTemplate.query(sql, mapOf("spaceId" to spaceId), userRowMapper()).toSet()
}
override fun findByTgId(tgId: String): User? {
override fun findByTgId(tgId: Long): User? {
val sql = """
select * from finance.users u where tg_id = :tgId
""".trimIndent()
@@ -53,13 +56,15 @@ class UserRepoImpl(
return jdbcTemplate.queryForObject(sql, params, userRowMapper())
}
override fun save(user: User): User {
val sql = "insert into finance.users(username, first_name, tg_id, tg_user_name, password, is_active, reg_date) values (:username, :firstname, :tg_id, :tg_user_name, :password, :isActive, :regDate) returning ID"
override fun create(user: User): User {
val sql =
"insert into finance.users(username, first_name, tg_id, tg_user_name, photo_url, password, is_active, reg_date) values (:username, :firstname, :tg_id, :tg_user_name, :photo_url :password, :isActive, :regDate) returning ID"
val params = mapOf(
"username" to user.username,
"firstname" to user.firstName,
"tg_id" to user.tgId,
"tg_user_name" to user.tgUserName,
"photo_url" to user.photoUrl,
"password" to user.password,
"isActive" to user.isActive,
"regDate" to user.regDate,