Skip to content

Commit

Permalink
Merge pull request #68 from KUSITMS-29th-TEAM-B/feat/flight-39
Browse files Browse the repository at this point in the history
feat: 경험 등록 API 구현(#39)
  • Loading branch information
whereami2048 authored May 18, 2024
2 parents 91ecac8 + 9706597 commit e142b15
Show file tree
Hide file tree
Showing 47 changed files with 585 additions and 96 deletions.
Binary file added Api-Module/.jqwik-database
Binary file not shown.
17 changes: 17 additions & 0 deletions Api-Module/src/docs/asciidoc/Experience.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[Experience-API]]
== Experience-API

[[CreateExperienceTest]]
=== 경험 등록 API

operation::ExperienceControllerTest/createExperienceTest/[snippets='http-request,request-headers,request-body,request-fields,http-response,response-body,response-fields']

[[CreateOverTitleLengthTest]]
=== 제목 글자 수 제한(50자) 예외

operation::ExperienceControllerTest/createOverTitleLengthTest/[snippets='http-request,request-headers,request-body,request-fields,http-response,response-body,response-fields']

[[CreateOverStrongPointCountTest]]
=== 역량 키워드 제한(5개) 초과 예외

operation::ExperienceControllerTest/createOverStrongPointCountTest/[snippets='http-request,request-headers,request-body,http-response,response-body,response-fields']
3 changes: 1 addition & 2 deletions Api-Module/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ include::User.adoc[]
include::StrongPoint.adoc[]
include::Tag.adoc[]
include::JobDescription.adoc[]


include::Experience.adoc[]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bamyanggang.apimodule.domain.experience.application.dto

import java.time.LocalDateTime
import java.util.*

