From 9d93ac546df3822e71ee648409e72743340419c9 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 15:45:23 +0900 Subject: [PATCH 1/8] refact: rename recruitDone field name to recruitStatus --- .../application/mapper/ExperimentMapper.kt | 2 +- .../GetExperimentPostDetailUseCase.kt | 2 +- .../experiment/GetExperimentPostsUseCase.kt | 6 ++--- .../member/GetMyExperimentPostsUseCase.kt | 4 +-- .../domain/model/experiment/CustomFilter.kt | 2 +- .../domain/model/experiment/ExperimentPost.kt | 6 ++--- .../entity/experiment/ExperimentPostEntity.kt | 8 +++--- .../ExperimentPostCustomRepositoryImpl.kt | 10 +++---- .../controller/ExperimentPostController.kt | 4 +-- .../dto/request/experiment/CustomFilter.kt | 2 +- .../ExperimentPostDetailResponse.kt | 2 +- .../experiment/ExperimentPostsResponse.kt | 3 ++- .../member/MyExperimentPostResponse.kt | 2 +- .../api/mapper/ExperimentPostMapper.kt | 8 +++--- .../presentation/api/mapper/MemberMapper.kt | 2 +- .../mapper/ExperimentMapperTest.kt | 6 ++--- ...GetExperimentPostApplyMethodUseCaseTest.kt | 2 +- .../GetExperimentPostDetailUseCaseTest.kt | 2 +- .../GetExperimentPostsUseCaseTest.kt | 26 +++++++++---------- .../member/GetMyExperimentPostsUseCaseTest.kt | 12 ++++----- 20 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/main/kotlin/com/dobby/backend/application/mapper/ExperimentMapper.kt b/src/main/kotlin/com/dobby/backend/application/mapper/ExperimentMapper.kt index 889d5c5a..7bcc3e60 100644 --- a/src/main/kotlin/com/dobby/backend/application/mapper/ExperimentMapper.kt +++ b/src/main/kotlin/com/dobby/backend/application/mapper/ExperimentMapper.kt @@ -22,7 +22,7 @@ object ExperimentMapper { areas = it.areas ) }, - recruitDone = customFilter.recruitDone + recruitStatus = customFilter.recruitStatus ) } diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCase.kt index 3ed998d7..406fd18a 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCase.kt @@ -38,7 +38,7 @@ fun ExperimentPost.toDetailResponse(): ExperimentPostDetailResponse { uploadDate = this.createdAt.toLocalDate(), uploaderName = this.member.name, views = this.views, - recruitDone = this.recruitDone, + recruitStatus = this.recruitStatus, summary = this.toSummaryResponse(), targetGroup = this.targetGroup.toResponse(), address = this.toAddressResponse(), diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt index 4c5c4671..8b7d5b42 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt @@ -20,7 +20,7 @@ class GetExperimentPostsUseCase ( val matchType : MatchType?, val studyTarget: StudyTargetInput?, val locationTarget: LocationTargetInput?, - val recruitDone: Boolean?, + val recruitStatus: Boolean?, ) data class StudyTargetInput( @@ -48,7 +48,7 @@ class GetExperimentPostsUseCase ( val views: Int, val univName: String, val reward: String, - val recruitDone: Boolean, + val recruitStatus: Boolean, val durationInfo: DurationInfoOutput ) @@ -71,7 +71,7 @@ class GetExperimentPostsUseCase ( views = post.views, univName = post.univName, reward = post.reward, - recruitDone = post.recruitDone, + recruitStatus = post.recruitStatus, durationInfo = DurationInfoOutput( startDate = post.startDate, endDate = post.endDate diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCase.kt index 6ba69917..b60cfd61 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCase.kt @@ -25,7 +25,7 @@ class GetMyExperimentPostsUseCase( val title: String, val content: String, val views: Int, - val recruitDone: Boolean, + val recruitStatus: Boolean, val uploadDate: LocalDate ) @@ -42,7 +42,7 @@ class GetMyExperimentPostsUseCase( title = post.title, content = post.content, views = post.views, - recruitDone = post.recruitDone, + recruitStatus = post.recruitStatus, uploadDate = post.createdAt.toLocalDate() ) } ?: emptyList() diff --git a/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt b/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt index 085a98bf..71656a5d 100644 --- a/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt +++ b/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt @@ -9,7 +9,7 @@ data class CustomFilter( val matchType: MatchType?, val studyTarget: StudyTarget?, val locationTarget: LocationTarget?, - val recruitDone: Boolean? + val recruitStatus: Boolean? ) data class StudyTarget( val gender: GenderType?, diff --git a/src/main/kotlin/com/dobby/backend/domain/model/experiment/ExperimentPost.kt b/src/main/kotlin/com/dobby/backend/domain/model/experiment/ExperimentPost.kt index 57be5ae0..13e00e95 100644 --- a/src/main/kotlin/com/dobby/backend/domain/model/experiment/ExperimentPost.kt +++ b/src/main/kotlin/com/dobby/backend/domain/model/experiment/ExperimentPost.kt @@ -28,7 +28,7 @@ data class ExperimentPost( val area: Area, val detailedAddress: String?, val alarmAgree: Boolean, - val recruitDone: Boolean = false, + val recruitStatus: Boolean = true, val images: List, var createdAt: LocalDateTime, var updatedAt: LocalDateTime @@ -59,7 +59,7 @@ data class ExperimentPost( area: Area, detailedAddress: String, alarmAgree: Boolean, - recruitDone: Boolean, + recruitStatus: Boolean, images: List, createdAt: LocalDateTime = LocalDateTime.now(), updatedAt: LocalDateTime = LocalDateTime.now() @@ -83,7 +83,7 @@ data class ExperimentPost( area = area, detailedAddress = detailedAddress, alarmAgree = alarmAgree, - recruitDone = recruitDone, + recruitStatus = true, images = images, createdAt = createdAt, updatedAt = updatedAt diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt index 9530523f..84d798dc 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt @@ -78,8 +78,8 @@ class ExperimentPostEntity( @Column(name = "alarm_agree", nullable = false) val alarmAgree: Boolean, - @Column(name = "recruit_done", nullable = false) - val recruitDone: Boolean = false, + @Column(name = "recruit_status", nullable = false) + val recruitStatus: Boolean = false, @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true) @JoinColumn(name = "experiment_image_id") @@ -111,7 +111,7 @@ class ExperimentPostEntity( area = area, detailedAddress = detailedAddress, alarmAgree = alarmAgree, - recruitDone = recruitDone, + recruitStatus = recruitStatus, images = images.map { it.toDomain() }, createdAt = createdAt, updatedAt = updatedAt @@ -139,7 +139,7 @@ class ExperimentPostEntity( area = area, detailedAddress = detailedAddress, alarmAgree = alarmAgree, - recruitDone = recruitDone, + recruitStatus = recruitStatus, images = images.map { ExperimentImageEntity.fromDomain(it) }, createdAt = createdAt, updatedAt = updatedAt diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt index 6abf85ab..737a26cc 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt @@ -34,7 +34,7 @@ class ExperimentPostCustomRepositoryImpl ( ageBetween(post, customFilter.studyTarget?.age), regionEq(post, customFilter.locationTarget?.region), areasIn(post, customFilter.locationTarget?.areas), - recruitDoneEq(post, customFilter.recruitDone) + recruitStatusEq(post, customFilter.recruitStatus) ) .offset((pagination.page - 1L) * pagination.count) .limit(pagination.count.toLong()) @@ -84,8 +84,8 @@ class ExperimentPostCustomRepositoryImpl ( } } - private fun recruitDoneEq(post: QExperimentPostEntity, recruitDone: Boolean?): BooleanExpression? { - return recruitDone?.let { post.recruitDone.eq(it) } + private fun recruitStatusEq(post: QExperimentPostEntity, recruitStatus: Boolean?): BooleanExpression? { + return recruitStatus?.let { post.recruitStatus.eq(it) } } @Override @@ -93,10 +93,10 @@ class ExperimentPostCustomRepositoryImpl ( val experimentPost = QExperimentPostEntity.experimentPostEntity return jpaQueryFactory.update(experimentPost) - .set(experimentPost.recruitDone, true) + .set(experimentPost.recruitStatus, true) .where( experimentPost.endDate.lt(currentDate) - .and(experimentPost.recruitDone.eq(false)) + .and(experimentPost.recruitStatus.eq(false)) ) .execute() } diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt index 046171b3..9ea9ab66 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt @@ -104,11 +104,11 @@ class ExperimentPostController ( @RequestParam(required = false) age: Int?, @RequestParam(required = false) region: Region?, @RequestParam(required = false) areas: List?, - @RequestParam(required = false) recruitDone: Boolean?, + @RequestParam(required = false) recruitStatus: Boolean?, @RequestParam(defaultValue = "1") page: Int, @RequestParam(defaultValue = "6") count: Int ): List { - val customFilter = ExperimentPostMapper.toUseCaseCustomFilter(matchType, gender, age, region, areas, recruitDone) + val customFilter = ExperimentPostMapper.toUseCaseCustomFilter(matchType, gender, age, region, areas, recruitStatus) val pagination = ExperimentPostMapper.toUseCasePagination(page, count) val input = ExperimentPostMapper.toGetExperimentPostsUseCaseInput(customFilter, pagination) val output = experimentPostService.getExperimentPosts(input) diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt index a82e87b5..ad2a81ad 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt @@ -17,7 +17,7 @@ data class CustomFilter ( val locationTarget: LocationTarget?, @Schema(description = "공고 상태 필터 - false이면 모집 중인 공고만 확인 가능") - val recruitDone: Boolean?, + val recruitStatus: Boolean?, ) data class StudyTarget ( diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt index 96137901..49b4e807 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt @@ -26,7 +26,7 @@ data class ExperimentPostDetailResponse( val views: Int, @Schema(description = "모집 완료 여부", example = "true") - val recruitDone: Boolean, + val recruitStatus: Boolean, @Schema(description = "요약 정보", example = "실험 공고의 요약(주요) 정보") val summary: SummaryResponse, diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostsResponse.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostsResponse.kt index b0dca182..c8cbaaae 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostsResponse.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostsResponse.kt @@ -1,5 +1,6 @@ package com.dobby.backend.presentation.api.dto.response.experiment + data class ExperimentPostsResponse ( val postInfo: PostInfo, - val recruitDone: Boolean + val recruitStatus: Boolean ) diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt index 3df6c398..fb5789d8 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt @@ -17,7 +17,7 @@ data class MyExperimentPostResponse( val views: Int, @Schema(description = "모집 완료 여부", example = "false") - val recruitDone: Boolean, + val recruitStatus: Boolean, @Schema(description = "업로드 날짜", example = "2025-01-01") val uploadDate: LocalDate diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt index b3323c37..a5d14648 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt @@ -96,7 +96,7 @@ object ExperimentPostMapper { uploadDate = response.experimentPostDetailResponse.uploadDate, uploaderName = response.experimentPostDetailResponse.uploaderName, views = response.experimentPostDetailResponse.views, - recruitDone = response.experimentPostDetailResponse.recruitDone, + recruitStatus = response.experimentPostDetailResponse.recruitStatus, summary = response.experimentPostDetailResponse.summary, targetGroup = response.experimentPostDetailResponse.targetGroup, address = response.experimentPostDetailResponse.address, @@ -162,7 +162,7 @@ object ExperimentPostMapper { age: Int?, region: Region?, areas: List?, - recruitDone: Boolean? + recruitStatus: Boolean? ): GetExperimentPostsUseCase.CustomFilterInput { return GetExperimentPostsUseCase.CustomFilterInput( matchType = matchType, @@ -174,7 +174,7 @@ object ExperimentPostMapper { region = region, areas = areas ), - recruitDone = recruitDone + recruitStatus = recruitStatus ) } @@ -211,7 +211,7 @@ object ExperimentPostMapper { ) ), - recruitDone = output.postInfo.recruitDone + recruitStatus = output.postInfo.recruitStatus ) } diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/MemberMapper.kt b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/MemberMapper.kt index f92940b2..2fc936fb 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/MemberMapper.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/MemberMapper.kt @@ -139,7 +139,7 @@ object MemberMapper { title = post.title, content = post.content, views = post.views, - recruitDone = post.recruitDone, + recruitStatus = post.recruitStatus, uploadDate = post.uploadDate ) }, diff --git a/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt b/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt index 95b14284..bcff7fa9 100644 --- a/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt @@ -23,7 +23,7 @@ class ExperimentMapperTest : BehaviorSpec({ region = Region.SEOUL, areas = listOf(Area.GANGNAMGU) ), - recruitDone = false + recruitStatus = false ) `when`("toDomainFilter 메서드가 호출되면") { @@ -43,8 +43,8 @@ class ExperimentMapperTest : BehaviorSpec({ result.locationTarget?.areas shouldBe listOf(Area.GANGNAMGU) } - then("recruitDone이 올바르게 매핑되어야 한다") { - result.recruitDone shouldBe false + then("recruitStatus이 올바르게 매핑되어야 한다") { + result.recruitStatus shouldBe false } } } diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostApplyMethodUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostApplyMethodUseCaseTest.kt index 09338399..c2feb301 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostApplyMethodUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostApplyMethodUseCaseTest.kt @@ -40,7 +40,7 @@ class GetExperimentPostApplyMethodUseCaseTest : BehaviorSpec({ updatedAt = LocalDateTime.now(), member = member, views = 100, - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now(), leadResearcher = "Lead", diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCaseTest.kt index f688963b..447c40cc 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostDetailUseCaseTest.kt @@ -48,7 +48,7 @@ class GetExperimentPostDetailUseCaseTest : BehaviorSpec({ updatedAt = LocalDateTime.now(), member = member, views = 100, - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now(), leadResearcher = "Lead", diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt index 0d555488..e213678f 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt @@ -31,7 +31,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = StudyTargetInput(gender = GenderType.FEMALE, age = 24), locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU, Area.MAPOGU)), - recruitDone = false + recruitStatus = false ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -42,7 +42,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ views = 10, univName = "야뿌 대학교", reward = "스타벅스 1만원권 쿠폰", - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), alarmAgree = true, @@ -98,7 +98,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ result.first().postInfo.title shouldBe "야뿌 피자 먹방 테스트" result.first().postInfo.univName shouldBe "야뿌 대학교" result.first().postInfo.reward shouldBe "스타벅스 1만원권 쿠폰" - result.first().postInfo.recruitDone shouldBe false + result.first().postInfo.recruitStatus shouldBe false } } } @@ -108,7 +108,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = null, locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU)), - recruitDone = false + recruitStatus = false ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -119,7 +119,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ views = 10, univName = "Test University", reward = "Test Reward", - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), alarmAgree = true, @@ -182,7 +182,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = StudyTargetInput(gender = GenderType.FEMALE, age = 24), locationTarget = LocationTargetInput(region = Region.SEOUL, areas = null), - recruitDone = false + recruitStatus = false ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -193,7 +193,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ views = 10, univName = "Test University", reward = "Test Reward", - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), alarmAgree = true, @@ -255,7 +255,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = StudyTargetInput(gender = GenderType.FEMALE, age = 30), locationTarget = LocationTargetInput(region = Region.GYEONGGI, areas = listOf(Area.GWANGMYEONGSI)), - recruitDone = false + recruitStatus = false ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -266,7 +266,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ views = 10, univName = "Test University", reward = "Test Reward", - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), alarmAgree = true, @@ -328,7 +328,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = null, locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU)), - recruitDone = false + recruitStatus = false ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -339,7 +339,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ views = 10, univName = "Test University", reward = "Test Reward", - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), alarmAgree = true, @@ -402,7 +402,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = null, locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU)), - recruitDone = true + recruitStatus = true ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -413,7 +413,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ views = 10, univName = "Test University", reward = "Test Reward", - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), alarmAgree = true, diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCaseTest.kt index d07bd939..af135590 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/member/GetMyExperimentPostsUseCaseTest.kt @@ -50,7 +50,7 @@ class GetMyExperimentPostsUseCaseTest : BehaviorSpec({ updatedAt = LocalDateTime.now(), member = member, views = 100, - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now(), leadResearcher = "임지수", @@ -75,7 +75,7 @@ class GetMyExperimentPostsUseCaseTest : BehaviorSpec({ updatedAt = LocalDateTime.now(), member = member, views = 150, - recruitDone = true, + recruitStatus = true, startDate = LocalDate.now().plusDays(1), endDate = LocalDate.now().plusWeeks(2), leadResearcher = "임지수 연구자", @@ -100,7 +100,7 @@ class GetMyExperimentPostsUseCaseTest : BehaviorSpec({ updatedAt = LocalDateTime.now(), member = member, views = 200, - recruitDone = false, + recruitStatus = false, startDate = LocalDate.now(), endDate = LocalDate.now().plusDays(10), leadResearcher = "Dr. Lim", @@ -131,19 +131,19 @@ class GetMyExperimentPostsUseCaseTest : BehaviorSpec({ result[0].title shouldBe "야뿌들의 평균 식사량 체크 테스트" result[0].content shouldBe "야뿌들의 한끼 식사량을 체크하는 테스트입니다." result[0].views shouldBe 100 - result[0].recruitDone shouldBe false + result[0].recruitStatus shouldBe false result[1].experimentPostId shouldBe 2L result[1].title shouldBe "다음 세대 인공지능을 위한 연구" result[1].content shouldBe "다음 세대의 AI를 위한 실험 연구입니다." result[1].views shouldBe 150 - result[1].recruitDone shouldBe true + result[1].recruitStatus shouldBe true result[2].experimentPostId shouldBe 3L result[2].title shouldBe "소셜 미디어 연구 참가자 모집" result[2].content shouldBe "소셜 미디어에 대한 연구에 참여할 모집입니다." result[2].views shouldBe 200 - result[2].recruitDone shouldBe false + result[2].recruitStatus shouldBe false } } } From 5e7683af2c129f1b700476c7a33e24a8cc82edeb Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 16:11:47 +0900 Subject: [PATCH 2/8] refact: refact GetExperimentPosts logic due to renamed field and parameter --- .../experiment/GetExperimentPostsUseCase.kt | 3 +- .../experiment/ExperimentPostGateway.kt | 2 +- .../domain/model/experiment/CustomFilter.kt | 3 +- .../entity/enums/experiment/RecruitStatus.kt | 17 +++++ .../ExperimentPostCustomRepositoryImpl.kt | 7 +- .../experiment/ExperimentPostGatewayImpl.kt | 1 + .../controller/ExperimentPostController.kt | 2 +- .../api/mapper/ExperimentPostMapper.kt | 5 +- .../mapper/ExperimentMapperTest.kt | 68 ------------------- .../GetExperimentPostsUseCaseTest.kt | 13 ++-- 10 files changed, 40 insertions(+), 81 deletions(-) create mode 100644 src/main/kotlin/com/dobby/backend/infrastructure/database/entity/enums/experiment/RecruitStatus.kt delete mode 100644 src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt index 8b7d5b42..2902655e 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCase.kt @@ -7,6 +7,7 @@ import com.dobby.backend.infrastructure.database.entity.enums.GenderType import com.dobby.backend.infrastructure.database.entity.enums.MatchType import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import java.time.LocalDate class GetExperimentPostsUseCase ( @@ -20,7 +21,7 @@ class GetExperimentPostsUseCase ( val matchType : MatchType?, val studyTarget: StudyTargetInput?, val locationTarget: LocationTargetInput?, - val recruitStatus: Boolean?, + val recruitStatus: RecruitStatus, ) data class StudyTargetInput( diff --git a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt index dc536357..1ddf23b9 100644 --- a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt +++ b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt @@ -15,7 +15,7 @@ interface ExperimentPostGateway { fun countExperimentPosts(): Int fun countExperimentPostByRegionGroupedByArea(region: Region): List fun countExperimentPostGroupedByRegion(): List - fun updateExperimentPostStatus(todayDate : LocalDate) : Long + fun updateExperimentPostStatus(currentDate : LocalDate) : Long fun findExperimentPostsByMemberIdWithPagination(memberId: Long, pagination: Pagination, order: String): List? fun countExperimentPostsByMemberId(memberId: Long): Int } diff --git a/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt b/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt index 71656a5d..b18e3fd5 100644 --- a/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt +++ b/src/main/kotlin/com/dobby/backend/domain/model/experiment/CustomFilter.kt @@ -4,12 +4,13 @@ import com.dobby.backend.infrastructure.database.entity.enums.GenderType import com.dobby.backend.infrastructure.database.entity.enums.MatchType import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus data class CustomFilter( val matchType: MatchType?, val studyTarget: StudyTarget?, val locationTarget: LocationTarget?, - val recruitStatus: Boolean? + val recruitStatus: RecruitStatus ) data class StudyTarget( val gender: GenderType?, diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/enums/experiment/RecruitStatus.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/enums/experiment/RecruitStatus.kt new file mode 100644 index 00000000..1df2f4ba --- /dev/null +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/enums/experiment/RecruitStatus.kt @@ -0,0 +1,17 @@ +package com.dobby.backend.infrastructure.database.entity.enums.experiment + +import java.security.InvalidParameterException + +enum class RecruitStatus { + ALL, OPEN; + + companion object { + fun fromString(value: String): RecruitStatus { + return when (value) { + "ALL" -> ALL + "OPEN" -> OPEN + else -> throw InvalidParameterException() + } + } + } +} diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt index 737a26cc..6b237c89 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostCustomRepositoryImpl.kt @@ -7,6 +7,7 @@ import com.dobby.backend.infrastructure.database.entity.enums.MatchType import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area.Companion.isAll import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import com.dobby.backend.infrastructure.database.entity.experiment.ExperimentPostEntity import com.dobby.backend.infrastructure.database.entity.experiment.QExperimentPostEntity import com.querydsl.core.types.OrderSpecifier @@ -24,6 +25,10 @@ class ExperimentPostCustomRepositoryImpl ( pagination: Pagination ): List? { val post = QExperimentPostEntity.experimentPostEntity + val recruitStatusCondition = when (customFilter.recruitStatus) { + RecruitStatus.ALL -> null + RecruitStatus.OPEN -> post.recruitStatus.eq(true) + } return jpaQueryFactory.selectFrom(post) .join(post.targetGroup).fetchJoin() @@ -34,7 +39,7 @@ class ExperimentPostCustomRepositoryImpl ( ageBetween(post, customFilter.studyTarget?.age), regionEq(post, customFilter.locationTarget?.region), areasIn(post, customFilter.locationTarget?.areas), - recruitStatusEq(post, customFilter.recruitStatus) + recruitStatusCondition ) .offset((pagination.page - 1L) * pagination.count) .limit(pagination.count.toLong()) diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt index f6225a18..76183d8d 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt @@ -60,6 +60,7 @@ class ExperimentPostGatewayImpl( override fun updateExperimentPostStatus(currentDate: LocalDate): Long { return experimentPostCustomRepository.updateExperimentPostStatus(currentDate) } + override fun findExperimentPostsByMemberIdWithPagination( memberId: Long, pagination: Pagination, diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt index 9ea9ab66..dc905e8e 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt @@ -104,7 +104,7 @@ class ExperimentPostController ( @RequestParam(required = false) age: Int?, @RequestParam(required = false) region: Region?, @RequestParam(required = false) areas: List?, - @RequestParam(required = false) recruitStatus: Boolean?, + @RequestParam(required = false, defaultValue = "ALL") recruitStatus: String, @RequestParam(defaultValue = "1") page: Int, @RequestParam(defaultValue = "6") count: Int ): List { diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt index a5d14648..bce87726 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt @@ -10,6 +10,7 @@ import com.dobby.backend.infrastructure.database.entity.enums.GenderType import com.dobby.backend.infrastructure.database.entity.enums.MatchType import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import com.dobby.backend.presentation.api.dto.request.experiment.* import com.dobby.backend.presentation.api.dto.response.experiment.* import com.dobby.backend.util.getCurrentMemberId @@ -162,7 +163,7 @@ object ExperimentPostMapper { age: Int?, region: Region?, areas: List?, - recruitStatus: Boolean? + recruitStatus: String ): GetExperimentPostsUseCase.CustomFilterInput { return GetExperimentPostsUseCase.CustomFilterInput( matchType = matchType, @@ -174,7 +175,7 @@ object ExperimentPostMapper { region = region, areas = areas ), - recruitStatus = recruitStatus + recruitStatus = RecruitStatus.fromString(recruitStatus) ) } diff --git a/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt b/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt deleted file mode 100644 index bcff7fa9..00000000 --- a/src/test/kotlin/com/dobby/backend/application/mapper/ExperimentMapperTest.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.dobby.backend.application.mapper - -import com.dobby.backend.application.usecase.experiment.GetExperimentPostsUseCase -import com.dobby.backend.domain.model.experiment.CustomFilter -import com.dobby.backend.domain.model.experiment.Pagination -import com.dobby.backend.infrastructure.database.entity.enums.GenderType -import com.dobby.backend.infrastructure.database.entity.enums.MatchType -import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area -import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region -import io.kotest.core.spec.style.BehaviorSpec -import io.kotest.matchers.shouldBe - -class ExperimentMapperTest : BehaviorSpec({ - - given("유효한 CustomFilterInput이 주어졌을 때") { - val input = GetExperimentPostsUseCase.CustomFilterInput( - matchType = MatchType.ONLINE, - studyTarget = GetExperimentPostsUseCase.StudyTargetInput( - gender = GenderType.MALE, - age = 25 - ), - locationTarget = GetExperimentPostsUseCase.LocationTargetInput( - region = Region.SEOUL, - areas = listOf(Area.GANGNAMGU) - ), - recruitStatus = false - ) - - `when`("toDomainFilter 메서드가 호출되면") { - val result: CustomFilter = ExperimentMapper.toDomainFilter(input) - - then("matchType이 올바르게 매핑되어야 한다") { - result.matchType shouldBe MatchType.ONLINE - } - - then("studyTarget이 올바르게 매핑되어야 한다") { - result.studyTarget?.gender shouldBe GenderType.MALE - result.studyTarget?.age shouldBe 25 - } - - then("locationTarget이 올바르게 매핑되어야 한다") { - result.locationTarget?.region shouldBe Region.SEOUL - result.locationTarget?.areas shouldBe listOf(Area.GANGNAMGU) - } - - then("recruitStatus이 올바르게 매핑되어야 한다") { - result.recruitStatus shouldBe false - } - } - } - - given("유효한 PaginationInput이 주어졌을 때") { - val input = GetExperimentPostsUseCase.PaginationInput(page = 2, count = 10) - - `when`("toDomainPagination 메서드가 호출되면") { - val result: Pagination = ExperimentMapper.toDomainPagination(input) - - then("page가 올바르게 매핑되어야 한다") { - result.page shouldBe 2 - } - - then("count가 올바르게 매핑되어야 한다") { - result.count shouldBe 10 - } - } - } -}) - diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt index e213678f..db9842f1 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostsUseCaseTest.kt @@ -15,6 +15,7 @@ import com.dobby.backend.domain.model.member.Member import com.dobby.backend.infrastructure.database.entity.enums.* import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.mockk.every @@ -31,7 +32,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = StudyTargetInput(gender = GenderType.FEMALE, age = 24), locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU, Area.MAPOGU)), - recruitStatus = false + recruitStatus = RecruitStatus.ALL ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -108,7 +109,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = null, locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU)), - recruitStatus = false + recruitStatus = RecruitStatus.ALL ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -182,7 +183,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = StudyTargetInput(gender = GenderType.FEMALE, age = 24), locationTarget = LocationTargetInput(region = Region.SEOUL, areas = null), - recruitStatus = false + recruitStatus = RecruitStatus.ALL ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -255,7 +256,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = StudyTargetInput(gender = GenderType.FEMALE, age = 30), locationTarget = LocationTargetInput(region = Region.GYEONGGI, areas = listOf(Area.GWANGMYEONGSI)), - recruitStatus = false + recruitStatus = RecruitStatus.ALL ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -328,7 +329,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = null, locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU)), - recruitStatus = false + recruitStatus = RecruitStatus.ALL ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) @@ -402,7 +403,7 @@ class GetExperimentPostsUseCaseTest : BehaviorSpec({ matchType = MatchType.ALL, studyTarget = null, locationTarget = LocationTargetInput(region = Region.SEOUL, areas = listOf(Area.SEODAEMUNGU)), - recruitStatus = true + recruitStatus = RecruitStatus.ALL ) val pagination = PaginationInput(page = 1, count = 6) val input = Input(customFilter, pagination) From 68424f6aa65f60438dd41dc7ee0f9242e9d30ce4 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 16:17:24 +0900 Subject: [PATCH 3/8] fix: alter recruitStatus's default value --- .../database/entity/experiment/ExperimentPostEntity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt index 84d798dc..120d2ed1 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/entity/experiment/ExperimentPostEntity.kt @@ -79,7 +79,7 @@ class ExperimentPostEntity( val alarmAgree: Boolean, @Column(name = "recruit_status", nullable = false) - val recruitStatus: Boolean = false, + val recruitStatus: Boolean = true, @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true) @JoinColumn(name = "experiment_image_id") From 1d8ad5b382d5c99c762a79c74101d850d78a9610 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 16:35:52 +0900 Subject: [PATCH 4/8] refact: add recruitStatus condition to GetExperimentPostCountsByRegionUseCase --- .../GetExperimentPostCountsByRegionUseCase.kt | 14 +++++++++++--- .../gateway/experiment/ExperimentPostGateway.kt | 3 +++ .../repository/ExperimentPostRepository.kt | 5 +++++ .../experiment/ExperimentPostGatewayImpl.kt | 9 +++++++++ .../api/controller/ExperimentPostController.kt | 5 +++-- .../api/mapper/ExperimentPostMapper.kt | 6 +++--- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt index d636b5cd..393f7228 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt @@ -3,13 +3,15 @@ package com.dobby.backend.application.usecase.experiment import com.dobby.backend.application.usecase.UseCase import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus class GetExperimentPostCountsByRegionUseCase( private val experimentPostGateway: ExperimentPostGateway ) : UseCase { data class Input( - val region: String? + val region: String?, + val recruitStatus: RecruitStatus ) data class Output( @@ -23,10 +25,16 @@ class GetExperimentPostCountsByRegionUseCase( ) override fun execute(input: Input): Output { - val total = experimentPostGateway.countExperimentPosts() + val total = when (input.recruitStatus) { + RecruitStatus.ALL -> experimentPostGateway.countExperimentPosts() + RecruitStatus.OPEN -> experimentPostGateway.countExperimentPostsByRecruitStatus(true) + } val allRegions = Region.values().filter { it != Region.NONE } - val regionData = experimentPostGateway.countExperimentPostGroupedByRegion() + val regionData = when (input.recruitStatus) { + RecruitStatus.ALL -> experimentPostGateway.countExperimentPostGroupedByRegion() + RecruitStatus.OPEN -> experimentPostGateway.countExperimentPostGroupedByRegionAndRecruitStatus(true) + } val regionDataMap = regionData.associateBy { it.get(0, Region::class.java) } val area = allRegions.map { region -> diff --git a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt index 1ddf23b9..5c669950 100644 --- a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt +++ b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt @@ -4,6 +4,7 @@ import com.dobby.backend.domain.model.experiment.CustomFilter import com.dobby.backend.domain.model.experiment.Pagination import com.dobby.backend.domain.model.experiment.ExperimentPost import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import jakarta.persistence.Tuple import java.time.LocalDate @@ -13,8 +14,10 @@ interface ExperimentPostGateway { fun findById(experimentPostId: Long): ExperimentPost? fun countExperimentPostsByRegion(region: Region): Int fun countExperimentPosts(): Int + fun countExperimentPostsByRecruitStatus(recruitStatus: Boolean): Int fun countExperimentPostByRegionGroupedByArea(region: Region): List fun countExperimentPostGroupedByRegion(): List + fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List fun updateExperimentPostStatus(currentDate : LocalDate) : Long fun findExperimentPostsByMemberIdWithPagination(memberId: Long, pagination: Pagination, order: String): List? fun countExperimentPostsByMemberId(memberId: Long): Int diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt index 7aa637e4..94ceb892 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt @@ -17,4 +17,9 @@ interface ExperimentPostRepository : JpaRepository { fun countExperimentPostGroupedByRegion(): List fun countByMemberId(memberId: Long): Int + + fun countByRecruitStatus(recruitStatus: Boolean): Int + + @Query("SELECT e.region, COUNT(e) FROM experiment_post e WHERE e.recruitStatus = :recruitStatus GROUP BY e.region") + fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List } diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt index 76183d8d..6fe54e2a 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt @@ -6,6 +6,7 @@ import com.dobby.backend.domain.model.experiment.ExperimentPost import com.dobby.backend.domain.model.experiment.Pagination import com.dobby.backend.infrastructure.converter.ExperimentPostConverter import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import com.dobby.backend.infrastructure.database.entity.experiment.ExperimentPostEntity import com.dobby.backend.infrastructure.database.repository.ExperimentPostCustomRepository import com.dobby.backend.infrastructure.database.repository.ExperimentPostRepository @@ -49,6 +50,10 @@ class ExperimentPostGatewayImpl( return experimentPostRepository.count().toInt() } + override fun countExperimentPostsByRecruitStatus(recruitStatus: Boolean): Int { + return experimentPostRepository.countByRecruitStatus(recruitStatus) + } + override fun countExperimentPostByRegionGroupedByArea(region: Region): List { return experimentPostRepository.countExperimentPostByRegionGroupedByArea(region) } @@ -57,6 +62,10 @@ class ExperimentPostGatewayImpl( return experimentPostRepository.countExperimentPostGroupedByRegion() } + override fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List { + return experimentPostRepository.countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus) + } + override fun updateExperimentPostStatus(currentDate: LocalDate): Long { return experimentPostCustomRepository.updateExperimentPostStatus(currentDate) } diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt index dc905e8e..14b8853c 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt @@ -73,9 +73,10 @@ class ExperimentPostController ( description = "지역 별로 등록된 공고 수를 조회합니다" ) fun getExperimentPostCounts( - @RequestParam(required = false) region: String? + @RequestParam(required = false) region: String?, + @RequestParam(required = false, defaultValue = "ALL") recruitStatus: String ): ExperimentPostCountsResponse { - val input = ExperimentPostMapper.toGetExperimentPostCountsUseCaseInput(region) + val input = ExperimentPostMapper.toGetExperimentPostCountsUseCaseInput(region, recruitStatus) val output = experimentPostService.getExperimentPostCounts(input) return ExperimentPostMapper.toGetExperimentPostCountsResponse(output) } diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt index bce87726..0f839260 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt @@ -106,11 +106,11 @@ object ExperimentPostMapper { ) } - fun toGetExperimentPostCountsUseCaseInput(region: String?): Any { + fun toGetExperimentPostCountsUseCaseInput(region: String?, recruitStatus: String): Any { return if (region == null) { - GetExperimentPostCountsByRegionUseCase.Input(region = null) + GetExperimentPostCountsByRegionUseCase.Input(region = null, RecruitStatus.fromString(recruitStatus)) } else { - GetExperimentPostCountsByAreaUseCase.Input(region = region) + GetExperimentPostCountsByAreaUseCase.Input(region = region, RecruitStatus.fromString(recruitStatus)) } } From ebb8b7f25df263e16942a7dae4c667cd0ca65422 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 17:01:02 +0900 Subject: [PATCH 5/8] refact: add recruitStatus condition to GetExperimentPostCountsByAreaUseCase --- .../GetExperimentPostCountsByAreaUseCase.kt | 15 ++++++++++++--- .../gateway/experiment/ExperimentPostGateway.kt | 3 ++- .../repository/ExperimentPostRepository.kt | 5 +++++ .../experiment/ExperimentPostGatewayImpl.kt | 9 ++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCase.kt index ba5516e3..c91258bb 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCase.kt @@ -4,6 +4,7 @@ import com.dobby.backend.application.usecase.UseCase import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import jakarta.persistence.Tuple class GetExperimentPostCountsByAreaUseCase( @@ -11,7 +12,8 @@ class GetExperimentPostCountsByAreaUseCase( ) : UseCase { data class Input( - val region: String + val region: String, + val recruitStatus: RecruitStatus ) data class Output( @@ -27,8 +29,15 @@ class GetExperimentPostCountsByAreaUseCase( override fun execute(input: Input): Output { val region = Region.fromDisplayName(input.region) - val total = experimentPostGateway.countExperimentPostsByRegion(region) - val regionData = region.let { experimentPostGateway.countExperimentPostByRegionGroupedByArea(it) } + val total = when (input.recruitStatus) { + RecruitStatus.ALL -> experimentPostGateway.countExperimentPostsByRegion(region) + RecruitStatus.OPEN -> experimentPostGateway.countExperimentPostsByRegionAndRecruitStatus(region, true) + } + + val regionData = when (input.recruitStatus) { + RecruitStatus.ALL -> region.let { experimentPostGateway.countExperimentPostByRegionGroupedByArea(it) } + RecruitStatus.OPEN -> region.let { experimentPostGateway.countExperimentPostByRegionAndRecruitStatusGroupedByArea(it, true) } + } val areaCounts = getAreaCounts(region, regionData) return Output(total, areaCounts) diff --git a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt index 5c669950..d6054f2c 100644 --- a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt +++ b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt @@ -4,7 +4,6 @@ import com.dobby.backend.domain.model.experiment.CustomFilter import com.dobby.backend.domain.model.experiment.Pagination import com.dobby.backend.domain.model.experiment.ExperimentPost import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region -import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import jakarta.persistence.Tuple import java.time.LocalDate @@ -13,9 +12,11 @@ interface ExperimentPostGateway { fun findExperimentPostsByCustomFilter(customFilter: CustomFilter, pagination: Pagination): List? fun findById(experimentPostId: Long): ExperimentPost? fun countExperimentPostsByRegion(region: Region): Int + fun countExperimentPostsByRegionAndRecruitStatus(region: Region, recruitStatus: Boolean): Int fun countExperimentPosts(): Int fun countExperimentPostsByRecruitStatus(recruitStatus: Boolean): Int fun countExperimentPostByRegionGroupedByArea(region: Region): List + fun countExperimentPostByRegionAndRecruitStatusGroupedByArea(region: Region, recruitStatus: Boolean): List fun countExperimentPostGroupedByRegion(): List fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List fun updateExperimentPostStatus(currentDate : LocalDate) : Long diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt index 94ceb892..e23ab40d 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt @@ -10,9 +10,14 @@ import org.springframework.data.repository.query.Param interface ExperimentPostRepository : JpaRepository { fun countByRegion(region: Region): Int + fun countByRegionAndRecruitStatus(region: Region, recruitStatus: Boolean): Int + @Query("SELECT e.area, COUNT(e) FROM experiment_post e WHERE e.region = :region GROUP BY e.area") fun countExperimentPostByRegionGroupedByArea(@Param("region") region: Region): List + @Query("SELECT e.area, COUNT(e) FROM experiment_post e WHERE e.region = :region AND e.recruitStatus = :recruitStatus GROUP BY e.area") + fun countExperimentPostByRegionAndRecruitStatusGroupedByArea(region: Region, recruitStatus: Boolean): List + @Query("SELECT e.region, COUNT(e) FROM experiment_post e GROUP BY e.region") fun countExperimentPostGroupedByRegion(): List diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt index 6fe54e2a..54c734fe 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt @@ -6,7 +6,6 @@ import com.dobby.backend.domain.model.experiment.ExperimentPost import com.dobby.backend.domain.model.experiment.Pagination import com.dobby.backend.infrastructure.converter.ExperimentPostConverter import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region -import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import com.dobby.backend.infrastructure.database.entity.experiment.ExperimentPostEntity import com.dobby.backend.infrastructure.database.repository.ExperimentPostCustomRepository import com.dobby.backend.infrastructure.database.repository.ExperimentPostRepository @@ -46,6 +45,10 @@ class ExperimentPostGatewayImpl( return experimentPostRepository.countByRegion(region) } + override fun countExperimentPostsByRegionAndRecruitStatus(region: Region, recruitStatus: Boolean): Int { + return experimentPostRepository.countByRegionAndRecruitStatus(region, recruitStatus) + } + override fun countExperimentPosts(): Int { return experimentPostRepository.count().toInt() } @@ -58,6 +61,10 @@ class ExperimentPostGatewayImpl( return experimentPostRepository.countExperimentPostByRegionGroupedByArea(region) } + override fun countExperimentPostByRegionAndRecruitStatusGroupedByArea(region: Region, recruitStatus: Boolean): List { + return experimentPostRepository.countExperimentPostByRegionAndRecruitStatusGroupedByArea(region, recruitStatus) + } + override fun countExperimentPostGroupedByRegion(): List { return experimentPostRepository.countExperimentPostGroupedByRegion() } From 9cc158b02c688a0643053d37495fa539f5f39eb7 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 17:14:20 +0900 Subject: [PATCH 6/8] test: fix failed test due to added condition --- .../GetExperimentPostCountsByRegionUseCase.kt | 2 +- .../experiment/ExperimentPostGateway.kt | 2 +- .../repository/ExperimentPostRepository.kt | 2 +- .../experiment/ExperimentPostGatewayImpl.kt | 4 +-- ...etExperimentPostCountsByAreaUseCaseTest.kt | 27 +++++++++++++++-- ...ExperimentPostCountsByRegionUseCaseTest.kt | 29 +++++++++++++++---- 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt index 393f7228..52231254 100644 --- a/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt +++ b/src/main/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCase.kt @@ -33,7 +33,7 @@ class GetExperimentPostCountsByRegionUseCase( val allRegions = Region.values().filter { it != Region.NONE } val regionData = when (input.recruitStatus) { RecruitStatus.ALL -> experimentPostGateway.countExperimentPostGroupedByRegion() - RecruitStatus.OPEN -> experimentPostGateway.countExperimentPostGroupedByRegionAndRecruitStatus(true) + RecruitStatus.OPEN -> experimentPostGateway.countExperimentPostsByRecruitStatusGroupedByRegion(true) } val regionDataMap = regionData.associateBy { it.get(0, Region::class.java) } diff --git a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt index d6054f2c..a13542d7 100644 --- a/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt +++ b/src/main/kotlin/com/dobby/backend/domain/gateway/experiment/ExperimentPostGateway.kt @@ -18,7 +18,7 @@ interface ExperimentPostGateway { fun countExperimentPostByRegionGroupedByArea(region: Region): List fun countExperimentPostByRegionAndRecruitStatusGroupedByArea(region: Region, recruitStatus: Boolean): List fun countExperimentPostGroupedByRegion(): List - fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List + fun countExperimentPostsByRecruitStatusGroupedByRegion(recruitStatus: Boolean): List fun updateExperimentPostStatus(currentDate : LocalDate) : Long fun findExperimentPostsByMemberIdWithPagination(memberId: Long, pagination: Pagination, order: String): List? fun countExperimentPostsByMemberId(memberId: Long): Int diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt index e23ab40d..0f36cbfb 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/database/repository/ExperimentPostRepository.kt @@ -26,5 +26,5 @@ interface ExperimentPostRepository : JpaRepository { fun countByRecruitStatus(recruitStatus: Boolean): Int @Query("SELECT e.region, COUNT(e) FROM experiment_post e WHERE e.recruitStatus = :recruitStatus GROUP BY e.region") - fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List + fun countExperimentPostsByRecruitStatusGroupedByRegion(recruitStatus: Boolean): List } diff --git a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt index 54c734fe..704902c9 100644 --- a/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt +++ b/src/main/kotlin/com/dobby/backend/infrastructure/gateway/experiment/ExperimentPostGatewayImpl.kt @@ -69,8 +69,8 @@ class ExperimentPostGatewayImpl( return experimentPostRepository.countExperimentPostGroupedByRegion() } - override fun countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus: Boolean): List { - return experimentPostRepository.countExperimentPostGroupedByRegionAndRecruitStatus(recruitStatus) + override fun countExperimentPostsByRecruitStatusGroupedByRegion(recruitStatus: Boolean): List { + return experimentPostRepository.countExperimentPostsByRecruitStatusGroupedByRegion(recruitStatus) } override fun updateExperimentPostStatus(currentDate: LocalDate): Long { diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCaseTest.kt index 6c0fec52..948fdbff 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByAreaUseCaseTest.kt @@ -2,6 +2,7 @@ import com.dobby.backend.application.usecase.experiment.GetExperimentPostCountsB import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.mockk.every @@ -31,8 +32,28 @@ class GetExperimentPostCountsByAreaUseCaseTest : BehaviorSpec({ every { experimentPostGateway.countExperimentPostsByRegion(region) } returns 15 every { experimentPostGateway.countExperimentPostByRegionGroupedByArea(region) } returns regionData - `when`("execute가 호출되면") { - val input = GetExperimentPostCountsByAreaUseCase.Input(regionName) + `when`("모든 공고를 조회하는 execute가 호출되면") { + val input = GetExperimentPostCountsByAreaUseCase.Input(regionName, RecruitStatus.ALL) + val result = getExperimentPostCountsByAreaUseCase.execute(input) + + then("총 공고 개수가 반환된다") { + result.total shouldBe 15 + } + + then("지역별 공고 개수가 반환된다") { + result.area.size shouldBe 26 + result.area[0].name shouldBe Area.SEOUL_ALL.displayName + result.area[0].count shouldBe 5 + result.area[1].name shouldBe Area.GEUMCHEONGU.displayName + result.area[1].count shouldBe 10 + } + } + + every { experimentPostGateway.countExperimentPostsByRegionAndRecruitStatus(region, true) } returns 15 + every { experimentPostGateway.countExperimentPostByRegionAndRecruitStatusGroupedByArea(region, true) } returns regionData + + `when`("모집중인 공고를 조회하는 execute가 호출되면") { + val input = GetExperimentPostCountsByAreaUseCase.Input(regionName, RecruitStatus.OPEN) val result = getExperimentPostCountsByAreaUseCase.execute(input) then("총 공고 개수가 반환된다") { @@ -53,7 +74,7 @@ class GetExperimentPostCountsByAreaUseCaseTest : BehaviorSpec({ val invalidRegionName = "INVALID_REGION" `when`("execute가 호출되면") { - val input = GetExperimentPostCountsByAreaUseCase.Input(invalidRegionName) + val input = GetExperimentPostCountsByAreaUseCase.Input(invalidRegionName, RecruitStatus.ALL) then("예외가 발생한다") { val exception = runCatching { getExperimentPostCountsByAreaUseCase.execute(input) }.exceptionOrNull() diff --git a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCaseTest.kt b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCaseTest.kt index e0a7470c..5124f1b9 100644 --- a/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCaseTest.kt +++ b/src/test/kotlin/com/dobby/backend/application/usecase/experiment/GetExperimentPostCountsByRegionUseCaseTest.kt @@ -1,6 +1,7 @@ import com.dobby.backend.application.usecase.experiment.GetExperimentPostCountsByRegionUseCase import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe import io.mockk.every @@ -11,7 +12,7 @@ class GetExperimentPostCountsByRegionUseCaseTest : BehaviorSpec({ val experimentPostGateway = mockk() val getExperimentPostCountsByRegionUseCase = GetExperimentPostCountsByRegionUseCase(experimentPostGateway) - given("유효한 지역 정보가 주어졌을 때") { + given("유효한 지역 이름이 주어졌을 때") { val regionData = listOf( mockk().apply { every { get(0, Region::class.java) } returns Region.SEOUL @@ -26,8 +27,26 @@ class GetExperimentPostCountsByRegionUseCaseTest : BehaviorSpec({ every { experimentPostGateway.countExperimentPosts() } returns 20 every { experimentPostGateway.countExperimentPostGroupedByRegion() } returns regionData - `when`("execute가 호출되면") { - val input = GetExperimentPostCountsByRegionUseCase.Input(region = null) + `when`("모든 공고를 조회하는 execute가 호출되면") { + val input = GetExperimentPostCountsByRegionUseCase.Input(region = null, recruitStatus = RecruitStatus.ALL) + val result = getExperimentPostCountsByRegionUseCase.execute(input) + + then("전체 공고 개수가 반환된다") { + result.total shouldBe 20 + } + + then("지역별 공고 개수가 반환된다") { + result.area.size shouldBe 17 + result.area.find { it.name == "SEOUL" }?.count shouldBe 5 + result.area.find { it.name == "GYEONGGI" }?.count shouldBe 10 + } + } + + every { experimentPostGateway.countExperimentPostsByRecruitStatus(true) } returns 20 + every { experimentPostGateway.countExperimentPostsByRecruitStatusGroupedByRegion(true) } returns regionData + + `when`("모집중인 공고를 조회하는 execute가 호출되면") { + val input = GetExperimentPostCountsByRegionUseCase.Input(region = null, recruitStatus = RecruitStatus.OPEN) val result = getExperimentPostCountsByRegionUseCase.execute(input) then("전체 공고 개수가 반환된다") { @@ -58,7 +77,7 @@ class GetExperimentPostCountsByRegionUseCaseTest : BehaviorSpec({ every { experimentPostGateway.countExperimentPostGroupedByRegion() } returns regionData `when`("execute가 호출되면") { - val input = GetExperimentPostCountsByRegionUseCase.Input(region = null) + val input = GetExperimentPostCountsByRegionUseCase.Input(region = null, recruitStatus = RecruitStatus.ALL) val result = getExperimentPostCountsByRegionUseCase.execute(input) then("전체 공고 개수는 20이어야 한다") { @@ -79,7 +98,7 @@ class GetExperimentPostCountsByRegionUseCaseTest : BehaviorSpec({ val invalidRegionName = "INVALID_REGION" `when`("execute가 호출되면") { - val input = GetExperimentPostCountsByRegionUseCase.Input(region = invalidRegionName) + val input = GetExperimentPostCountsByRegionUseCase.Input(region = invalidRegionName, recruitStatus = RecruitStatus.ALL) then("null이 반환된다") { val result = runCatching { getExperimentPostCountsByRegionUseCase.execute(input) }.exceptionOrNull() From 495b20ef696081929f5ce078f11e7729d1d796ea Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 17:27:25 +0900 Subject: [PATCH 7/8] refact: delete unused file and alter description --- .../dto/request/experiment/CustomFilter.kt | 37 ------------------- .../ExperimentPostDetailResponse.kt | 2 +- .../member/MyExperimentPostResponse.kt | 2 +- 3 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt deleted file mode 100644 index ad2a81ad..00000000 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/CustomFilter.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.dobby.backend.presentation.api.dto.request.experiment - -import com.dobby.backend.infrastructure.database.entity.enums.GenderType -import com.dobby.backend.infrastructure.database.entity.enums.MatchType -import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area -import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region -import io.swagger.v3.oas.annotations.media.Schema - -data class CustomFilter ( - @Schema(description = "진행 방식 필터") - val matchType : MatchType?, - - @Schema(description = "모집 대상") - val studyTarget: StudyTarget?, - - @Schema(description = "지역") - val locationTarget: LocationTarget?, - - @Schema(description = "공고 상태 필터 - false이면 모집 중인 공고만 확인 가능") - val recruitStatus: Boolean?, -) - -data class StudyTarget ( - @Schema(description = "모집 대상 - 성별 필터") - val gender : GenderType?, - - @Schema(description = "모집 대상 - 나이 필터") - val age: Int? -) - -data class LocationTarget ( - @Schema(description = "지역 - 시/도 필터") - val region: Region?, - - @Schema(description = "지역 - 시/군/구 필터") - val areas: List?, -) diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt index 49b4e807..6d74f9f9 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/experiment/ExperimentPostDetailResponse.kt @@ -25,7 +25,7 @@ data class ExperimentPostDetailResponse( @Schema(description = "조회수", example = "123") val views: Int, - @Schema(description = "모집 완료 여부", example = "true") + @Schema(description = "모집 상태 여부", example = "true") val recruitStatus: Boolean, @Schema(description = "요약 정보", example = "실험 공고의 요약(주요) 정보") diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt index fb5789d8..1cf43373 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/dto/response/member/MyExperimentPostResponse.kt @@ -16,7 +16,7 @@ data class MyExperimentPostResponse( @Schema(description = "조회수", example = "123") val views: Int, - @Schema(description = "모집 완료 여부", example = "false") + @Schema(description = "모집 상태 여부", example = "false") val recruitStatus: Boolean, @Schema(description = "업로드 날짜", example = "2025-01-01") From fe199261d607b7b0c112879948baa3eb9c863be5 Mon Sep 17 00:00:00 2001 From: jisu Date: Sun, 19 Jan 2025 20:16:11 +0900 Subject: [PATCH 8/8] refact: alter recruitStatus's parameter type --- .../api/controller/ExperimentPostController.kt | 5 +++-- .../presentation/api/mapper/ExperimentPostMapper.kt | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt index 14b8853c..4d9443ef 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/controller/ExperimentPostController.kt @@ -7,6 +7,7 @@ import com.dobby.backend.infrastructure.database.entity.enums.GenderType import com.dobby.backend.infrastructure.database.entity.enums.MatchType import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Area import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region +import com.dobby.backend.infrastructure.database.entity.enums.experiment.RecruitStatus import com.dobby.backend.presentation.api.dto.request.experiment.CreateExperimentPostRequest import com.dobby.backend.presentation.api.dto.response.experiment.* import com.dobby.backend.presentation.api.dto.response.experiment.CreateExperimentPostResponse @@ -74,7 +75,7 @@ class ExperimentPostController ( ) fun getExperimentPostCounts( @RequestParam(required = false) region: String?, - @RequestParam(required = false, defaultValue = "ALL") recruitStatus: String + @RequestParam(required = false, defaultValue = "ALL") recruitStatus: RecruitStatus ): ExperimentPostCountsResponse { val input = ExperimentPostMapper.toGetExperimentPostCountsUseCaseInput(region, recruitStatus) val output = experimentPostService.getExperimentPostCounts(input) @@ -105,7 +106,7 @@ class ExperimentPostController ( @RequestParam(required = false) age: Int?, @RequestParam(required = false) region: Region?, @RequestParam(required = false) areas: List?, - @RequestParam(required = false, defaultValue = "ALL") recruitStatus: String, + @RequestParam(required = false, defaultValue = "ALL") recruitStatus: RecruitStatus, @RequestParam(defaultValue = "1") page: Int, @RequestParam(defaultValue = "6") count: Int ): List { diff --git a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt index 0f839260..d3a8e150 100644 --- a/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt +++ b/src/main/kotlin/com/dobby/backend/presentation/api/mapper/ExperimentPostMapper.kt @@ -106,11 +106,11 @@ object ExperimentPostMapper { ) } - fun toGetExperimentPostCountsUseCaseInput(region: String?, recruitStatus: String): Any { + fun toGetExperimentPostCountsUseCaseInput(region: String?, recruitStatus: RecruitStatus): Any { return if (region == null) { - GetExperimentPostCountsByRegionUseCase.Input(region = null, RecruitStatus.fromString(recruitStatus)) + GetExperimentPostCountsByRegionUseCase.Input(region = null, recruitStatus) } else { - GetExperimentPostCountsByAreaUseCase.Input(region = region, RecruitStatus.fromString(recruitStatus)) + GetExperimentPostCountsByAreaUseCase.Input(region = region, recruitStatus) } } @@ -163,7 +163,7 @@ object ExperimentPostMapper { age: Int?, region: Region?, areas: List?, - recruitStatus: String + recruitStatus: RecruitStatus ): GetExperimentPostsUseCase.CustomFilterInput { return GetExperimentPostsUseCase.CustomFilterInput( matchType = matchType, @@ -175,7 +175,7 @@ object ExperimentPostMapper { region = region, areas = areas ), - recruitStatus = RecruitStatus.fromString(recruitStatus) + recruitStatus = recruitStatus ) }