-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from KUSITMS-29th-TEAM-B/feat/flight-52
- Loading branch information
Showing
29 changed files
with
630 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
include::Auth.adoc[] | ||
include::User.adoc[] | ||
include::StrongPoint.adoc[] | ||
include::Tag.adoc[] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file removed
0
Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/application/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions
8
Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/application/dto/CreateTag.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
55 changes: 55 additions & 0 deletions
55
.../main/kotlin/com/bamyanggang/apimodule/domain/tag/application/service/TagCreateService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../main/kotlin/com/bamyanggang/apimodule/domain/tag/application/service/TagDeleteService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
6 changes: 6 additions & 0 deletions
6
Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
29 changes: 29 additions & 0 deletions
29
...Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.