Skip to content

Commit

Permalink
[KAN-37] 유저 - 유저 수정 API 개발 (#22)
Browse files Browse the repository at this point in the history
* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발

* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발 (패스워드 재설정 기능 추가)

* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발 (패스워드 재설정 기능 추가)

* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발 (네이밍 변경

* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발 (네이밍 변경

* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발 (네이밍 변경

* [KAN-34] 유저 - 이메일인증 메일 전송 API 개발 (네이밍 변경 (ktlint)

* [KAN-36] 유저 - 패스워드 업데이트 API 개발

* [KAN-37] 유저 - 유저 수정 API 개발
  • Loading branch information
sinkyoungdeok authored May 8, 2024
1 parent aa1f543 commit cbf29a4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/com/restaurant/be/user/domain/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.restaurant.be.user.domain.entity

import com.restaurant.be.common.converter.SeparatorConverter
import com.restaurant.be.common.password.PasswordService
import com.restaurant.be.user.presentation.dto.UpdateUserRequest
import javax.persistence.Column
import javax.persistence.Convert
import javax.persistence.Entity
Expand All @@ -14,7 +15,7 @@ import javax.persistence.Table
@Table(name = "users")
class User(
@Id
@Column(name = "user_id")
@Column
@GeneratedValue(strategy = GenerationType.AUTO)
var id: Long? = null,

Expand All @@ -30,9 +31,17 @@ class User(
var withdrawal: Boolean = false,

@Convert(converter = SeparatorConverter::class)
var roles: List<String> = listOf()
var roles: List<String> = listOf(),

@Column
var profileImageUrl: String
) {
fun updatePassword(password: String) {
this.password = password.run(PasswordService::hashPassword)
}

fun updateUser(request: UpdateUserRequest) {
this.nickname = request.nickname
this.profileImageUrl = request.profileImageUrl
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.restaurant.be.common.exception.NotEqualTokenException
import com.restaurant.be.common.exception.NotFoundUserEmailException
import com.restaurant.be.common.redis.RedisRepository
import com.restaurant.be.user.presentation.dto.UpdatePasswordRequest
import com.restaurant.be.user.presentation.dto.UpdateUserRequest
import com.restaurant.be.user.presentation.dto.UpdateUserResponse
import com.restaurant.be.user.presentation.dto.common.EmailSendType
import com.restaurant.be.user.repository.UserRepository
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -41,4 +43,14 @@ class UpdateUserService(
.lowercase(Locale.getDefault())}_token"
)
}

@Transactional
fun updateUser(request: UpdateUserRequest, email: String): UpdateUserResponse {
val user = userRepository.findByEmail(email)
?: throw NotFoundUserEmailException()
user.updateUser(request)
userRepository.save(user)

return UpdateUserResponse(user)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.restaurant.be.user.presentation.controller

import com.restaurant.be.common.response.CommonResponse
import com.restaurant.be.user.domain.service.UpdateUserService
import com.restaurant.be.user.presentation.dto.UpdateUserRequest
import com.restaurant.be.user.presentation.dto.UpdateUserResponse
import io.swagger.annotations.Api
Expand All @@ -19,7 +20,9 @@ import javax.validation.Valid
@Api(tags = ["01. User Info"], description = "유저 서비스")
@RestController
@RequestMapping("/api/v1/users")
class UpdateUserController {
class UpdateUserController(
private val updateUserService: UpdateUserService
) {

@PatchMapping
@PreAuthorize("hasRole('USER')")
Expand All @@ -34,6 +37,7 @@ class UpdateUserController {
@Valid @RequestBody
request: UpdateUserRequest
): CommonResponse<UpdateUserResponse> {
updateUserService.updateUser(request, principal.name)
return CommonResponse.success()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ data class SignInUserRequest(
@NotBlank(message = "비밀번호를 입력해 주세요.")
@ApiModelProperty(value = "비밀번호", example = "test12!@", required = true)
val password: String
) {

fun toEntity() = User(
email = email,
password = password
)
}
)

data class SignInUserResponse(
@Schema(description = "유저 정보")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ data class SignUpUserRequest(
email = email,
password = password.run(PasswordService::hashPassword),
nickname = nickname,
roles = listOf(Role.ROLE_USER.toString())
roles = listOf(Role.ROLE_USER.toString()),
profileImageUrl = profileImageUrl
)
}

Expand All @@ -50,8 +51,10 @@ data class SignUpUserResponse(
) {
constructor(user: User, token: Token) : this(
userDto = UserDto(
id = user.id ?: 0,
email = user.email,
nickname = user.nickname
nickname = user.nickname,
profileImageUrl = user.profileImageUrl
),
token = token
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.restaurant.be.user.presentation.dto

import com.restaurant.be.user.domain.entity.User
import com.restaurant.be.user.presentation.dto.common.UserDto
import io.swagger.annotations.ApiModelProperty
import io.swagger.v3.oas.annotations.media.Schema
Expand All @@ -21,4 +22,13 @@ data class UpdateUserRequest(
data class UpdateUserResponse(
@Schema(description = "유저 정보")
val userDto: UserDto
)
) {
constructor(user: User) : this(
userDto = UserDto(
id = user.id ?: 0,
email = user.email,
nickname = user.nickname,
profileImageUrl = user.profileImageUrl
)
)
}

0 comments on commit cbf29a4

Please sign in to comment.