Skip to content

Commit

Permalink
출입문 유형이 없을 때 다른 출입문 유형을 같이 입력할 수 없다 & 테스트 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
yongseongkim committed Mar 24, 2024
1 parent 8752ba3 commit 7bd39bd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ class AccessibilityApplicationService(
createPlaceAccessibilityParams: PlaceAccessibilityRepository.CreateParams,
createPlaceAccessibilityCommentParams: PlaceAccessibilityCommentRepository.CreateParams?,
): RegisterPlaceAccessibilityResult {
if (createPlaceAccessibilityParams.isValid().not()) {
throw SccDomainException("잘못된 접근성 정보입니다. 필수 항목을 모두 입력해주세요.")
}
if (placeAccessibilityRepository.findByPlaceId(createPlaceAccessibilityParams.placeId) != null) {
throw SccDomainException("이미 접근성 정보가 등록된 장소입니다.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import club.staircrusher.challenge.application.port.`in`.ChallengeService
import club.staircrusher.challenge.domain.model.ChallengeAddress
import club.staircrusher.challenge.domain.model.ChallengeContribution
import club.staircrusher.stdlib.di.annotation.Component
import club.staircrusher.stdlib.domain.SccDomainException
import club.staircrusher.stdlib.persistence.TransactionManager

@Component
Expand All @@ -26,25 +27,30 @@ class RegisterPlaceAccessibilityUseCase(
userId: String,
createPlaceAccessibilityParams: PlaceAccessibilityRepository.CreateParams,
createPlaceAccessibilityCommentParams: PlaceAccessibilityCommentRepository.CreateParams?,
): RegisterPlaceAccessibilityUseCaseResult = transactionManager.doInTransaction {
val registerResult = accessibilityApplicationService.doRegisterPlaceAccessibility(
createPlaceAccessibilityParams,
createPlaceAccessibilityCommentParams
)
val getAccessibilityResult =
accessibilityApplicationService.doGetAccessibility(createPlaceAccessibilityParams.placeId, userId)
val challengeContributions = challengeService.contributeToSatisfiedChallenges(
userId = userId,
contribution = ChallengeService.Contribution.PlaceAccessibility(
placeAccessibilityId = registerResult.placeAccessibility.id,
placeAccessibilityAddress = ChallengeAddress(registerResult.place),
): RegisterPlaceAccessibilityUseCaseResult {
if (createPlaceAccessibilityParams.isValid().not()) {
throw SccDomainException("잘못된 접근성 정보입니다. 필수 입력을 빠트렸거나 조건을 다시 한 번 확인해주세요.", SccDomainException.ErrorCode.INVALID_ARGUMENTS)
}
return transactionManager.doInTransaction {
val registerResult = accessibilityApplicationService.doRegisterPlaceAccessibility(
createPlaceAccessibilityParams,
createPlaceAccessibilityCommentParams
)
val getAccessibilityResult =
accessibilityApplicationService.doGetAccessibility(createPlaceAccessibilityParams.placeId, userId)
val challengeContributions = challengeService.contributeToSatisfiedChallenges(
userId = userId,
contribution = ChallengeService.Contribution.PlaceAccessibility(
placeAccessibilityId = registerResult.placeAccessibility.id,
placeAccessibilityAddress = ChallengeAddress(registerResult.place),
)
)
)

return@doInTransaction RegisterPlaceAccessibilityUseCaseResult(
registerPlaceAccessibilityResult = registerResult,
getAccessibilityResult = getAccessibilityResult,
challengeContributions = challengeContributions
)
return@doInTransaction RegisterPlaceAccessibilityUseCaseResult(
registerPlaceAccessibilityResult = registerResult,
getAccessibilityResult = getAccessibilityResult,
challengeContributions = challengeContributions
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ interface PlaceAccessibilityRepository : EntityRepository<PlaceAccessibility, St
) {
fun isValid(): Boolean {
// 0401 버전에서 추가된 항목이 모두 있거나 모두 없거나
return listOf(floors, isStairOnlyOption, stairHeightLevel, entranceDoorTypes).all { it == null }
|| listOf(floors, isStairOnlyOption, stairHeightLevel, entranceDoorTypes).all { it != null }
val isInputValid = listOf(floors, isStairOnlyOption, stairHeightLevel, entranceDoorTypes).all { it == null } || listOf(floors, isStairOnlyOption, stairHeightLevel, entranceDoorTypes).all { it != null }
val isDoorTypesInvalid = entranceDoorTypes?.let { it.contains(EntranceDoorType.None) && it.count() > 1 }
?: false
return isInputValid && isDoorTypesInvalid.not()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import club.staircrusher.accessibility.domain.model.StairInfo
import club.staircrusher.accessibility.infra.adapter.`in`.controller.toDTO
import club.staircrusher.accessibility.infra.adapter.`in`.controller.toModel
import club.staircrusher.accesssibility.infra.adapter.`in`.controller.base.AccessibilityITBase
import club.staircrusher.api.spec.dto.ApiErrorResponse
import club.staircrusher.api.spec.dto.EntranceDoorType
import club.staircrusher.api.spec.dto.RegisterPlaceAccessibilityRequestDto
import club.staircrusher.api.spec.dto.RegisterPlaceAccessibilityResponseDto
Expand Down Expand Up @@ -122,22 +123,21 @@ class RegisterPlaceAccessibilityTest : AccessibilityITBase() {
assertEquals(expectedRegisteredUserOrder, result.registeredUserOrder)
}
}
}

// 1층인 경우
@Test
fun `출입문 유형 입력에서 "문 없음" 과 다른 출입문 유형(미닫이, 여닫이 등)을 같이 입력할 수 없다`() {
val user = transactionManager.doInTransaction { testDataGenerator.createUser() }
val place = transactionManager.doInTransaction { testDataGenerator.createBuildingAndPlace(placeName = "장소장소") }
val firstFloorPlaceParams = getRegisterPlaceAccessibilityRequestParamsAfter240401(place, listOf(1))
val nthFloorParams = getRegisterPlaceAccessibilityRequestParamsAfter240401(place, listOf(3, 4), entranceDoorTypes = listOf(EntranceDoorType.none, EntranceDoorType.automatic))
mvc
.sccRequest("/registerPlaceAccessibility", firstFloorPlaceParams, user = user)
.sccRequest("/registerPlaceAccessibility", nthFloorParams, user = user)
.andExpect {
status { isBadRequest() }
}
.apply {
val result = getResult(RegisterPlaceAccessibilityResponseDto::class)
val accessibilityInfo = result.accessibilityInfo!!
assertNull(accessibilityInfo.buildingAccessibility)
assertTrue(accessibilityInfo.buildingAccessibilityComments.isEmpty())

val placeAccessibility = accessibilityInfo.placeAccessibility!!
assertEquals(place.id, placeAccessibility.placeId)
assertTrue(placeAccessibility.isFirstFloor)
val result = getResult(ApiErrorResponse::class)
assertEquals(ApiErrorResponse.Code.INVALID_ARGUMENTS, result.code)
}
}

Expand Down

0 comments on commit 7bd39bd

Please sign in to comment.