Skip to content

Commit

Permalink
Merge pull request #173 from PSR-Co/fix/#172-errorCode
Browse files Browse the repository at this point in the history
[fix] QA 에러 수정
  • Loading branch information
chaerlo127 authored Sep 13, 2023
2 parents 8021da0 + 890df22 commit e61b13d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class WebSecurityConfig(
c.requestMatchers("/users/eid").permitAll()
c.requestMatchers("/users/reissue").permitAll()
c.requestMatchers("/users/password-reset").permitAll()
c.requestMatchers("/users/phone/*/*").permitAll()
c.requestMatchers("/users/phone/*").permitAll()
c.requestMatchers("/users/email/search").permitAll()
c.requestMatchers("/users/password").permitAll()
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/com/psr/psr/user/controller/UserController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,26 @@ class UserController(
}

/**
* 휴대폰번호 유효
* 휴대폰번호 전송
*/
@PostMapping("/phone/check")
fun checkValidPhone(@RequestBody @Validated validPhoneReq: ValidPhoneReq) : BaseResponse<Any>{
userService.checkValidPhone(validPhoneReq)
return BaseResponse(BaseResponseCode.SUCCESS)
}

/**
* 회원가입을 위한 휴대폰번호 전송
*/
@PostMapping("/phone/check/signup")
fun checkValidPhoneForSignUp(@RequestBody @Validated validPhoneReq: ValidPhoneReq) : BaseResponse<Any>{
// 이미 있는 휴대폰 번호인지 확인
if(userService.checkDuplicatePhone(validPhoneReq.phone)) throw BaseException(BaseResponseCode.EXISTS_PHONE)
// 휴대폰 번호 전송
userService.checkValidPhone(validPhoneReq)
return BaseResponse(BaseResponseCode.SUCCESS)
}

/**
* 휴대폰 인증번호 조회
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.*
interface UserRepository: JpaRepository<User, Long> {
fun findByIdAndStatus(id: Long, status: String) : User?
fun existsByNicknameAndStatus(nickname: String, status: String): Boolean
fun existsByNicknameAndStatusAndIdNot(nickname: String, status: String, userId: Long) : Boolean
fun existsByPhoneAndStatus(phone: String, status: String): Boolean
fun existsByEmailAndStatus(nickname: String, status: String): Boolean
fun findByEmailAndStatus(email:String, status: String): Optional<User>
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/com/psr/psr/user/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class UserService(
return userRepository.existsByNicknameAndStatus(nickname, ACTIVE_STATUS)
}

// 휴대폰번호 중복체크
fun checkDuplicatePhone(phone: String): Boolean{
return userRepository.existsByPhoneAndStatus(phone, ACTIVE_STATUS)
}

// token 생성 extract method
private fun createToken(user: User, password: String): TokenDto {
val authenticationToken = UsernamePasswordAuthenticationToken(user.id.toString(), password)
Expand All @@ -140,8 +145,7 @@ class UserService(
fun patchProfile(user: User, profileReq: ProfileReq) {
// 닉네임이 변경이 되었으면
if(user.nickname != profileReq.nickname) {
// todo: 코드 변경 필요 -> 자기 자신 닉네임 제외
if(userRepository.existsByNicknameAndStatus(profileReq.nickname, ACTIVE_STATUS)) throw BaseException(EXISTS_NICKNAME)
if(userRepository.existsByNicknameAndStatusAndIdNot(profileReq.nickname, ACTIVE_STATUS, user.id!!)) throw BaseException(EXISTS_NICKNAME)
user.nickname = profileReq.nickname
}
// 프로필 이미지가 변경이 되었으면
Expand Down

0 comments on commit e61b13d

Please sign in to comment.