Skip to content

Commit

Permalink
refactor: 연도 조회 API 응답 값 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
whereami2048 committed May 20, 2024
1 parent 25ea75c commit 6e2f9f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package com.bamyanggang.apimodule.domain.experience.application.dto

import java.util.*

class ExperienceYear {
data class Response(
val years : List<Int>
val years : List<Int>,
val yearTagInfos: List<YearTagInfo>
)

data class YearTagInfo(
val year: Int,
val tags: List<TagDetail>
)

data class TagDetail(
val id: UUID,
val name: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,29 @@ class ExperienceGetService(
fun getAllYearsByExistExperience(): ExperienceYear.Response {
val currentUserId = getAuthenticationPrincipal()

return experienceReader.readAllYearsByExistExperience(currentUserId)
.let { ExperienceYear.Response(it) }
val years = experienceReader.readAllYearsByExistExperience(currentUserId)
val yearTagInfos = years.map { year ->
val parentTagIds = experienceReader.readByUserIDAndYearDesc(year, currentUserId)
.distinctBy { it.parentTagId }
.map { it.parentTagId }

val tagDetails = tagReader.readByIds(parentTagIds).map {
ExperienceYear.TagDetail(
id = it.id,
name = it.name
)
}

ExperienceYear.YearTagInfo(
year,
tagDetails
)
}

return ExperienceYear.Response(
years,
yearTagInfos
)
}

fun getExperienceByYearAndParentTag(year: Int, parentTagId: UUID): GetExperience.Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,11 @@ class ExperienceControllerTest : BaseRestDocsTest() {
@DisplayName("유저의 경험 내 존재하는 연도들을 중복 제거한 리스트를 반환한다.")
fun getExperienceYearsTest() {
//given
val userId: UUID = generateFixture()
val years = arrayListOf(2020,2021,2023, 2024, 2025)
val yearResponse = ExperienceYear.Response(years)
val yearResponse = ExperienceYear.Response(
years,
generateFixture()
)

given(experienceGetService.getAllYearsByExistExperience()).willReturn(yearResponse)

Expand All @@ -541,7 +543,11 @@ class ExperienceControllerTest : BaseRestDocsTest() {
headerWithName("Authorization").description("엑세스 토큰")
),
responseFields(
fieldWithPath("years").description("경험이 존재하는 연도 배열(활동 시작 일시 기준)")
fieldWithPath("years").description("경험이 존재하는 연도 배열(활동 시작 일시 기준)"),
fieldWithPath("yearTagInfos[].year").description("연도"),
fieldWithPath("yearTagInfos[].tags").description("연도 내 상위 태그 정보"),
fieldWithPath("yearTagInfos[].tags[].id").description("상위 태그 id"),
fieldWithPath("yearTagInfos[].tags[].name").description("상위 태그 이름"),
)
)
)
Expand Down

0 comments on commit 6e2f9f0

Please sign in to comment.