diff --git a/build.gradle.kts b/build.gradle.kts index 9c6016c..4425231 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -91,6 +91,15 @@ dependencies { /** aws */ implementation("com.amazonaws:aws-java-sdk-s3:${DependencyVersion.AWS_S3_SDK_VERSION}") + + /** etc */ + developmentOnly("org.springframework.boot:spring-boot-devtools") + val isMacOS = System.getProperty("os.name").startsWith("Mac OS X") + val architecture = System.getProperty("os.arch").lowercase() + if (isMacOS && architecture == "aarch64") { + developmentOnly("io.netty:netty-resolver-dns-native-macos:${DependencyVersion.MAC_DNS}:osx-aarch_64") + testImplementation("io.netty:netty-resolver-dns-native-macos:${DependencyVersion.MAC_DNS}:osx-aarch_64") + } } defaultTasks("bootRun") diff --git a/buildSrc/src/main/kotlin/DependencyVersion.kt b/buildSrc/src/main/kotlin/DependencyVersion.kt index 38884c2..7b735bc 100644 --- a/buildSrc/src/main/kotlin/DependencyVersion.kt +++ b/buildSrc/src/main/kotlin/DependencyVersion.kt @@ -6,6 +6,7 @@ object DependencyVersion { const val ARROW_FX = "1.2.4" const val KOTLIN_LOGGING = "6.0.9" const val LOGBACK_ENCODER = "7.4" + const val MAC_DNS = "4.1.111.Final" /** springdoc */ const val SPRINGDOC = "2.3.0" diff --git a/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt b/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt index c0e1a2a..8a2ef5d 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt @@ -11,6 +11,7 @@ import com.hero.alignlab.domain.user.domain.vo.OAuthProvider import com.hero.alignlab.domain.user.infrastructure.UserInfoRepository import com.hero.alignlab.domain.user.model.request.ChangeNicknameRequest import com.hero.alignlab.domain.user.model.response.ChangeNicknameResponse +import com.hero.alignlab.domain.user.model.response.CheckChangeNicknameResponse import com.hero.alignlab.domain.user.model.response.UserInfoResponse import com.hero.alignlab.exception.ErrorCode import com.hero.alignlab.exception.InvalidRequestException @@ -124,6 +125,37 @@ class UserInfoService( return ChangeNicknameResponse.from(updatedUserInfo) } + suspend fun checkChangeNickname( + user: AuthUser, + id: Long, + request: ChangeNicknameRequest, + ): CheckChangeNicknameResponse { + if (user.uid != id) { + return CheckChangeNicknameResponse( + valid = false, + reason = "유저 정보를 변경할 수 있는 권한이 없습니다.", + ) + } + + runCatching { + parZip( + { getUserByIdOrThrowSync(id) }, + { existsByNicknameAndIdNot(request.nickname, id) } + ) { userInfo, existsNickname -> + if (existsNickname) { + throw InvalidRequestException(ErrorCode.DUPLICATE_USER_NICKNAME_ERROR) + } + } + }.onFailure { e -> + return CheckChangeNicknameResponse( + valid = false, + reason = e.message ?: "닉네임 변경을 할 수 없습니다." + ) + } + + return CheckChangeNicknameResponse(valid = true) + } + suspend fun existsByNicknameAndIdNot(nickname: String, id: Long): Boolean { return withContext(Dispatchers.IO) { userInfoRepository.existsByNicknameAndIdNot(nickname, id) diff --git a/src/main/kotlin/com/hero/alignlab/domain/user/model/request/ChangeNicknameRequest.kt b/src/main/kotlin/com/hero/alignlab/domain/user/model/request/ChangeNicknameRequest.kt index 820a481..dfde805 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/user/model/request/ChangeNicknameRequest.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/user/model/request/ChangeNicknameRequest.kt @@ -1,5 +1,8 @@ package com.hero.alignlab.domain.user.model.request +import jakarta.validation.constraints.Size + data class ChangeNicknameRequest( + @field:Size(max = 200) val nickname: String, ) diff --git a/src/main/kotlin/com/hero/alignlab/domain/user/model/response/CheckChangeNicknameResponse.kt b/src/main/kotlin/com/hero/alignlab/domain/user/model/response/CheckChangeNicknameResponse.kt new file mode 100644 index 0000000..eadad1d --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/user/model/response/CheckChangeNicknameResponse.kt @@ -0,0 +1,6 @@ +package com.hero.alignlab.domain.user.model.response + +data class CheckChangeNicknameResponse( + val valid: Boolean, + val reason: String? = null, +) diff --git a/src/main/kotlin/com/hero/alignlab/domain/user/resource/UserResource.kt b/src/main/kotlin/com/hero/alignlab/domain/user/resource/UserResource.kt index b3d295e..c7b6b82 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/user/resource/UserResource.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/user/resource/UserResource.kt @@ -6,6 +6,7 @@ import com.hero.alignlab.domain.auth.model.AuthUser import com.hero.alignlab.domain.user.application.UserInfoService import com.hero.alignlab.domain.user.model.request.ChangeNicknameRequest import com.hero.alignlab.domain.user.model.response.ChangeNicknameResponse +import com.hero.alignlab.domain.user.model.response.CheckChangeNicknameResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.MediaType @@ -31,4 +32,18 @@ class UserResource( request = request ).wrapOk() } + + @Operation(summary = "유저 닉네임 유효성 검사 체크") + @PutMapping("/api/v1/users/{id}/nickname/check") + suspend fun checkChangeNickname( + user: AuthUser, + @PathVariable id: Long, + @RequestBody request: ChangeNicknameRequest, + ): ResponseEntity> { + return userInfoService.checkChangeNickname( + user = user, + id = id, + request = request + ).wrapOk() + } }