From abf873d554011d51053e39d2291c0eb21fd4b955 Mon Sep 17 00:00:00 2001 From: ManHyuk Date: Tue, 23 Jan 2024 23:32:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat(#132):=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EC=88=98=EC=A0=95=20api=20=EB=B6=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/request/UpdateUserRequest.kt | 8 +++- .../api/user/controller/UserController.kt | 38 ++++++++++++++++--- .../raemian/api/user/service/UserService.kt | 18 +++++++-- .../io/raemian/storage/db/core/user/User.kt | 2 +- 4 files changed, 56 insertions(+), 10 deletions(-) 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..21f9a46e 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,11 @@ import java.time.LocalDate data class UpdateUserRequest( val nickname: String, val birth: LocalDate, - val username: String, ) + + +data class UpdateUserInfoRequest( + val nickname: String, + val birth: LocalDate, + val username: String +) \ No newline at end of file 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..6d4c94da 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,47 @@ 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, From f0eeeae05f7f014e6c6db6b7ba99ce0a68b916ee Mon Sep 17 00:00:00 2001 From: ManHyuk Date: Tue, 23 Jan 2024 23:40:52 +0900 Subject: [PATCH 2/2] chore(#132): lint --- .../api/auth/controller/request/UpdateUserRequest.kt | 5 ++--- .../kotlin/io/raemian/api/user/controller/UserController.kt | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) 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 21f9a46e..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 @@ -7,9 +7,8 @@ data class UpdateUserRequest( val birth: LocalDate, ) - data class UpdateUserInfoRequest( val nickname: String, val birth: LocalDate, - val username: String -) \ No newline at end of file + 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 6d4c94da..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 @@ -49,16 +49,14 @@ class UserController( @PutMapping("/users") fun updateFromMy( @AuthenticationPrincipal currentUser: CurrentUser, - @RequestBody updateUserInfoRequest: UpdateUserInfoRequest + @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 + birth = updateUserInfoRequest.birth, ) return ResponseEntity.ok().build() }