Skip to content

Commit

Permalink
Merge pull request #26 from DDD-Community/feature/POLABO-108
Browse files Browse the repository at this point in the history
fix(POLABO-108): 페이지네이션 정책 통일화 작업 2차
  • Loading branch information
dldmsql authored Aug 18, 2024
2 parents ab442d5 + 782ea97 commit 4a27c12
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class MyBoardService(private val boardJooqRepository: BoardJooqRepository) {
fun getMyBoards(userId: Long, page: Int, size: Int): PageDto<MyBoardDto.Companion.PageListRes> {
val data = this.boardJooqRepository.findAllByUserId(userId, page-1, size)
val totalCount = this.boardJooqRepository.selectTotalCountByUserId(userId)
val totalPage = totalCount.toInt() / size + 1

return PageDto(data, totalCount, totalPage, page, size)
return PageDto(data, totalCount, page, size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ddd.sonnypolabobe.domain.oauth.service.OauthService
import com.ddd.sonnypolabobe.domain.user.dto.UserDto
import com.ddd.sonnypolabobe.global.response.ApplicationResponse
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.bind.annotation.*

Expand All @@ -16,9 +17,12 @@ class OauthController(private val oauthService: OauthService) {
이미 가입된 회원이라면 로그인을 진행하고, 가입되지 않은 회원이라면 회원가입을 진행합니다.
요청 바디의 값이 변경되었습니다. - 2024.08.11
- birthDt, gender 필드는 프로필 수정에서 업데이트 가능합니다.
응답 DTO에 기본값 바인딩으로 채웠습니다.
""")
@PostMapping("/sign-in")
fun signIn(@RequestBody request: UserDto.Companion.CreateReq)
fun signIn(@RequestBody @Valid request: UserDto.Companion.CreateReq)
= ApplicationResponse.ok(this.oauthService.signIn(request))

@PutMapping("/re-issue")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ddd.sonnypolabobe.domain.oauth.service

import com.ddd.sonnypolabobe.domain.user.dto.GenderType
import com.ddd.sonnypolabobe.domain.user.dto.UserDto
import com.ddd.sonnypolabobe.domain.user.repository.UserJooqRepository
import com.ddd.sonnypolabobe.domain.user.token.dto.UserTokenDto
Expand Down Expand Up @@ -37,7 +38,11 @@ class OauthService(
)

this.userTokenRepository.updateByUserId(userToken)
return tokenRes.also { it.isNewUser = false }
return tokenRes.also { _ ->
tokenRes.isNewUser = false
tokenRes.birthDt = it.birthDt
tokenRes.gender = it.gender
}
} ?: run {
val userId = this.userRepository.insertOne(request)

Expand All @@ -58,7 +63,11 @@ class OauthService(
)

this.userTokenRepository.insertOne(userToken)
return tokenRes.also { it.isNewUser = true }
return tokenRes.also { _ ->
tokenRes.isNewUser = true
tokenRes.birthDt = null
tokenRes.gender = GenderType.NONE
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UserController(
보내는 값을 그대로 디비에 저장합니다.
""")
@PutMapping("/profile")
fun updateNickname(@RequestBody request: UserDto.Companion.UpdateReq)
fun updateProfile(@RequestBody request: UserDto.Companion.UpdateReq)
: ApplicationResponse<Nothing> {
val userInfoFromToken = SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
this.userService.updateProfile(request, userInfoFromToken.id)
Expand Down
47 changes: 35 additions & 12 deletions src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/UserDto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ddd.sonnypolabobe.domain.user.dto

import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.Email
import org.intellij.lang.annotations.RegExp
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.UserDetails
Expand All @@ -12,22 +14,23 @@ import java.util.stream.Collectors
class UserDto {
companion object {
data class CreateReq(
@field:Email
val email: String,
val nickName: String,
val birthDt : LocalDate?,
val gender : GenderType?
)
// val birthDt : LocalDate?,
// val gender : GenderType?
)

data class UpdateReq(
@JsonProperty("nickName")
val nickName : String,
val nickName: String,
@JsonProperty("birthDt")
val birthDt : LocalDate?,
val gender : GenderType?
val birthDt: LocalDate?,
val gender: GenderType?
)

data class CreateTokenReq(
val id : Long,
val id: Long,
val email: String,
val nickName: String
)
Expand All @@ -36,9 +39,27 @@ class UserDto {
val accessToken: String,
val refreshToken: String,
val expiredDate: Date,
var isNewUser : Boolean,
val nickName: String
)
var isNewUser: Boolean,
val nickName: String,
var birthDt: LocalDate?,
var gender: GenderType
) {
constructor(
accessToken: String,
refreshToken: String,
expiredDate: Date,
isNewUser: Boolean,
nickName: String
) : this(
accessToken,
refreshToken,
expiredDate,
isNewUser,
nickName,
null,
GenderType.NONE
)
}

data class ProfileRes(
val id: Long,
Expand All @@ -49,7 +70,7 @@ class UserDto {

data class WithdrawReq(
val type: WithdrawType,
val reason : String?
val reason: String?
)

data class Res(
Expand All @@ -58,7 +79,9 @@ class UserDto {
val nickName: String,
val yn: Boolean,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime?
val updatedAt: LocalDateTime?,
val birthDt: LocalDate?,
val gender : GenderType
) : UserDetails {
override fun getAuthorities(): MutableCollection<out GrantedAuthority> {
val roles = mutableListOf("ROLE_USER")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ddd.sonnypolabobe.domain.user.repository

import com.ddd.sonnypolabobe.domain.user.dto.GenderType
import com.ddd.sonnypolabobe.domain.user.dto.UserDto
import com.ddd.sonnypolabobe.global.util.DateConverter
import com.ddd.sonnypolabobe.jooq.polabo.enums.UserGender
Expand All @@ -17,16 +18,12 @@ class UserJooqRepositoryImpl(private val dslContext: DSLContext) : UserJooqRepos
jUser.NICK_NAME,
jUser.CREATED_AT,
jUser.YN,
jUser.BIRTH_DT,
jUser.GENDER
)
.values(
request.email,
request.nickName,
DateConverter.convertToKst(LocalDateTime.now()),
1,
request.birthDt,
UserGender.valueOf(request.gender?.name ?: UserGender.NONE.name)
).execute()
if(result == 0) throw Exception("Failed to insert user")

Expand All @@ -49,7 +46,9 @@ class UserJooqRepositoryImpl(private val dslContext: DSLContext) : UserJooqRepos
nickName = it.nickName!!,
yn = it.yn?.toInt() == 1,
createdAt = it.createdAt!!,
updatedAt = it.updatedAt
updatedAt = it.updatedAt,
birthDt = it.birthDt,
gender = GenderType.valueOf(it.gender?.name ?: GenderType.NONE.name)
)
}
}
Expand All @@ -67,7 +66,9 @@ class UserJooqRepositoryImpl(private val dslContext: DSLContext) : UserJooqRepos
nickName = it.nickName!!,
yn = it.yn?.toInt() == 1,
createdAt = it.createdAt!!,
updatedAt = it.updatedAt
updatedAt = it.updatedAt,
birthDt = it.birthDt,
gender = GenderType.valueOf(it.gender?.name ?: GenderType.NONE.name)
)
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/kotlin/com/ddd/sonnypolabobe/global/entity/PageDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ package com.ddd.sonnypolabobe.global.entity
data class PageDto<T>(
val data: List<T>,
val totalCount: Long,
val totalPage: Int,
var totalPage: Int,
val currentPage: Int,
val size : Int
)
) {

constructor(
data: List<T>,
totalCount: Long,
page: Int,
size: Int
) : this(data, totalCount, 0, page, size
)
init {
totalPage = totalCount.toInt() / size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DiscordApiClient(
.bodyValue(payload)
.retrieve()
.bodyToMono(Void::class.java)
.block()
.subscribe()
}

fun sendErrorTrace(errorCode: String, message: String?, trace: String) {
Expand All @@ -82,7 +82,7 @@ class DiscordApiClient(
field3["name"] = "메시지"
field3["value"] = message ?: "메시지 없음"

embedData["fields"] = listOf<Map<String, String>>(field1)
embedData["fields"] = listOf<Map<String, String>>(field1, field2, field3)

val payload: MutableMap<String, Any> = HashMap()
payload["embeds"] = arrayOf<Any>(embedData)
Expand All @@ -93,7 +93,7 @@ class DiscordApiClient(
.bodyValue(payload)
.retrieve()
.bodyToMono(Void::class.java)
.block()
.subscribe()
}

}

0 comments on commit 4a27c12

Please sign in to comment.