From 2568153548af07185120d5be3fb2b29492a6cb65 Mon Sep 17 00:00:00 2001 From: Combi153 Date: Sat, 6 Apr 2024 18:45:07 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Fish=20=EC=9E=90=EB=8F=99=EC=99=84?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=83=89=20=EC=8B=9C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/petqua/domain/auth/token/AuthToken.kt | 1 - .../petqua/domain/fish/FishCustomRepositoryImpl.kt | 1 + src/main/kotlin/com/petqua/domain/member/TankName.kt | 11 +++++------ .../com/petqua/application/fish/FishServiceTest.kt | 4 ++-- .../domain/fish/FishCustomRepositoryImplTest.kt | 8 ++++---- .../petqua/presentation/fish/FishControllerTest.kt | 4 ++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/petqua/domain/auth/token/AuthToken.kt b/src/main/kotlin/com/petqua/domain/auth/token/AuthToken.kt index 00b22609..42f59ee7 100644 --- a/src/main/kotlin/com/petqua/domain/auth/token/AuthToken.kt +++ b/src/main/kotlin/com/petqua/domain/auth/token/AuthToken.kt @@ -1,6 +1,5 @@ package com.petqua.domain.auth.token - private const val EMPTY_TOKEN = "" class AuthToken private constructor( diff --git a/src/main/kotlin/com/petqua/domain/fish/FishCustomRepositoryImpl.kt b/src/main/kotlin/com/petqua/domain/fish/FishCustomRepositoryImpl.kt index 89dd4910..7fa6c1d9 100644 --- a/src/main/kotlin/com/petqua/domain/fish/FishCustomRepositoryImpl.kt +++ b/src/main/kotlin/com/petqua/domain/fish/FishCustomRepositoryImpl.kt @@ -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() ) diff --git a/src/main/kotlin/com/petqua/domain/member/TankName.kt b/src/main/kotlin/com/petqua/domain/member/TankName.kt index 0a8d463f..d55a20c7 100644 --- a/src/main/kotlin/com/petqua/domain/member/TankName.kt +++ b/src/main/kotlin/com/petqua/domain/member/TankName.kt @@ -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") @@ -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,}") } } diff --git a/src/test/kotlin/com/petqua/application/fish/FishServiceTest.kt b/src/test/kotlin/com/petqua/application/fish/FishServiceTest.kt index ec0f09ac..dade7398 100644 --- a/src/test/kotlin/com/petqua/application/fish/FishServiceTest.kt +++ b/src/test/kotlin/com/petqua/application/fish/FishServiceTest.kt @@ -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), ) } } @@ -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), ) } } diff --git a/src/test/kotlin/com/petqua/domain/fish/FishCustomRepositoryImplTest.kt b/src/test/kotlin/com/petqua/domain/fish/FishCustomRepositoryImplTest.kt index adb35b42..97224c40 100644 --- a/src/test/kotlin/com/petqua/domain/fish/FishCustomRepositoryImplTest.kt +++ b/src/test/kotlin/com/petqua/domain/fish/FishCustomRepositoryImplTest.kt @@ -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 ) } } diff --git a/src/test/kotlin/com/petqua/presentation/fish/FishControllerTest.kt b/src/test/kotlin/com/petqua/presentation/fish/FishControllerTest.kt index 9354c478..845d86d9 100644 --- a/src/test/kotlin/com/petqua/presentation/fish/FishControllerTest.kt +++ b/src/test/kotlin/com/petqua/presentation/fish/FishControllerTest.kt @@ -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), ) } } @@ -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), ) } }