Skip to content

Commit

Permalink
Merge pull request #105 from KUSITMS-29th-TEAM-B/feat/flight-53
Browse files Browse the repository at this point in the history
상위 태그 내 하위 태그 조회 API 구현(#53)
  • Loading branch information
whereami2048 authored May 20, 2024
2 parents a7d1068 + 94205dc commit a85f71c
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 56 deletions.
8 changes: 6 additions & 2 deletions Api-Module/src/docs/asciidoc/Tag.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ operation::TagControllerTest/getTopRankParentTagTest/[snippets='http-request,req

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


[[GetChildTagTest]]
=== 하위 태그 조회 API
=== 하위 태그 전체 조회 API

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

[[GetChildTagsByFilter]]
=== 상위 태그 내 하위 태그 조회 API

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.bamyanggang.apimodule.domain.tag.application.dto

import com.bamyanggang.apimodule.domain.tag.application.dto.GetParentTag.TagDetail
import java.util.*

class GetChildTag {
data class Response(
val tags: List<TagDetail>
)

data class TotalTagInfo(
val totalExperienceCount: Int,
val tagInfos : List<ChildTagSummary>
)

data class ChildTagSummary(
val id: UUID,
val name: String,
val experienceCount: Int
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.bamyanggang.apimodule.domain.tag.application.dto

import java.util.*

class GetTag {
class GetParentTag {
data class Response(
val tags: List<TagDetail>
)
Expand All @@ -14,10 +14,10 @@ class GetTag {

data class TotalTagInfo(
val totalExperienceCount: Int,
val tagInfos : List<TagSummary>
val tagInfos : List<ParentTagSummary>
)

data class TagSummary(
data class ParentTagSummary(
val id: UUID,
val name: String,
val strongPointCount: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.bamyanggang.apimodule.domain.tag.application.service

import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.tag.application.dto.GetTag
import com.bamyanggang.apimodule.domain.tag.application.dto.GetChildTag
import com.bamyanggang.apimodule.domain.tag.application.dto.GetParentTag
import com.bamyanggang.domainmodule.domain.experience.service.ExperienceReader
import com.bamyanggang.domainmodule.domain.tag.service.TagReader
import org.springframework.stereotype.Service
Expand All @@ -14,44 +15,44 @@ class TagGetService(
private val experienceReader: ExperienceReader
) {
@Transactional(readOnly = true)
fun getAllParentTagByUserId(): GetTag.Response {
fun getAllParentTagByUserId(): GetParentTag.Response {
val tagDetails = getAuthenticationPrincipal().let {
tagReader.readAllParentTagsByUserId(it).map { tag ->
GetTag.TagDetail(tag.id, tag.name)
GetParentTag.TagDetail(tag.id, tag.name)
}
}

return GetTag.Response(tagDetails)
return GetParentTag.Response(tagDetails)
}

@Transactional(readOnly = true)
fun getAllChildTagsByParentTagId(parentTagId: UUID): GetTag.Response {
fun getAllChildTagsByParentTagId(parentTagId: UUID): GetChildTag.Response {
val tagDetails = getAuthenticationPrincipal().let {
tagReader.readAllChildTagsByUserId(it, parentTagId).map { tag ->
GetTag.TagDetail(tag.id, tag.name)
GetParentTag.TagDetail(tag.id, tag.name)
}
}

return GetTag.Response(tagDetails)
return GetChildTag.Response(tagDetails)
}

@Transactional(readOnly = true)
fun getParentTagsByYearAndLimit(year: Int, limit: Int): GetTag.Response {
fun getParentTagsByYearAndLimit(year: Int, limit: Int): GetParentTag.Response {
val currentUserId = getAuthenticationPrincipal()
val topParentTagIds = experienceReader.readByYearDesc(year, currentUserId)
.distinctBy { it.parentTagId }
.take(limit)
.map { it.parentTagId }

return tagReader.readByIds(topParentTagIds).map {
GetTag.TagDetail(it.id, it.name)
GetParentTag.TagDetail(it.id, it.name)
}.let {
GetTag.Response(it)
GetParentTag.Response(it)
}
}

@Transactional(readOnly = true)
fun getAllParentTagsByYear(year: Int): GetTag.TotalTagInfo {
fun getAllParentTagsByYear(year: Int): GetParentTag.TotalTagInfo {
val currentUserId = getAuthenticationPrincipal()
val experiences = experienceReader.readByYearDesc(year, currentUserId)

Expand All @@ -67,15 +68,37 @@ class TagGetService(
}
}

GetTag.TagSummary(
GetParentTag.ParentTagSummary(
parentTag.id,
parentTag.name,
strongPoints.size,
it.value.size
)
}

return GetTag.TotalTagInfo(
return GetParentTag.TotalTagInfo(
experiences.size,
tagSummaries
)
}

@Transactional(readOnly = true)
fun getAllChildTagsByYearAndParentTagId(year: Int, parentTagId: UUID): GetChildTag.TotalTagInfo {
val currentUserId = getAuthenticationPrincipal()
val experiences = experienceReader.readByYearDesc(year, currentUserId)
val experienceGroup = experiences.groupBy { it.childTagId }

val tagSummaries = experienceGroup.map {
val childTag = tagReader.readById(it.key)

GetChildTag.ChildTagSummary(
childTag.id,
childTag.name,
it.value.size
)
}

return GetChildTag.TotalTagInfo(
experiences.size,
tagSummaries
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.bamyanggang.apimodule.domain.tag.presentation

object TagApi {
const val BASE_URL = "/api/tags"
const val MY_TAG_URL = "$BASE_URL/my"
const val MY_PARENT_TAG_URL = "$BASE_URL/my"
const val TOP_RANK_TAG_URL = "$BASE_URL/top-rank"
const val TAG_PATH_VARIABLE_URL = "$BASE_URL/{tagId}"
const val MY_CHILD_TAG_URL = "$BASE_URL/{tagId}/my"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.bamyanggang.apimodule.domain.tag.presentation

import com.bamyanggang.apimodule.domain.tag.application.dto.CreateTag
import com.bamyanggang.apimodule.domain.tag.application.dto.GetTag
import com.bamyanggang.apimodule.domain.tag.application.dto.GetChildTag
import com.bamyanggang.apimodule.domain.tag.application.dto.GetParentTag
import com.bamyanggang.apimodule.domain.tag.application.service.TagCreateService
import com.bamyanggang.apimodule.domain.tag.application.service.TagDeleteService
import com.bamyanggang.apimodule.domain.tag.application.service.TagGetService
Expand All @@ -14,29 +15,35 @@ class TagController(
private val tagDeleteService: TagDeleteService,
private val tagGetService: TagGetService
) {
@GetMapping(TagApi.BASE_URL)
fun getParentTagsByYear(@RequestParam("year") year: Int): GetTag.TotalTagInfo {
return tagGetService.getAllParentTagsByYear(year)
}

@GetMapping(TagApi.TOP_RANK_TAG_URL)
fun getTopRankTagsByLimit(
@RequestParam("year") year: Int,
@RequestParam("limit") limit: Int
): GetTag.Response {
): GetParentTag.Response {
return tagGetService.getParentTagsByYearAndLimit(year, limit)
}

@GetMapping(TagApi.MY_TAG_URL)
fun getUserParentTags(): GetTag.Response {
@GetMapping(TagApi.MY_PARENT_TAG_URL)
fun getUserParentTags(): GetParentTag.Response {
return tagGetService.getAllParentTagByUserId()
}

@GetMapping(TagApi.TAG_PATH_VARIABLE_URL)
fun getAllChildTags(@PathVariable("tagId") parentTagId: UUID): GetTag.Response {
@GetMapping(TagApi.MY_CHILD_TAG_URL)
fun getUserChildTags(@PathVariable("tagId") parentTagId: UUID): GetChildTag.Response {
return tagGetService.getAllChildTagsByParentTagId(parentTagId)
}

@GetMapping(TagApi.BASE_URL)
fun getParentTagsByYear(@RequestParam("year") year: Int): GetParentTag.TotalTagInfo {
return tagGetService.getAllParentTagsByYear(year)
}

@GetMapping(TagApi.TAG_PATH_VARIABLE_URL)
fun getChildTagsByYear(@PathVariable("tagId") parentTagId: UUID,
@RequestParam("year") year: Int): GetChildTag.TotalTagInfo {
return tagGetService.getAllChildTagsByYearAndParentTagId(year, parentTagId)
}

@PostMapping(TagApi.BASE_URL)
fun createParentTag(@RequestBody request: CreateTag.Request): CreateTag.Response {
return tagCreateService.createParentTag(request)
Expand Down
Loading

0 comments on commit a85f71c

Please sign in to comment.