diff --git a/Api-Module/src/docs/asciidoc/JobDescription.adoc b/Api-Module/src/docs/asciidoc/JobDescription.adoc index 7c3b2372..c1ffb672 100644 --- a/Api-Module/src/docs/asciidoc/JobDescription.adoc +++ b/Api-Module/src/docs/asciidoc/JobDescription.adoc @@ -57,6 +57,10 @@ operation::JobDescriptionControllerTest/updateWriteStatus[snippets='http-request operation::JobDescriptionControllerTest/updateJobDescription[snippets='http-request,path-parameters,request-headers,request-fields,http-response'] [[DELETE-JD]] +=== JD 삭제 + +operation::JobDescriptionControllerTest/deleteJobDescription[snippets='http-request,path-parameters,request-headers,http-response'] + diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyInfoGetService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyInfoGetService.kt index c1eeb1ce..e5590e8f 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyInfoGetService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyInfoGetService.kt @@ -3,6 +3,7 @@ package com.bamyanggang.apimodule.domain.jobDescription.application.service import com.bamyanggang.apimodule.domain.jobDescription.application.dto.ApplyInfo import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import java.util.* @Service @@ -10,6 +11,7 @@ class ApplyInfoGetService( private val applyReader: ApplyReader ) { + @Transactional(readOnly = true) fun getApplyInfo(jobDescriptionId: UUID): ApplyInfo.Response { return applyReader.readApplyByJobDescriptionId(jobDescriptionId).contents.map { ApplyInfo.ContentInfo( diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyUpdateService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyUpdateService.kt index ae27c4af..475d8468 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyUpdateService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/ApplyUpdateService.kt @@ -4,13 +4,14 @@ import com.bamyanggang.apimodule.domain.jobDescription.application.dto.ApplyInfo import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.ApplyContent import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyModifier import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import java.util.* @Service class ApplyUpdateService( private val applyModifier: ApplyModifier ) { - + @Transactional fun updateApplyInfo(jobDescriptionId: UUID, request: ApplyInfo.Request.Update) { applyModifier.modifyApplyInfo( jobDescriptionId = jobDescriptionId, diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionDeleteService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionDeleteService.kt new file mode 100644 index 00000000..3f6ccc1a --- /dev/null +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionDeleteService.kt @@ -0,0 +1,18 @@ +package com.bamyanggang.apimodule.domain.jobDescription.application.service + +import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionRemover +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.util.* + +@Service +class JobDescriptionDeleteService( + private val jobDescriptionRemover: JobDescriptionRemover +) { + + @Transactional + fun deleteJobDescription(jobDescriptionId: UUID) { + jobDescriptionRemover.removeJobDescription(jobDescriptionId) + } + +} diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoUpdateService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoUpdateService.kt index b4887dd3..b1f5e2de 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoUpdateService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/service/JobDescriptionInfoUpdateService.kt @@ -3,16 +3,19 @@ package com.bamyanggang.apimodule.domain.jobDescription.application.service import com.bamyanggang.apimodule.domain.jobDescription.application.dto.JobDescriptionInfo import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionModifier import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import java.util.* @Service class JobDescriptionInfoUpdateService( private val jobDescriptionModifier: JobDescriptionModifier, ) { + @Transactional fun updateWriteStatus(jobDescriptionId: UUID) { jobDescriptionModifier.modifyWriteStatus(jobDescriptionId) } + @Transactional fun updateJobDescriptionDetail(jobDescriptionId: UUID, request: JobDescriptionInfo.Request.Update) { jobDescriptionModifier.modifyJobDescription( jobDescriptionId, request.enterpriseName, diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionController.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionController.kt index 7075511a..54ab8ff0 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionController.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/jobDescription/presentation/JobDescriptionController.kt @@ -6,6 +6,7 @@ import com.bamyanggang.apimodule.domain.jobDescription.application.service.* import com.bamyanggang.domainmodule.domain.jobDescription.enums.SortType import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus import org.springframework.data.domain.Pageable +import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PathVariable @@ -23,7 +24,8 @@ class JobDescriptionController( private val jobDescriptionInfoGetService: JobDescriptionInfoGetService, private val applyInfoGetService: ApplyInfoGetService, private val applyUpdateService: ApplyUpdateService, - private val jobDescriptionInfoUpdateService: JobDescriptionInfoUpdateService + private val jobDescriptionInfoUpdateService: JobDescriptionInfoUpdateService, + private val jobDescriptionDeleteService: JobDescriptionDeleteService ) { @PostMapping(JobDescriptionApi.BASE_URL) @@ -73,4 +75,9 @@ class JobDescriptionController( @RequestBody request: JobDescriptionInfo.Request.Update ) = jobDescriptionInfoUpdateService.updateJobDescriptionDetail(jobDescriptionId, request) + @DeleteMapping(JobDescriptionApi.DETAIL) + fun deleteJobDescription( + @PathVariable("jobDescriptionId") jobDescriptionId: UUID + ) = jobDescriptionDeleteService.deleteJobDescription(jobDescriptionId) + } diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionDeleteServiceTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionDeleteServiceTest.kt new file mode 100644 index 00000000..7ac7177f --- /dev/null +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/jobDescription/application/JobDescriptionDeleteServiceTest.kt @@ -0,0 +1,24 @@ +package com.bamyanggang.apimodule.domain.jobDescription.application + +import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionDeleteService +import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionRemover +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.mockk +import io.mockk.verify +import java.util.* + +class JobDescriptionDeleteServiceTest: BehaviorSpec({ + val jobRemover = mockk<JobDescriptionRemover>(relaxed = true) + val jobDescriptionDeleteService = JobDescriptionDeleteService(jobRemover) + + given("JobDescriptionDeleteService.deleteJobDescription") { + val jobDescriptionId = UUID.randomUUID() + `when`("jobDescriptionId가 주어지면") { + jobDescriptionDeleteService.deleteJobDescription(jobDescriptionId) + then("removeJobDescription가 호출된다.") { + verify { jobRemover.removeJobDescription(jobDescriptionId) } + } + } + } + +}) 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 94b3f515..6257df91 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 @@ -49,6 +49,9 @@ class JobDescriptionControllerTest : BaseRestDocsTest() { @MockBean private lateinit var jobDescriptionInfoUpdateService: JobDescriptionInfoUpdateService + @MockBean + private lateinit var jobDescriptionDeleteService: JobDescriptionDeleteService + @Test @DisplayName("직무 공고를 등록한다.") fun createJobDescription() { @@ -515,4 +518,31 @@ class JobDescriptionControllerTest : BaseRestDocsTest() { ) } + @Test + @DisplayName("JD를 삭제한다") + fun deleteJobDescription() { + // given + val jobDescriptionId = UUID.randomUUID() + + val request = RestDocumentationRequestBuilders.delete(JobDescriptionApi.DETAIL, jobDescriptionId) + .header("Authorization", "Bearer Access Token") + .contentType(MediaType.APPLICATION_JSON_VALUE) + + //when + val result = mockMvc.perform(request) + + //then + result.andExpect(status().isOk) + .andDo( + resultHandler.document( + requestHeaders( + headerWithName("Authorization").description("엑세스 토큰") + ), + pathParameters( + RequestDocumentation.parameterWithName("jobDescriptionId").description("jd 공고 ID") + ) + ) + ) + } + } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt index 1618231a..f4a47762 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/repository/JobDescriptionRepository.kt @@ -17,4 +17,6 @@ interface JobDescriptionRepository { fun findAllByUserId(userId: UUID, page: Int, size: Int, writeStatus: WriteStatus?): PageDomain<JobDescription> + fun deleteById(jobDescriptionId: UUID) + } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionRemover.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionRemover.kt new file mode 100644 index 00000000..56988c56 --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionRemover.kt @@ -0,0 +1,16 @@ +package com.bamyanggang.domainmodule.domain.jobDescription.service + +import com.bamyanggang.domainmodule.domain.jobDescription.repository.JobDescriptionRepository +import org.springframework.stereotype.Service +import java.util.* + +@Service +class JobDescriptionRemover( + private val jobDescriptionRepository: JobDescriptionRepository +) { + + fun removeJobDescription(jobDescriptionId: UUID) { + jobDescriptionRepository.deleteById(jobDescriptionId) + } + +} diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionRemoverTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionRemoverTest.kt new file mode 100644 index 00000000..b047d30f --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/jobDescription/service/JobDescriptionRemoverTest.kt @@ -0,0 +1,25 @@ +package com.bamyanggang.domainmodule.domain.jobDescription.service + +import com.bamyanggang.domainmodule.domain.jobDescription.repository.JobDescriptionRepository +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.mockk +import io.mockk.verify +import java.util.* + +class JobDescriptionRemoverTest: BehaviorSpec({ + val jobDescriptionRepository = mockk<JobDescriptionRepository>(relaxed = true) + val service = JobDescriptionRemover(jobDescriptionRepository) + + given("JobDescriptionRemover.removeJobDescription") { + val jobDescriptionId: UUID = UUID.randomUUID() + `when`("jobDescriptionId가 주어지면") { + service.removeJobDescription(jobDescriptionId) + then("removeJobDescription가 호출된다.") { + verify { + jobDescriptionRepository.deleteById(jobDescriptionId) + } + } + } + } + +}) diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java index a1355c6d..2f9feb2b 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/JobDescriptionRepositoryImpl.java @@ -63,4 +63,9 @@ public PageDomain<JobDescription> findAllByUserIdAndSortByEndedAt(UUID userId, i ,jobDescriptionSlice.getTotalPages(), jobDescriptionSlice.hasNext()); } + @Override + public void deleteById(UUID jobDescriptionId) { + jobDescriptionJpaRepository.deleteById(jobDescriptionId); + } + }