Skip to content

Commit

Permalink
feat: 닉네임 유효성 검사 api 추가 및 dns resolver 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Nov 3, 2024
1 parent 82641d8 commit 004461b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/DependencyVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.hero.alignlab.domain.user.model.response

data class CheckChangeNicknameResponse(
val valid: Boolean,
val reason: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Response<CheckChangeNicknameResponse>> {
return userInfoService.checkChangeNickname(
user = user,
id = id,
request = request
).wrapOk()
}
}

0 comments on commit 004461b

Please sign in to comment.