Skip to content

Commit

Permalink
refactor: Fish 자동완성 검색 시 정렬 순서 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Combi153 committed Apr 6, 2024
1 parent 3f6d10b commit 2568153
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/com/petqua/domain/auth/token/AuthToken.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.petqua.domain.auth.token


private const val EMPTY_TOKEN = ""

class AuthToken private constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class FishCustomRepositoryImpl(
).whereAnd(
path(Fish::species)(Species::name).like(pattern = "%${speciesName}%")
).orderBy(
locate(speciesName, path(Fish::species)(Species::name)).asc(),
length(path(Fish::species)(Species::name)).asc(),
path(Fish::species)(Species::name).asc()
)
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/com/petqua/domain/member/TankName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import jakarta.persistence.Column
import jakarta.persistence.Embeddable
import java.util.regex.Pattern

private const val WHITESPACE = " "

@Embeddable
data class TankName(
@Column(nullable = false, name = "name")
Expand All @@ -28,19 +26,20 @@ data class TankName(
}

private fun validateConsecutiveWhitespaces() {
throwExceptionWhen(whitespacePattern.toRegex().containsMatchIn(value)) {
throwExceptionWhen(WHITESPACE_PATTERN.toRegex().containsMatchIn(value)) {
MemberException(INVALID_MEMBER_FISH_TANK_NAME)
}
}

private fun validateCharactersAndLength() {
throwExceptionWhen(!wordPattern.matcher(value).matches()) {
throwExceptionWhen(!WORD_PATTERN.matcher(value).matches()) {
MemberException(INVALID_MEMBER_FISH_TANK_NAME)
}
}

companion object {
private val wordPattern = Pattern.compile("^[a-zA-Z0-9가-힣,/_ ]{2,18}\$")
private val whitespacePattern = Pattern.compile("$WHITESPACE{2,}")
private const val WHITESPACE = " "
private val WORD_PATTERN = Pattern.compile("^[a-zA-Z0-9가-힣,/_ ]{2,18}\$")
private val WHITESPACE_PATTERN = Pattern.compile("$WHITESPACE{2,}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class FishServiceTest(
Then("관련된 어종 목록을 조회할 수 있다") {
responses shouldBe listOf(
SpeciesSearchResponse(fishA.id, fishA.species.name),
SpeciesSearchResponse(fishD.id, fishD.species.name),
SpeciesSearchResponse(fishB.id, fishB.species.name),
SpeciesSearchResponse(fishC.id, fishC.species.name),
SpeciesSearchResponse(fishD.id, fishD.species.name),
)
}
}
Expand All @@ -54,7 +54,7 @@ class FishServiceTest(
Then("입력한 개수만큼 관련된 어종 목록을 조회할 수 있다") {
responses shouldBe listOf(
SpeciesSearchResponse(fishA.id, fishA.species.name),
SpeciesSearchResponse(fishD.id, fishD.species.name),
SpeciesSearchResponse(fishB.id, fishB.species.name),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class FishCustomRepositoryImplTest(
Then("관련된 어종 목록을 조회할 수 있다") {
fishes.map { it.species.name } shouldBe listOf(
fishA.species.name,
fishD.species.name,
fishB.species.name,
fishC.species.name
fishC.species.name,
fishD.species.name
)
fishes.map { it.id } shouldBe listOf(
fishA.id,
fishD.id,
fishB.id,
fishC.id
fishC.id,
fishD.id
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class FishControllerTest(
response.statusCode shouldBe OK.value()
speciesSearchResponses shouldBe listOf(
SpeciesSearchResponse(fishA.id, fishA.species.name),
SpeciesSearchResponse(fishD.id, fishD.species.name),
SpeciesSearchResponse(fishB.id, fishB.species.name),
SpeciesSearchResponse(fishC.id, fishC.species.name),
SpeciesSearchResponse(fishD.id, fishD.species.name),
)
}
}
Expand All @@ -53,7 +53,7 @@ class FishControllerTest(
response.statusCode shouldBe OK.value()
speciesSearchResponses shouldBe listOf(
SpeciesSearchResponse(fishA.id, fishA.species.name),
SpeciesSearchResponse(fishD.id, fishD.species.name),
SpeciesSearchResponse(fishB.id, fishB.species.name),
)
}
}
Expand Down

0 comments on commit 2568153

Please sign in to comment.