From 5aaad7a7005656e30dcc327b6bd345fc929023c1 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 14:55:23 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor=20:=20=EC=9E=90=EA=B8=B0=EC=86=8C?= =?UTF-8?q?=EA=B0=9C=EC=84=9C=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80(#1?= =?UTF-8?q?57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/jobDescription/repository/ApplyRepository.kt | 2 ++ .../domainmodule/domain/jobDescription/service/ApplyReader.kt | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/ApplyRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/ApplyRepository.kt index feecdb5f..d5323ee0 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/ApplyRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/ApplyRepository.kt @@ -8,4 +8,6 @@ interface ApplyRepository { fun findByJobDescriptionId(jobDescriptionId: UUID): Apply + fun existsByJobDescriptionId(jobDescriptionId: UUID): Boolean + } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReader.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReader.kt index 94734988..5a23ba9f 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReader.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReader.kt @@ -12,4 +12,8 @@ class ApplyReader( return applyRepository.findByJobDescriptionId(JobDescriptionId) } + fun readApplyExists(JobDescriptionId: UUID): Boolean{ + return applyRepository.existsByJobDescriptionId(JobDescriptionId) + } + } From 429630837556f16e3943fddbe32f63208338564a Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 14:55:34 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor=20:=20=EA=B4=80=EB=A0=A8=20presist?= =?UTF-8?q?ence=20=EA=B3=84=EC=B8=B5=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/jobDescription/ApplyRepositoryImpl.java | 7 +++++++ .../jobDescription/jpa/repository/ApplyJpaRepository.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/ApplyRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/ApplyRepositoryImpl.java index 8c9dad32..4778bf26 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/ApplyRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/ApplyRepositoryImpl.java @@ -8,6 +8,7 @@ import com.bamyanggang.persistence.jobDescription.mapper.JobDescriptionMapper; import java.util.UUID; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Repository; @Repository @@ -28,4 +29,10 @@ public Apply findByJobDescriptionId(UUID jobDescriptionId) { .map(jobDescriptionMapper::toApplyDomainEntity) .orElseThrow(() -> new PersistenceException.NotFound()); } + + @Override + public boolean existsByJobDescriptionId(UUID jobDescriptionId) { + return applyJpaRepository.existsByJobDescriptionId(jobDescriptionId); + } + } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/ApplyJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/ApplyJpaRepository.java index 4c5092f6..493195a2 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/ApplyJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/ApplyJpaRepository.java @@ -9,4 +9,6 @@ public interface ApplyJpaRepository extends JpaRepository Optional findByJobDescriptionId(UUID jobDescriptionId); + boolean existsByJobDescriptionId(UUID jobDescriptionId); + } From 75b0379bb700f03c2c0f1eb0cddc3f6f7ff7bbbf Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 14:56:00 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor=20:=20JD=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EA=B0=92=20=EC=88=98=EC=A0=95(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/JobDescriptionInfo.kt | 3 ++- .../service/JobDescriptionInfoGetService.kt | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/dto/JobDescriptionInfo.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/dto/JobDescriptionInfo.kt index 600b80bc..48296abb 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/dto/JobDescriptionInfo.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/dto/JobDescriptionInfo.kt @@ -39,7 +39,8 @@ class JobDescriptionInfo { val writeStatus: WriteStatus, val createdAt: LocalDateTime, val startedAt: LocalDateTime, - val endedAt: LocalDateTime + val endedAt: LocalDateTime, + val isApplyExists: Boolean ): Response() } diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoGetService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoGetService.kt index 07207190..33c05518 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoGetService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoGetService.kt @@ -6,6 +6,7 @@ import com.bamyanggang.apimodule.domain.jobDescription.application.dto.JobDescri import com.bamyanggang.domainmodule.common.pagination.PageDomain import com.bamyanggang.domainmodule.domain.jobDescription.enums.SortType import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus +import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader import org.springframework.data.domain.Pageable import org.springframework.stereotype.Service @@ -16,13 +17,13 @@ import java.util.UUID @Service class JobDescriptionInfoGetService( private val jobDescriptionReader: JobDescriptionReader, + private val applyReader: ApplyReader ) { @Transactional(readOnly = true) fun getJobDescriptionInfo(pageable: Pageable, writeStatus: WriteStatus?, sortType: SortType?): PageResponse { return getAuthenticationPrincipal().let{ userId -> val jobDescriptions = jobDescriptionReader.readJobDescriptionByUserIdAndSortType(userId, pageable.pageNumber, pageable.pageSize, sortType, writeStatus) - val jobDescriptionInfoResponses = jobDescriptions.content.map{ jobDescription -> JobDescriptionInfo.Response.Basic( jobDescription.id, @@ -45,6 +46,12 @@ class JobDescriptionInfoGetService( @Transactional(readOnly = true) fun getJobDescriptionDetail(jobDescriptionId: UUID): JobDescriptionInfo.Response.Detail { return jobDescriptionReader.readJobDescriptionById(jobDescriptionId).let{ jobDescription -> + val isExists = when(jobDescription.writeStatus) { + WriteStatus.WRITING -> true + WriteStatus.NOT_APPLIED -> false + WriteStatus.WRITTEN -> true + else -> applyReader.readApplyExists(jobDescriptionId) + } JobDescriptionInfo.Response.Detail( jobDescription.getRemainingDate(), jobDescription.enterpriseName, @@ -54,7 +61,8 @@ class JobDescriptionInfoGetService( jobDescription.writeStatus, jobDescription.createdAt, jobDescription.startedAt, - jobDescription.endedAt + jobDescription.endedAt, + isExists ) } } From 4b604a3f4c67fc1b9b629836c24549bc3544b4d6 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 May 2024 14:56:42 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test=20:=20JD=20=EC=83=81=EC=84=B8=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EA=B0=92=20=EC=88=98=EC=A0=95=EC=97=90=20=EC=9D=98?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=B6=94=EA=B0=80(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JobDescriptionInfoGetServiceTest.kt | 72 ++++++++++++++++++- .../JobDescriptionControllerTest.kt | 3 +- .../jobDescription/service/ApplyReaderTest.kt | 12 ++++ 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionInfoGetServiceTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionInfoGetServiceTest.kt index dfb0ab00..04a8ee0d 100644 --- a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionInfoGetServiceTest.kt +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionInfoGetServiceTest.kt @@ -1,11 +1,14 @@ package com.bamyanggang.apimodule.domain.jobDescription.application +import com.bamyanggang.apimodule.domain.jobDescription.application.dto.JobDescriptionInfo import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionInfoGetService import com.bamyanggang.commonmodule.fixture.generateFixture import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.JobDescription import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus +import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader import io.kotest.core.spec.style.BehaviorSpec +import io.kotest.matchers.shouldBe import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -14,9 +17,52 @@ import java.util.* class JobDescriptionInfoGetServiceTest : BehaviorSpec({ val jobDescriptionReader = mockk() - val jobDescriptionInfoGetService = JobDescriptionInfoGetService(jobDescriptionReader) + val applyReader = mockk() + val jobDescriptionInfoGetService = JobDescriptionInfoGetService(jobDescriptionReader, applyReader) - Given("jobDescriptionId가 들어온 경우") { + Given("jobDescription의 writeStatus가 CLOSED인 경우") { + val jobDescriptionId = UUID.randomUUID() + val jobDescription : JobDescription = generateFixture { + it.set("enterpriseName", "기업 이름") + it.set("title", "직무 공고 제목") + it.set("content", "직무 공고 내용") + it.set("link", "직무 공고 링크") + it.set("writeStatus", WriteStatus.CLOSED) + it.set("startedAt", LocalDateTime.now()) + it.set("endedAt", LocalDateTime.now().plusDays(1)) + } + every { jobDescriptionReader.readJobDescriptionById(jobDescriptionId) } returns jobDescription + every { applyReader.readApplyExists(jobDescriptionId) } returns true + + When("getJobDescriptionDetail가 호출된다") { + val result = jobDescriptionInfoGetService.getJobDescriptionDetail(jobDescriptionId) + + Then("jobDescriptionReader.readJobDescriptionById가 호출된다") { + verify { jobDescriptionReader.readJobDescriptionById(jobDescriptionId) } + } + + And("applyReader.readApplyExists가 호출된다") { + verify { applyReader.readApplyExists(jobDescriptionId) } + } + + And("예상된 JobDescriptionInfo.Response.Detail 객체가 반환된다") { + result shouldBe JobDescriptionInfo.Response.Detail( + jobDescription.getRemainingDate(), + jobDescription.enterpriseName, + jobDescription.title, + jobDescription.content, + jobDescription.link, + jobDescription.writeStatus, + jobDescription.createdAt, + jobDescription.startedAt, + jobDescription.endedAt, + true + ) + } + } + } + + Given("jobDescription의 writeStatus가 WRITING인 경우") { val jobDescriptionId = UUID.randomUUID() val jobDescription : JobDescription = generateFixture { it.set("enterpriseName", "기업 이름") @@ -30,12 +76,32 @@ class JobDescriptionInfoGetServiceTest : BehaviorSpec({ every { jobDescriptionReader.readJobDescriptionById(jobDescriptionId) } returns jobDescription When("getJobDescriptionDetail가 호출된다") { - jobDescriptionInfoGetService.getJobDescriptionDetail(jobDescriptionId) + val result = jobDescriptionInfoGetService.getJobDescriptionDetail(jobDescriptionId) Then("jobDescriptionReader.readJobDescriptionById가 호출된다") { verify { jobDescriptionReader.readJobDescriptionById(jobDescriptionId) } } + + And("applyReader.readApplyExists는 호출되지 않는다") { + verify(exactly = 0) { applyReader.readApplyExists(jobDescriptionId) } + } + + And("예상된 JobDescriptionInfo.Response.Detail 객체가 반환된다") { + result shouldBe JobDescriptionInfo.Response.Detail( + jobDescription.getRemainingDate(), + jobDescription.enterpriseName, + jobDescription.title, + jobDescription.content, + jobDescription.link, + jobDescription.writeStatus, + jobDescription.createdAt, + jobDescription.startedAt, + jobDescription.endedAt, + true + ) + } } } + }) diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionControllerTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionControllerTest.kt index c6fc3225..ae59a007 100644 --- a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionControllerTest.kt +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionControllerTest.kt @@ -368,7 +368,8 @@ class JobDescriptionControllerTest : BaseRestDocsTest() { fieldWithPath("writeStatus").description("작성 상태. NOT_APPLIED(칩 없음, 작성 전), WRITING(작성 중), WRITTEN(작성 완료), CLOSED(마감)"), fieldWithPath("createdAt").description("생성일"), fieldWithPath("startedAt").description("시작일"), - fieldWithPath("endedAt").description("종료일") + fieldWithPath("endedAt").description("종료일"), + fieldWithPath("isApplyExists").description("자기소개서 작성 여부") ) ) ) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReaderTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReaderTest.kt index 00dbe2f2..f3e845ed 100644 --- a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReaderTest.kt +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/ApplyReaderTest.kt @@ -22,4 +22,16 @@ class ApplyReaderTest: BehaviorSpec({ } } + given("ApplyReader.readApplyExists") { + val jobDescriptionId: UUID = UUID.randomUUID() + `when`("jobDescriptionId가 주어지면") { + applyReader.readApplyExists(jobDescriptionId) + then("applyRepository.existsByJobDescriptionId가 호출된다.") { + verify { + applyRepository.existsByJobDescriptionId(jobDescriptionId) + } + } + } + } + })