class CreateExperience {
data class Request(
val title: String,
val parentTagId: UUID,
val childTagId: UUID,
val strongPointIds: List<UUID>,
val contents: List<ExperienceContentRequest>,
val startedAt: LocalDateTime,
val endedAt: LocalDateTime,
)

data class Response(val id: UUID)

data class ExperienceContentRequest(
val question: String,
val answer: String,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.bamyanggang.apimodule.domain.experience.application.service

import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.experience.application.dto.CreateExperience
import com.bamyanggang.domainmodule.domain.experience.service.ExperienceAppender
import com.bamyanggang.domainmodule.domain.experience.service.ExperienceContentAppender
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class ExperienceCreateService(
val experienceAppender: ExperienceAppender,
val experienceContentAppender: ExperienceContentAppender
) {
@Transactional
fun createExperience(request: CreateExperience.Request):CreateExperience.Response {
val currentUserId = getAuthenticationPrincipal()

return request.contents.map {
experienceContentAppender.appendExperienceContent(it.question, it.answer).id
}.let {
experienceAppender.appendExperience(
title = request.title,
userId = currentUserId,
parentTagId = request.parentTagId,
childTagId = request.childTagId,
strongPointIds = request.strongPointIds,
contentIds = it,
startedAt = request.startedAt,
endedAt = request.endedAt
)
}.let {
CreateExperience.Response(it.id)
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.bamyanggang.apimodule.domain.experience.presentation

object ExperienceApi {
const val BASE_URL = "/api/experiences"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bamyanggang.apimodule.domain.experience.presentation

import com.bamyanggang.apimodule.domain.experience.application.dto.CreateExperience
import com.bamyanggang.apimodule.domain.experience.application.service.ExperienceCreateService
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

@RestController
class ExperienceController(
private val experienceCreateService: ExperienceCreateService
) {
@PostMapping(ExperienceApi.BASE_URL)
fun createExperience(@RequestBody request: CreateExperience.Request): CreateExperience.Response {
return experienceCreateService.createExperience(request)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ class JobDescriptionCreateService(
)
}.also { return CreateJobDescription.Response(jobDescriptionId = it.id) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import com.bamyanggang.domainmodule.domain.strongpoint.exception.StrongPointExce
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointAppender
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointReader
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class StrongPointCreateService(
val strongPointAppender: StrongPointAppender,
val strongPointReader: StrongPointReader,
) {
@Transactional
fun createStrongPoint(request: CreateStrongPoint.Request): CreateStrongPoint.Response {
return getAuthenticationPrincipal()
.also {
val userStrongPoints = strongPointReader.readAllByUserId(it)
validateDuplicatedStrongPointName(userStrongPoints, request.name)
}.let {
val newStrongPointId = strongPointAppender.appendStrongPoint(request.name, it)
CreateStrongPoint.Response(newStrongPointId)
val newStrongPoint = strongPointAppender.appendStrongPoint(request.name, it)
CreateStrongPoint.Response(newStrongPoint.id)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class StrongPointController(
private val strongPointCreateService: StrongPointCreateService,
) {
@PostMapping(StrongPointApi.BASE_URL)
fun createStrongPoint(@RequestBody request: CreateStrongPoint.Request): CreateStrongPoint.Response {
fun createStrongPoint(@RequestBody request: CreateStrongPoint.Request): CreateStrongPoint.Response{
return strongPointCreateService.createStrongPoint(request)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,37 @@ import com.bamyanggang.domainmodule.domain.tag.exception.TagException
import com.bamyanggang.domainmodule.domain.tag.service.TagAppender
import com.bamyanggang.domainmodule.domain.tag.service.TagReader
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
class TagCreateService(
private val tagAppender: TagAppender,
private val tagReader: TagReader,
) {
@Transactional
fun createChildTag(request: CreateTag.Request, parentTagId: UUID): CreateTag.Response {
return getAuthenticationPrincipal()
.also {
val userChildTags = tagReader.readAllChildTagsByUserId(it, parentTagId)
validateTagCountLimit(userChildTags.size)
validateDuplicatedName(userChildTags, request.name)
}.let {
val newChildTagId = tagAppender.appendChildTag(request.name, parentTagId, it)
CreateTag.Response(newChildTagId)
}
val newTag = tagAppender.appendChildTag(request.name, parentTagId, it)
CreateTag.Response(newTag.id)
}
}

fun createParentTag(request: CreateTag.Request): CreateTag.Response {
@Transactional
fun createParentTag(request: CreateTag.Request) : CreateTag.Response {
return getAuthenticationPrincipal()
.also {
val userParentTags = tagReader.readAllParentTagsByUserId(it)
validateTagCountLimit(userParentTags.size)
validateDuplicatedName(userParentTags, request.name)
}.let {
val newParentTagId = tagAppender.appendParentTag(request.name, it)
CreateTag.Response(newParentTagId)
val newTag = tagAppender.appendParentTag(request.name, it)
CreateTag.Response(newTag.id)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.bamyanggang.apimodule.domain.tag.application.service

import com.bamyanggang.domainmodule.domain.tag.service.TagRemover
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
class TagDeleteService(
private val tagRemover: TagRemover
) {
@Transactional
fun deleteTag(tagId: UUID) {
tagRemover.removeTag(tagId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ class TagController(
private val tagCreateService: TagCreateService,
private val tagDeleteService: TagDeleteService
) {
@PostMapping(TagApi.BASE_URL, TagApi.TAG_PATH_VARIABLE_URL)
fun createTag(
@PathVariable("tagId", required = false) parentTagId: UUID?,
@PostMapping(TagApi.BASE_URL)
fun createParentTag(@RequestBody request: CreateTag.Request): CreateTag.Response {
return tagCreateService.createParentTag(request)
}

@PostMapping(TagApi.TAG_PATH_VARIABLE_URL)
fun createChildTag(
@RequestBody request: CreateTag.Request,
@PathVariable("tagId") parentTagId : UUID
): CreateTag.Response {
return when {
parentTagId == null -> tagCreateService.createParentTag(request)
else -> tagCreateService.createChildTag(request, parentTagId)
}
return tagCreateService.createChildTag(request, parentTagId)
}

@DeleteMapping(TagApi.TAG_PATH_VARIABLE_URL)
Expand Down
Loading

0 comments on commit e142b15

Please sign in to comment.