Skip to content

Commit

Permalink
Add Feature Validate Nickname Duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Diger committed Dec 26, 2023
1 parent ebb662c commit 3152b21
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatever.raisedragon.applicationservice

import com.whatever.raisedragon.controller.user.UserNicknameDuplicatedResponse
import com.whatever.raisedragon.controller.user.UserRetrieveResponse
import com.whatever.raisedragon.domain.user.UserService
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -33,4 +34,12 @@ class UserApplicationService(
fun delete(id: Long) {
userService.softDelete(id)
}

fun isNicknameDuplicated(
nickname: String
): UserNicknameDuplicatedResponse {
return UserNicknameDuplicatedResponse(
nicknameIsDuplicated = userService.isNicknameDuplicated(nickname)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class SecurityConfig(
// Auth endpoints
"/v1/auth/**",
// don't need an authorization
"/v1/goal/*/simple"
"/v1/goal/*/simple",
"/v1/user/nickname"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ class UserController(
private val userApplicationService: UserApplicationService
) {

@Operation(summary = "Validate User Nickname API", description = "닉네임 중복 검증")
@PostMapping("/nickname")
fun validateNickname(
@RequestBody userNicknameDuplicatedRequest: UserNicknameDuplicatedRequest
): Response<UserNicknameDuplicatedResponse> {
return Response.success(
userApplicationService.isNicknameDuplicated(
nickname = userNicknameDuplicatedRequest.nickname
)
)
}

@Operation(summary = "Request User retrieve API", description = "요청한 사용자를 조회합니다.")
@GetMapping
fun retrieveMe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ data class UserLoginResponse(

@Schema(description = "Refresh Token")
val refreshToken: String,
)

@Schema(description = "[Response] 유저 닉네임 중복체크")
data class UserNicknameDuplicatedRequest(
@Schema(description = "닉네임")
val nickname: String,
)

@Schema(description = "[Response] 유저 닉네임 중복체크")
data class UserNicknameDuplicatedResponse(
@Schema(description = "닉네임 변경 이력")
val nicknameIsDuplicated: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,3 @@ data class Nickname(
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository
@Repository
interface UserRepository : JpaRepository<UserEntity, Long> {
fun findByOauthTokenPayload(payload: String): UserEntity?

fun existsByNickname(nickname: Nickname): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class UserService(
return userRepository.findAllById(ids).map { it.toDto() }
}

fun isNicknameDuplicated(nickname: String): Boolean {
return userRepository.existsByNickname(Nickname(nickname))
}

@Transactional
fun create(user: User): User {
return userRepository.save(user.fromDto()).toDto()
Expand Down

0 comments on commit 3152b21

Please sign in to comment.