diff --git a/backend/application/api/src/main/kotlin/io/raemian/api/auth/controller/request/UpdateUserRequest.kt b/backend/application/api/src/main/kotlin/io/raemian/api/auth/controller/request/UpdateUserRequest.kt index c48a2e50..6d795ad7 100644 --- a/backend/application/api/src/main/kotlin/io/raemian/api/auth/controller/request/UpdateUserRequest.kt +++ b/backend/application/api/src/main/kotlin/io/raemian/api/auth/controller/request/UpdateUserRequest.kt @@ -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, ) diff --git a/backend/application/api/src/main/kotlin/io/raemian/api/user/controller/UserController.kt b/backend/application/api/src/main/kotlin/io/raemian/api/user/controller/UserController.kt index 2399f3ac..571635e3 100644 --- a/backend/application/api/src/main/kotlin/io/raemian/api/user/controller/UserController.kt +++ b/backend/application/api/src/main/kotlin/io/raemian/api/user/controller/UserController.kt @@ -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 @@ -31,20 +32,45 @@ class UserController( @Operation(summary = "유저 온보딩 이후 정보 업데이트 API") @PutMapping("/my") - fun update( + fun updateBaseInfo( @AuthenticationPrincipal currentUser: CurrentUser, @RequestBody updateUserRequest: UpdateUserRequest, ): ResponseEntity { - 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 { + 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() diff --git a/backend/application/api/src/main/kotlin/io/raemian/api/user/service/UserService.kt b/backend/application/api/src/main/kotlin/io/raemian/api/user/service/UserService.kt index 86cf897a..32e7d9ad 100644 --- a/backend/application/api/src/main/kotlin/io/raemian/api/user/service/UserService.kt +++ b/backend/application/api/src/main/kotlin/io/raemian/api/user/service/UserService.kt @@ -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) } diff --git a/backend/storage/db-core/src/main/kotlin/io/raemian/storage/db/core/user/User.kt b/backend/storage/db-core/src/main/kotlin/io/raemian/storage/db/core/user/User.kt index 08cca9b7..7e6adee3 100644 --- a/backend/storage/db-core/src/main/kotlin/io/raemian/storage/db/core/user/User.kt +++ b/backend/storage/db-core/src/main/kotlin/io/raemian/storage/db/core/user/User.kt @@ -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,