Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge develop to main #134

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading