Skip to content

Commit

Permalink
Merge pull request #158 from KUSITMS-29th-TEAM-B/refactor/flight-157
Browse files Browse the repository at this point in the history
refactor : JD 상세정보 조회 응답값 수정
  • Loading branch information
isprogrammingfun authored May 23, 2024
2 parents 103f030 + 4b604a3 commit 00fd78a
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<JobDescriptionInfo.Response.Basic> {
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,
Expand All @@ -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,
Expand All @@ -54,7 +61,8 @@ class JobDescriptionInfoGetService(
jobDescription.writeStatus,
jobDescription.createdAt,
jobDescription.startedAt,
jobDescription.endedAt
jobDescription.endedAt,
isExists
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,9 +17,52 @@ import java.util.*

class JobDescriptionInfoGetServiceTest : BehaviorSpec({
val jobDescriptionReader = mockk<JobDescriptionReader>()
val jobDescriptionInfoGetService = JobDescriptionInfoGetService(jobDescriptionReader)
val applyReader = mockk<ApplyReader>()
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", "기업 이름")
Expand All @@ -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
)
}
}
}


})
Original file line number Diff line number Diff line change
Expand Up @@ -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("자기소개서 작성 여부")
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface ApplyRepository {

fun findByJobDescriptionId(jobDescriptionId: UUID): Apply

fun existsByJobDescriptionId(jobDescriptionId: UUID): Boolean

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ class ApplyReader(
return applyRepository.findByJobDescriptionId(JobDescriptionId)
}

fun readApplyExists(JobDescriptionId: UUID): Boolean{
return applyRepository.existsByJobDescriptionId(JobDescriptionId)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface ApplyJpaRepository extends JpaRepository<ApplyJpaEntity, UUID>

Optional<ApplyJpaEntity> findByJobDescriptionId(UUID jobDescriptionId);

boolean existsByJobDescriptionId(UUID jobDescriptionId);

}

0 comments on commit 00fd78a

Please sign in to comment.