Skip to content

Commit

Permalink
Merge pull request #106 from KUSITMS-29th-TEAM-B/feat/flight-100
Browse files Browse the repository at this point in the history
feat : JD 삭제 API 구현
  • Loading branch information
isprogrammingfun authored May 20, 2024
2 parents 479b239 + d77c37f commit a7d1068
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Api-Module/src/docs/asciidoc/JobDescription.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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']




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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
class ApplyInfoGetService(
private val applyReader: ApplyReader
) {

@Transactional(readOnly = true)
fun getApplyInfo(jobDescriptionId: UUID): ApplyInfo.Response {
return applyReader.readApplyByJobDescriptionId(jobDescriptionId).contents.map {
ApplyInfo.ContentInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

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

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

})
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
@MockBean
private lateinit var jobDescriptionInfoUpdateService: JobDescriptionInfoUpdateService

@MockBean
private lateinit var jobDescriptionDeleteService: JobDescriptionDeleteService

@Test
@DisplayName("직무 공고를 등록한다.")
fun createJobDescription() {
Expand Down Expand Up @@ -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")
)
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ interface JobDescriptionRepository {

fun findAllByUserId(userId: UUID, page: Int, size: Int, writeStatus: WriteStatus?): PageDomain<JobDescription>

fun deleteById(jobDescriptionId: UUID)

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

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

})
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public PageDomain<JobDescription> findAllByUserIdAndSortByEndedAt(UUID userId, i
,jobDescriptionSlice.getTotalPages(), jobDescriptionSlice.hasNext());
}

@Override
public void deleteById(UUID jobDescriptionId) {
jobDescriptionJpaRepository.deleteById(jobDescriptionId);
}

}

0 comments on commit a7d1068

Please sign in to comment.