Skip to content

Commit

Permalink
Merge pull request #134 from depromeet/develop
Browse files Browse the repository at this point in the history
merge develop to main
  • Loading branch information
ManHyuk authored Jan 23, 2024
2 parents 07eae27 + 701527d commit 00f1a5b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ import java.time.LocalDate
data class UpdateUserRequest(
val nickname: String,
val birth: LocalDate,
)

data class UpdateUserInfoRequest(
val nickname: String,
val birth: LocalDate,
val username: String,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.raemian.api.user.controller

import io.raemian.api.auth.controller.request.UpdateUserInfoRequest
import io.raemian.api.auth.controller.request.UpdateUserRequest
import io.raemian.api.auth.domain.CurrentUser
import io.raemian.api.lifemap.LifeMapService
Expand Down Expand Up @@ -31,20 +32,45 @@ class UserController(

@Operation(summary = "유저 온보딩 이후 정보 업데이트 API")
@PutMapping("/my")
fun update(
fun updateBaseInfo(
@AuthenticationPrincipal currentUser: CurrentUser,
@RequestBody updateUserRequest: UpdateUserRequest,
): ResponseEntity<Void> {
val isDuplicated = userService.isDuplicatedUsername(updateUserRequest.username)
userService.updateBaseInfo(
id = currentUser.id,
nickname = updateUserRequest.nickname,
birth = updateUserRequest.birth,
)

return ResponseEntity.ok().build()
}

@Operation(summary = "마이페이지 정보 업데이트 API")
@PutMapping("/users")
fun updateFromMy(
@AuthenticationPrincipal currentUser: CurrentUser,
@RequestBody updateUserInfoRequest: UpdateUserInfoRequest,
): ResponseEntity<Void> {
val user = userService.getUserById(currentUser.id)
if (user.username == updateUserInfoRequest.username) {
userService.updateBaseInfo(
id = currentUser.id,
nickname = updateUserInfoRequest.nickname,
birth = updateUserInfoRequest.birth,
)
return ResponseEntity.ok().build()
}

val isDuplicated = userService.isDuplicatedUsername(updateUserInfoRequest.username)
if (isDuplicated) {
return ResponseEntity.status(409).build()
}

userService.update(
id = currentUser.id,
nickname = updateUserRequest.nickname,
birth = updateUserRequest.birth,
username = updateUserRequest.username,
nickname = updateUserInfoRequest.nickname,
birth = updateUserInfoRequest.birth,
username = updateUserInfoRequest.username,
)

return ResponseEntity.ok().build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,30 @@ class UserService(
return UserDTO.of(user)
}

fun update(id: Long, nickname: String, birth: LocalDate, username: String): UserDTO {
fun updateBaseInfo(id: Long, nickname: String, birth: LocalDate): UserDTO {
val user = userRepository.getById(id)

val updated = user.updateInfo(
val updated = user.updateBaseInfo(
nickname = nickname,
birth = birth,
username = username,
)

return UserDTO.of(userRepository.save(updated))
}

fun update(id: Long, nickname: String, birth: LocalDate, username: String): UserDTO {
val user = userRepository.getById(id)

val updated = user
.updateBaseInfo(
nickname = nickname,
birth = birth,
)
.updateUsername(username)

return UserDTO.of(userRepository.save(updated))
}

fun delete(id: Long) {
userRepository.deleteById(id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class User(
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
) : BaseEntity() {
fun updateInfo(nickname: String, birth: LocalDate, username: String): User {
fun updateBaseInfo(nickname: String, birth: LocalDate): User {
return User(
email = email,
nickname = nickname,
Expand Down

0 comments on commit 00f1a5b

Please sign in to comment.