Skip to content

Commit

Permalink
Merge pull request #98 from KUSITMS-29th-TEAM-B/feat/flight-84
Browse files Browse the repository at this point in the history
feat: 자기소개서 수정 API 구현
  • Loading branch information
isprogrammingfun authored May 19, 2024
2 parents 4f863c3 + 5932916 commit 9273030
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 36 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 @@ -41,6 +41,12 @@ operation::JobDescriptionControllerTest/getJobDescriptionDetail[snippets='http-r

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

[[UPDATE-APPLY]]
=== 자기소개서 수정

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





Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.bamyanggang.apimodule.domain.jobDescription.application.dto

class GetApplyInfo {
class ApplyInfo {

data class Request(
val contents: List<ContentInfo>
)

data class Response(
val applyContentList: List<ContentInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ class CreateApply {
val contents : List<CreateApplyContent>
)

data class CreateApplyContent (
val question: String,
val answer: String
)

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bamyanggang.apimodule.domain.jobDescription.application.service

import com.bamyanggang.apimodule.domain.jobDescription.application.dto.GetApplyInfo
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.ApplyInfo
import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader
import org.springframework.stereotype.Service
import java.util.*
Expand All @@ -10,14 +10,14 @@ class ApplyInfoGetService(
private val applyReader: ApplyReader
) {

fun getApplyInfo(jobDescriptionId: UUID): GetApplyInfo.Response {
fun getApplyInfo(jobDescriptionId: UUID): ApplyInfo.Response {
return applyReader.readApplyByJobDescriptionId(jobDescriptionId).contents.map {
GetApplyInfo.ContentInfo(
ApplyInfo.ContentInfo(
it.question,
it.answer
)
}.let {
GetApplyInfo.Response(it)
ApplyInfo.Response(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.bamyanggang.apimodule.domain.jobDescription.application.service

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 java.util.*

@Service
class ApplyUpdateService(
private val applyModifier: ApplyModifier
) {

fun updateApplyInfo(jobDescriptionId: UUID, request: ApplyInfo.Request) {
applyModifier.modifyApplyInfo(
jobDescriptionId = jobDescriptionId,
applyContentList = request.contents.map {
ApplyContent.create(
question = it.question,
answer = it.answer
)
}
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ object JobDescriptionApi {
const val BASE_URL = "/api/job-description"
const val APPLY = "${BASE_URL}/apply/{jobDescriptionId}"
const val DETAIL = "${BASE_URL}/{jobDescriptionId}"

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package com.bamyanggang.apimodule.domain.jobDescription.presentation

import com.bamyanggang.apimodule.common.dto.PageResponse
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.CreateApply
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.CreateJobDescription
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.GetApplyInfo
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.GetJobDescriptionInfo
import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyCreateService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyInfoGetService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionCreateService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionInfoGetService
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.*
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.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
Expand All @@ -25,7 +20,8 @@ class JobDescriptionController(
private val jobDescriptionCreateService: JobDescriptionCreateService,
private val applyCreateService: ApplyCreateService,
private val jobDescriptionInfoGetService: JobDescriptionInfoGetService,
private val applyInfoGetService: ApplyInfoGetService
private val applyInfoGetService: ApplyInfoGetService,
private val applyUpdateService: ApplyUpdateService
) {

@PostMapping(JobDescriptionApi.BASE_URL)
Expand Down Expand Up @@ -56,6 +52,12 @@ class JobDescriptionController(
@GetMapping(JobDescriptionApi.APPLY)
fun getApplyInfo(
@PathVariable("jobDescriptionId") jobDescriptionId: UUID
): GetApplyInfo.Response = applyInfoGetService.getApplyInfo(jobDescriptionId)
): ApplyInfo.Response = applyInfoGetService.getApplyInfo(jobDescriptionId)

@PutMapping(JobDescriptionApi.APPLY)
fun updateApplyInfo(
@PathVariable("jobDescriptionId") jobDescriptionId: UUID,
@RequestBody request: ApplyInfo.Request
) = applyUpdateService.updateApplyInfo(jobDescriptionId, request)

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

import com.bamyanggang.apimodule.domain.jobDescription.application.dto.CreateApply
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.CreateApplyContent
import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyCreateService
import com.bamyanggang.commonmodule.fixture.generateFixture
import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.JobDescription
Expand All @@ -26,7 +25,7 @@ class ApplyCreateServiceTest : BehaviorSpec({
given("ApplyCreateService.createApply") {
val request: CreateApply.Request = generateFixture {
it.set("contents", listOf(
CreateApplyContent(
CreateApply.CreateApplyContent(
question = "질문1",
answer = "답변1"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.bamyanggang.apimodule.domain.jobDescription.application

import com.bamyanggang.apimodule.domain.jobDescription.application.dto.ApplyInfo
import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyUpdateService
import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyModifier
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.util.UUID

class ApplyUpdateServiceTest: BehaviorSpec({
val applyModifier = mockk<ApplyModifier>(relaxed = true)
val service = ApplyUpdateService(applyModifier)

given("ApplyUpdateService") {
val jobDescriptionId = UUID.randomUUID()
val request = ApplyInfo.Request(
contents = listOf(
ApplyInfo.ContentInfo(
question = "질문1",
answer = "답변1"
)
)
)
`when`("updateApplyInfo") {
service.updateApplyInfo(jobDescriptionId, request)
then("should update apply info") {
verify { applyModifier.modifyApplyInfo(any(), any()) }
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package com.bamyanggang.apimodule.domain.jobDescription.presentation
import com.bamyanggang.apimodule.BaseRestDocsTest
import com.bamyanggang.apimodule.common.dto.PageResponse
import com.bamyanggang.apimodule.domain.jobDescription.application.dto.*
import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyCreateService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyInfoGetService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionCreateService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.JobDescriptionInfoGetService
import com.bamyanggang.apimodule.domain.jobDescription.application.service.*
import com.bamyanggang.commonmodule.exception.ExceptionHandler
import com.bamyanggang.commonmodule.fixture.generateFixture
import com.bamyanggang.domainmodule.common.pagination.PageDomain
Expand Down Expand Up @@ -46,6 +43,9 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
@MockBean
private lateinit var applyInfoGetService: ApplyInfoGetService

@MockBean
private lateinit var applyUpdateService: ApplyUpdateService

@Test
@DisplayName("직무 공고를 등록한다.")
fun createJobDescription() {
Expand Down Expand Up @@ -179,7 +179,7 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
fun createApply() {
//given
val jobDescriptionId = UUID.randomUUID()
val createApplyContentRequest: CreateApplyContent = generateFixture {
val createApplyContentRequest: CreateApply.CreateApplyContent = generateFixture {
it.set("question", "질문")
it.set("answer", "답변")
}
Expand Down Expand Up @@ -216,7 +216,7 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
fun createApplyWithEmptyContent() {
//given
val jobDescriptionId = UUID.randomUUID()
val createApplyContentRequest: CreateApplyContent = generateFixture {
val createApplyContentRequest: CreateApply.CreateApplyContent = generateFixture {
it.set("question", "질문")
it.set("answer", "")
}
Expand Down Expand Up @@ -370,15 +370,15 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
fun getApplyInfo() {
// given
val jobDescriptionId = UUID.randomUUID()
val contentInfo: GetApplyInfo.ContentInfo = generateFixture {
val contentInfo: ApplyInfo.ContentInfo = generateFixture {
it.set("question", "질문")
it.set("answer", "답변")
}
val getApplyInfoResponse: GetApplyInfo.Response = generateFixture {
val applyInfoResponse: ApplyInfo.Response = generateFixture {
it.set("applyContentList", listOf(contentInfo))
}

given(applyInfoGetService.getApplyInfo(jobDescriptionId)).willReturn(getApplyInfoResponse)
given(applyInfoGetService.getApplyInfo(jobDescriptionId)).willReturn(applyInfoResponse)

val request = RestDocumentationRequestBuilders.get(JobDescriptionApi.APPLY, jobDescriptionId)
.header("Authorization", "Bearer Access Token")
Expand All @@ -405,4 +405,40 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
)
}

@Test
@DisplayName("JD 공고 자기소개서 정보를 수정한다")
fun updateApplyInfo() {
// given
val jobDescriptionId = UUID.randomUUID()
val updateApplyRequest: ApplyInfo.Request = generateFixture {
it.set("contents", listOf(ApplyInfo.ContentInfo("질문", "답변")))
}

val request = RestDocumentationRequestBuilders.put(JobDescriptionApi.APPLY, jobDescriptionId)
.header("Authorization", "Bearer Access Token")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(updateApplyRequest))

//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")
),
requestFields(
fieldWithPath("contents").description("내용"),
fieldWithPath("contents[].question").description("질문"),
fieldWithPath("contents[].answer").description("답변")
)
)
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ data class Apply(
val jobDescriptionId: UUID,
): DomainEntity {

fun update(
contents: List<ApplyContent>,
): Apply {
return copy(
contents = contents,
jobDescriptionId = jobDescriptionId,
updatedAt = LocalDateTime.now()
)
}

companion object {
fun create(
contents: List<ApplyContent>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.bamyanggang.domainmodule.domain.jobDescription.service

import com.bamyanggang.domainmodule.domain.jobDescription.aggregate.ApplyContent
import com.bamyanggang.domainmodule.domain.jobDescription.repository.ApplyRepository
import org.springframework.stereotype.Service
import java.util.*

@Service
class ApplyModifier(
private val applyRepository: ApplyRepository
) {

fun modifyApplyInfo(
jobDescriptionId: UUID,
applyContentList: List<ApplyContent>
) {
applyRepository
.findByJobDescriptionId(jobDescriptionId)
.update(
contents = applyContentList
)
.also { applyRepository.save(it) }
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ import io.kotest.matchers.shouldBe
import java.util.*

class ApplyTest : FunSpec({
test("Apply.create 생성") {

test("Apply 생성") {
val applyContent: ApplyContent = generateFixture{
it.set("question", "질문")
it.set("answer", "답변")
}
val contents = listOf(applyContent)
val jobDescriptionId: UUID = UUID.randomUUID()

val apply = Apply.create(contents,jobDescriptionId)

apply.contents shouldBe contents
apply.jobDescriptionId shouldBe jobDescriptionId
}

test("Apply.update 업데이트") {
val contents = listOf(
ApplyContent.create(
question = generateFixture { it.set("question", "질문") },
Expand All @@ -21,7 +36,16 @@ class ApplyTest : FunSpec({

val apply = Apply.create(contents,jobDescriptionId)

apply.jobDescriptionId shouldBe jobDescriptionId
val newContents = listOf(
ApplyContent.create(
question = generateFixture { it.set("question", "질문2") },
answer = generateFixture { it.set("answer", "답변2") }
)
)

val updatedApply = apply.update(newContents)

updatedApply.contents shouldBe newContents
}

})
Loading

0 comments on commit 9273030

Please sign in to comment.