Skip to content

Commit

Permalink
Merge pull request #58 from KUSITMS-29th-TEAM-B/feat/flight-52
Browse files Browse the repository at this point in the history
feat: 상위 & 하위 태그 등록 API 구현(#52)(#44)
  • Loading branch information
whereami2048 authored May 17, 2024
2 parents 4e52071 + f20d25b commit d70d571
Show file tree
Hide file tree
Showing 29 changed files with 630 additions and 43 deletions.
27 changes: 27 additions & 0 deletions Api-Module/src/docs/asciidoc/Tag.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[Tag-API]]
== Tag-API

[[CreateParentTagTest]]
=== 상위 태그 등록 API

operation::TagControllerTest/createParentTagTest/[snippets='http-request,request-fields,http-response,response-fields']

[[CreateChildTagTest]]
=== 하위 태그 등록 API

operation::TagControllerTest/createChildTagTest/[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

[[duplicatedParentTagTest]]
=== 상위 태그 이름 중복 예외

operation::TagControllerTest/duplicatedParentTagTest/[snippets='http-request,request-fields,http-response,response-fields']

[[duplicatedChildTagTest]]
=== 하위 태그 이름 중복 예외

operation::TagControllerTest/duplicatedChildTagTest/[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

[[overTagCountLimitTest]]
=== 태그 개수 제한 이상 등록 요청 예외

operation::TagControllerTest/overTagCountLimitTest/[snippets='http-request,path-parameters,request-fields,http-response,response-fields']
1 change: 1 addition & 0 deletions Api-Module/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
include::Auth.adoc[]
include::User.adoc[]
include::StrongPoint.adoc[]
include::Tag.adoc[]


Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bamyanggang.apimodule.domain.strongpoint.application.service

import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.strongpoint.application.dto.CreateStrongPoint
import com.bamyanggang.domainmodule.domain.strongpoint.aggregate.StrongPoint
import com.bamyanggang.domainmodule.domain.strongpoint.exception.StrongPointException
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointAppender
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointReader
Expand All @@ -15,13 +16,19 @@ class StrongPointCreateService(
fun createStrongPoint(request: CreateStrongPoint.Request): CreateStrongPoint.Response {
return getAuthenticationPrincipal()
.also {
strongPointReader.findAllByUserId(it).forEach { strongPoint ->
if(strongPoint.isDuplicated(request.name))
throw StrongPointException.DuplicatedStrongPointName()
}
val userStrongPoints = strongPointReader.readAllByUserId(it)
validateDuplicatedStrongPointName(userStrongPoints, request.name)
}.let {
val newStrongPointId = strongPointAppender.appendStrongPoint(request.name, it)
CreateStrongPoint.Response(newStrongPointId)
}
}
}

private fun validateDuplicatedStrongPointName(userStrongPoints: List<StrongPoint>, name: String) {
userStrongPoints.forEach { strongPoint ->
if (strongPoint.isDuplicated(name)) {
throw StrongPointException.DuplicatedStrongPointName()
}
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bamyanggang.apimodule.domain.tag.application.dto

import java.util.UUID

class CreateTag {
data class Request(val name: String)
data class Response(val id: UUID)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.bamyanggang.apimodule.domain.tag.application.service

import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.tag.application.dto.CreateTag
import com.bamyanggang.domainmodule.domain.tag.aggregate.Tag
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 java.util.*

@Service
class TagCreateService(
private val tagAppender: TagAppender,
private val tagReader: TagReader,
) {
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)
}
}

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)
}
}

private fun validateDuplicatedName(userParentTags: List<Tag>, name: String) {
userParentTags.forEach {
if (it.isDuplicatedName(name)) {
throw TagException.DuplicatedTagName()
}
}
}

private fun validateTagCountLimit(size: Int) {
val limit = 10
if (size > limit) {
throw TagException.OverTagCountLimit()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bamyanggang.apimodule.domain.tag.application.service

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

@Service
class TagDeleteService(
private val tagRemover: TagRemover
) {
fun deleteTag(tagId: UUID) {
tagRemover.removeTag(tagId)
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bamyanggang.apimodule.domain.tag.presentation

object TagApi {
const val BASE_URL = "/api/tags"
const val TAG_PATH_VARIABLE_URL = "$BASE_URL/{tagId}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.bamyanggang.apimodule.domain.tag.presentation

import com.bamyanggang.apimodule.domain.tag.application.dto.CreateTag
import com.bamyanggang.apimodule.domain.tag.application.service.TagCreateService
import com.bamyanggang.apimodule.domain.tag.application.service.TagDeleteService
import org.springframework.web.bind.annotation.*
import java.util.*

@RestController
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?,
@RequestBody request: CreateTag.Request,
): CreateTag.Response {
return when {
parentTagId == null -> tagCreateService.createParentTag(request)
else -> tagCreateService.createChildTag(request, parentTagId)
}
}

@DeleteMapping(TagApi.TAG_PATH_VARIABLE_URL)
fun deleteTag( @PathVariable("tagId", required = false) tagId: UUID) {
tagDeleteService.deleteTag(tagId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bamyanggang.apimodule.domain.strongpoint.presentation
import com.bamyanggang.apimodule.BaseRestDocsTest
import com.bamyanggang.apimodule.domain.strongpoint.application.dto.CreateStrongPoint
import com.bamyanggang.commonmodule.fixture.generateFixture
import com.bamyanggang.domainmodule.domain.strongpoint.exception.StrongPointException
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
Expand Down Expand Up @@ -46,16 +45,4 @@ class StrongPointControllerTest : BaseRestDocsTest() {
)
)
}

@Test
@DisplayName("중복된 역량 키워드 등록 시 등록하지 않고 예외를 반환한다.")
fun duplicatedStrongPointNameTest() {

val duplicatedRequest = CreateStrongPoint.Request("duplicatedName")

strongPointController.createStrongPoint(duplicatedRequest)
strongPointController.createStrongPoint(duplicatedRequest)

given(strongPointController.createStrongPoint(duplicatedRequest)).willThrow(StrongPointException.DuplicatedStrongPointName())
}
}
Loading

0 comments on commit d70d571

Please sign in to comment.