Skip to content

Commit

Permalink
Merge pull request #99 from KUSITMS-29th-TEAM-B/feat/flight-64
Browse files Browse the repository at this point in the history
feat : JD 작성 상태 변경 API 구현
  • Loading branch information
isprogrammingfun authored May 19, 2024
2 parents 9273030 + 2fba293 commit 7c34fd8
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 27 deletions.
6 changes: 6 additions & 0 deletions Api-Module/src/docs/asciidoc/JobDescription.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ operation::JobDescriptionControllerTest/getApplyInfo[snippets='http-request,requ

operation::JobDescriptionControllerTest/updateApplyInfo[snippets='http-request,path-parameters,request-headers,request-fields,http-response']

[[UPDATE-WRITE-STATUS]]
=== JD 작성 상태 수정

operation::JobDescriptionControllerTest/updateWriteStatus[snippets='http-request,path-parameters,request-headers,http-response']





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApplyCreateService(
}

val jobDescription = jobDescriptionReader.readJobDescriptionById(jobDescriptionId)
jobDescriptionModifier.modifyWriteStatus(jobDescription, WriteStatus.WRITING)
jobDescriptionModifier.modifyWriteStatus(jobDescription)
applyAppender.appendApply(contents = applyContents, 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.JobDescriptionModifier
import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader
import org.springframework.stereotype.Service
import java.util.*

@Service
class JobDescriptionUpdateService(
private val jobDescriptionModifier: JobDescriptionModifier,
private val jobDescriptionReader: JobDescriptionReader
) {
fun updateWriteStatus(jobDescriptionId: UUID) {
val jobDescription = jobDescriptionReader.readJobDescriptionById(jobDescriptionId)
jobDescriptionModifier.modifyWriteStatus(jobDescription)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ object JobDescriptionApi {
const val BASE_URL = "/api/job-description"
const val APPLY = "${BASE_URL}/apply/{jobDescriptionId}"
const val DETAIL = "${BASE_URL}/{jobDescriptionId}"
const val STATUS = "${BASE_URL}/status/{jobDescriptionId}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
Expand All @@ -21,7 +22,8 @@ class JobDescriptionController(
private val applyCreateService: ApplyCreateService,
private val jobDescriptionInfoGetService: JobDescriptionInfoGetService,
private val applyInfoGetService: ApplyInfoGetService,
private val applyUpdateService: ApplyUpdateService
private val applyUpdateService: ApplyUpdateService,
private val jobDescriptionUpdateService: JobDescriptionUpdateService
) {

@PostMapping(JobDescriptionApi.BASE_URL)
Expand Down Expand Up @@ -60,4 +62,9 @@ class JobDescriptionController(
@RequestBody request: ApplyInfo.Request
) = applyUpdateService.updateApplyInfo(jobDescriptionId, request)

@PatchMapping(JobDescriptionApi.STATUS)
fun updateJobDescription(
@PathVariable("jobDescriptionId") jobDescriptionId: UUID
) = jobDescriptionUpdateService.updateWriteStatus(jobDescriptionId)

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ApplyCreateServiceTest : BehaviorSpec({

then("modifyWriteStatus와 appendApply가 호출된다.") {
verify {
jobDescriptionModifier.modifyWriteStatus(any(), any())
jobDescriptionModifier.modifyWriteStatus(any())
applyAppender.appendApply(any(), any())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.bamyanggang.apimodule.domain.jobDescription.application

import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionUpdateService
import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionModifier
import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.util.UUID

class JobDescriptionUpdateServiceTest: BehaviorSpec({
val jobDescriptionModifier = mockk<JobDescriptionModifier>(relaxed = true)
val jobDescriptionReader = mockk<JobDescriptionReader>(relaxed = true)
val service = JobDescriptionUpdateService(jobDescriptionModifier, jobDescriptionReader)

given("JobDescriptionUpdateService.updateWriteStatus") {
val jobDescriptionId = UUID.randomUUID()
`when`("직무 공고 id가 주어지면") {
service.updateWriteStatus(jobDescriptionId)
then("modifyWriteStatus가 호출된다.") {
verify { jobDescriptionModifier.modifyWriteStatus(any()) }
}
}
}

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

@MockBean
private lateinit var jobDescriptionUpdateService: JobDescriptionUpdateService

@Test
@DisplayName("직무 공고를 등록한다.")
fun createJobDescription() {
Expand Down Expand Up @@ -441,4 +444,31 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
)
}

@Test
@DisplayName("JD 작성 상태를 수정한다")
fun updateWriteStatus() {
// given
val jobDescriptionId = UUID.randomUUID()

val request = RestDocumentationRequestBuilders.patch(JobDescriptionApi.STATUS, 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 @@ -2,6 +2,7 @@ package com.bamyanggang.domainmodule.domain.jobDescription.aggregate

import com.bamyanggang.domainmodule.common.entity.AggregateRoot
import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus
import com.bamyanggang.domainmodule.domain.jobDescription.exception.JobDescriptionException
import com.example.uuid.UuidCreator
import java.time.LocalDate
import java.time.LocalDateTime
Expand Down Expand Up @@ -34,8 +35,13 @@ data class JobDescription(
return LocalDate.now().until(endedAt.toLocalDate(), ChronoUnit.DAYS).toInt()
}

fun changeWriteStatus(writeStatus: WriteStatus): JobDescription {
return copy(writeStatus = writeStatus)
fun changeWriteStatus() : JobDescription {
return when(writeStatus) {
WriteStatus.NOT_APPLIED -> copy(writeStatus = WriteStatus.WRITING)
WriteStatus.WRITING -> copy(writeStatus = WriteStatus.WRITTEN)
WriteStatus.WRITTEN -> copy(writeStatus = WriteStatus.WRITING)
else -> throw JobDescriptionException.ModifyWriteStatusFailed()
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.bamyanggang.domainmodule.domain.jobDescription.exception

import com.bamyanggang.commonmodule.exception.CustomException
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatusCode

sealed class JobDescriptionException (
errorCode: Int,
httpStatusCode: HttpStatusCode,
message: String,
) : CustomException(CODE_PREFIX, errorCode, httpStatusCode , message) {

class ModifyWriteStatusFailed(message: String = "쓰기 상태 변경에 실패하였습니다.") :
JobDescriptionException(errorCode = 1, httpStatusCode = HttpStatus.BAD_REQUEST, message = message)

companion object {
const val CODE_PREFIX = "AUTH"
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bamyanggang.domainmodule.domain.jobDescription.service

import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.JobDescription
import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus
import com.bamyanggang.domainmodule.domain.jobDescription.repository.JobDescriptionRepository
import org.springframework.stereotype.Service

Expand All @@ -10,8 +9,8 @@ class JobDescriptionModifier(
private val jobDescriptionRepository: JobDescriptionRepository
) {

fun modifyWriteStatus(jobDescription: JobDescription, writeStatus: WriteStatus) {
jobDescription.changeWriteStatus(writeStatus).also { jobDescriptionRepository.save(it) }
fun modifyWriteStatus(jobDescription: JobDescription) {
jobDescription.changeWriteStatus().also { jobDescriptionRepository.save(it) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ class JobDescriptionTest : FunSpec({
// arrange
val startedAt: LocalDateTime = LocalDateTime.now()
val endedAt: LocalDateTime = startedAt.plusDays(1)
val jobDescription = JobDescription.create(
enterpriseName = generateBasicTypeFixture(10),
title = generateBasicTypeFixture(10),
content = generateBasicTypeFixture(10),
link = generateBasicTypeFixture(10),
startedAt = startedAt,
endedAt = endedAt,
userId = UUID.randomUUID()
)
val jobDescription: JobDescription = generateFixture {
it.set("enterpriseName", "기업 이름")
it.set("title", "직무 공고 제목")
it.set("writeStatus", WriteStatus.NOT_APPLIED)
it.set("content", "직무 공고 내용")
it.set("link", "직무 공고 링크")
it.set("createdAt", LocalDateTime.now())
it.set("updatedAt", LocalDateTime.now())
it.set("startedAt", LocalDateTime.now())
it.set("endedAt", LocalDateTime.now().plusDays(1))
it.set("userId", UUID.randomUUID())
}

// act
val remainingDate = jobDescription.getRemainingDate()
Expand All @@ -113,18 +116,21 @@ class JobDescriptionTest : FunSpec({

test("상태 변경") {
// arrange
val jobDescription = JobDescription.create(
enterpriseName = generateBasicTypeFixture(10),
title = generateBasicTypeFixture(10),
content = generateBasicTypeFixture(10),
link = generateBasicTypeFixture(10),
startedAt = LocalDateTime.now(),
endedAt = LocalDateTime.now().plusDays(1),
userId = UUID.randomUUID()
)
val jobDescription: JobDescription = generateFixture {
it.set("enterpriseName", "기업 이름")
it.set("title", "직무 공고 제목")
it.set("writeStatus", WriteStatus.NOT_APPLIED)
it.set("content", "직무 공고 내용")
it.set("link", "직무 공고 링크")
it.set("createdAt", LocalDateTime.now())
it.set("updatedAt", LocalDateTime.now())
it.set("startedAt", LocalDateTime.now())
it.set("endedAt", LocalDateTime.now().plusDays(1))
it.set("userId", UUID.randomUUID())
}

// act
val changedJobDescription = jobDescription.changeWriteStatus(WriteStatus.WRITING)
val changedJobDescription = jobDescription.changeWriteStatus()

// assert
changedJobDescription.writeStatus shouldBe WriteStatus.WRITING
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.bamyanggang.domainmodule.domain.jobDescription.service

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.repository.JobDescriptionRepository
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.time.LocalDateTime
import java.util.*

class JobDescriptionModifierTest: BehaviorSpec({
val jobDescriptionRepository = mockk<JobDescriptionRepository>(relaxed = true)
val service = JobDescriptionModifier(jobDescriptionRepository)

given("JobDescriptionModifier.modifyWriteStatus") {
val jobDescription: JobDescription = generateFixture {
it.set("enterpriseName", "기업 이름")
it.set("title", "직무 공고 제목")
it.set("writeStatus", WriteStatus.NOT_APPLIED)
it.set("content", "직무 공고 내용")
it.set("link", "직무 공고 링크")
it.set("createdAt", LocalDateTime.now())
it.set("updatedAt", LocalDateTime.now())
it.set("startedAt", LocalDateTime.now())
it.set("endedAt", LocalDateTime.now().plusDays(1))
it.set("userId", UUID.randomUUID())
}
`when`("jobDescription가 주어지면") {
service.modifyWriteStatus(jobDescription)
then("changeWriteStatus가 호출된다.") {
verify { jobDescriptionRepository.save(any()) }
}
}
}

})

0 comments on commit 7c34fd8

Please sign in to comment.