Skip to content

Commit

Permalink
Merge pull request #184 from depromeet/feature/#182
Browse files Browse the repository at this point in the history
[🆘 Bug] 아이디(username) 변경 시 한글, 특수문자 입력하면 오류 #182
  • Loading branch information
ManHyuk authored Feb 14, 2024
2 parents 456e339 + 1417eb0 commit 4958fc7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ data class UpdateUserInfoRequest(
val birth: LocalDate,
val username: String,
val image: String,
)
) {
fun validateUsername(): Boolean {
val regex = "^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*".toRegex()
return regex.matches(username)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ enum class ErrorInfo(
"같은 인생 지도는 1분에 1번만 응원할 수 있습니다.",
LogLevel.INFO,
),

INVALID_USERNAME(
HttpStatus.BAD_REQUEST,
1005,
"유효하지 않은 username 입니다.",
LogLevel.INFO,
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.raemian.api.auth.controller.request.UpdateUserRequest
import io.raemian.api.auth.domain.CurrentUser
import io.raemian.api.auth.domain.UserDTO
import io.raemian.api.lifemap.LifeMapService
import io.raemian.api.support.error.ErrorInfo
import io.raemian.api.support.response.ApiResponse
import io.raemian.api.user.controller.response.UserResponse
import io.raemian.api.user.service.UserService
Expand Down Expand Up @@ -63,8 +64,13 @@ class UserController(
return ResponseEntity.ok().body(ApiResponse.success(updated))
}

val isDuplicated = userService.isDuplicatedUsername(updateUserInfoRequest.username)
if (isDuplicated) {
if (!updateUserInfoRequest.validateUsername()) {
return ResponseEntity
.status(400)
.body(ApiResponse.error(ErrorInfo.RESOURCE_NOT_FOUND))
}

if (userService.isDuplicatedUsername(updateUserInfoRequest.username)) {
return ResponseEntity.status(409).build()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.raemian.api.support

import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

class RegexTest {

@Test
@DisplayName("유저네임 영문+숫자+하이픈 으로만 생성 가능하도록 체크")
fun validateUsername() {
val regex = "^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*".toRegex()
val result1 = regex.matches("aaaaaa00000")
val result2 = regex.matches("아아아아아아")
val result3 = regex.matches("-aaaa")
val result4 = regex.matches("aaaa-")
val result5 = regex.matches("----")

println(result1)
println(result2)
println(result3)
println(result4)
println(result5)
}
}

0 comments on commit 4958fc7

Please sign in to comment.