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 ) } } 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/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) + } + } 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) + } + } + } + } + }) 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); + }