Skip to content

Commit

Permalink
Merge pull request #111 from KUSITMS-29th-TEAM-B/feat/flight-42
Browse files Browse the repository at this point in the history
feat: 경험 목록 조회 API 구현(#42)
  • Loading branch information
whereami2048 authored May 20, 2024
2 parents e1c50cd + 40cffe1 commit 51cd663
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 53 deletions.
5 changes: 5 additions & 0 deletions Api-Module/src/docs/asciidoc/Experience.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ operation::ExperienceControllerTest/deleteExperienceTest/[snippets='http-request

operation::ExperienceControllerTest/getExperienceDetailTest/[snippets='http-request,path-parameters,request-headers,request-body,http-response,response-body']

[[GetExperiencesTest]]
=== 경험 목록 조회 API

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

[[getExperienceYearsTest]]
=== 유저 경험 내 존재 연도 조회 API

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package com.bamyanggang.apimodule.domain.experience.application.dto
import java.time.LocalDateTime
import java.util.*

class DetailExperience {
class GetExperience {
data class Response(
val experiences: List<DetailExperience>
)

data class DetailExperience(
val id: UUID,
val title: String,
val parentTag: DetailTag,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.bamyanggang.apimodule.domain.experience.application.service

import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.experience.application.dto.DetailExperience
import com.bamyanggang.apimodule.domain.experience.application.dto.ExperienceYear
import com.bamyanggang.apimodule.domain.experience.application.dto.GetExperience
import com.bamyanggang.domainmodule.domain.experience.aggregate.Experience
import com.bamyanggang.domainmodule.domain.experience.service.ExperienceReader
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointReader
import com.bamyanggang.domainmodule.domain.tag.service.TagReader
Expand All @@ -15,56 +16,82 @@ class ExperienceGetService(
private val strongPointReader: StrongPointReader,
private val tagReader: TagReader,
) {
fun getExperienceDetailById(experienceId: UUID) : DetailExperience.Response {
fun getExperienceDetailById(experienceId: UUID) : GetExperience.DetailExperience {
val oneExperience = experienceReader.readExperience(experienceId)
return createExperienceDetailResponse(oneExperience)
}

val detailExperienceContents = oneExperience.contents.map {
DetailExperience.DetailExperienceContent(
it.question,
it.answer
)
fun getAllYearsByExistExperience(): ExperienceYear.Response {
val currentUserId = getAuthenticationPrincipal()

return experienceReader.readAllYearsByExistExperience(currentUserId)
.let { ExperienceYear.Response(it) }
}

fun getExperienceByYearAndParentTag(year: Int, parentTagId: UUID): GetExperience.Response {
val experiences = experienceReader.readByYearAndParentTagId(year, parentTagId).map {
createExperienceDetailResponse(it)
}

val strongPointIds = oneExperience.strongPoints.map { it.strongPointId }
val strongPointDetails = strongPointReader.readByIds(strongPointIds).map {
DetailExperience.DetailStrongPoint(
it.id,
it.name
)
return GetExperience.Response(experiences)
}

fun getExperienceByYearAndChildTag(year: Int, childTagId: UUID): GetExperience.Response {
val experiences = experienceReader.readByYearAndParentTagId(year, childTagId).map {
createExperienceDetailResponse(it)
}

val detailParentTag = tagReader.readById(oneExperience.parentTagId).let {
DetailExperience.DetailTag(
return GetExperience.Response(experiences)
}

private fun createExperienceDetailResponse(experience: Experience): GetExperience.DetailExperience {
val detailExperienceContents = convertDetailExperienceContent(experience)
val strongPointDetails = convertStrongPoints(experience)
val detailParentTag = convertParentTag(experience)
val detailChildTag = convertChildTag(experience)

return GetExperience.DetailExperience(
id = experience.id,
title = experience.title,
parentTag = detailParentTag,
childTag = detailChildTag,
strongPoints = strongPointDetails,
contents = detailExperienceContents,
startedAt = experience.startedAt,
endedAt = experience.endedAt
)
}

private fun convertChildTag(oneExperience: Experience) =
tagReader.readById(oneExperience.childTagId).let {
GetExperience.DetailTag(
it.id,
it.name
)
}

val detailChildTag = tagReader.readById(oneExperience.childTagId).let {
DetailExperience.DetailTag(
private fun convertParentTag(oneExperience: Experience) =
tagReader.readById(oneExperience.parentTagId).let {
GetExperience.DetailTag(
it.id,
it.name
)
}

return oneExperience.let {
DetailExperience.Response(
id = it.id,
title = it.title,
parentTag = detailParentTag,
childTag = detailChildTag,
strongPoints = strongPointDetails,
contents = detailExperienceContents,
startedAt = it.startedAt,
endedAt = it.endedAt
private fun convertDetailExperienceContent(experience: Experience) =
experience.contents.map { GetExperience.DetailExperienceContent(
it.question,
it.answer
)
}
}

fun getAllYearsByExistExperience(): ExperienceYear.Response {
val currentUserId = getAuthenticationPrincipal()

return experienceReader.readAllYearsByExistExperience(currentUserId)
.let { ExperienceYear.Response(it) }
private fun convertStrongPoints(experience: Experience) =
experience.strongPoints.map { it.strongPointId }.let {
strongPointReader.readByIds(it).map { strongPoint ->
GetExperience.DetailStrongPoint(
strongPoint.id,
strongPoint.name
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.bamyanggang.apimodule.domain.experience.presentation

import com.bamyanggang.apimodule.domain.experience.application.dto.CreateExperience
import com.bamyanggang.apimodule.domain.experience.application.dto.DetailExperience
import com.bamyanggang.apimodule.domain.experience.application.dto.EditExperience
import com.bamyanggang.apimodule.domain.experience.application.dto.ExperienceYear
import com.bamyanggang.apimodule.domain.experience.application.dto.*
import com.bamyanggang.apimodule.domain.experience.application.service.ExperienceCreateService
import com.bamyanggang.apimodule.domain.experience.application.service.ExperienceDeleteService
import com.bamyanggang.apimodule.domain.experience.application.service.ExperienceEditService
Expand All @@ -18,8 +15,18 @@ class ExperienceController(
private val experienceEditService: ExperienceEditService,
private val experienceGetService: ExperienceGetService
) {
@GetMapping(ExperienceApi.BASE_URL)
fun getExperienceByFilter(@RequestParam("year") year: Int,
@RequestParam("parent-tag") parentTagId: UUID,
@RequestParam("child-tag", required = false) childTagId: UUID?
) : GetExperience.Response =
when (childTagId){
null -> experienceGetService.getExperienceByYearAndParentTag(year, parentTagId)
else -> experienceGetService.getExperienceByYearAndChildTag(year, childTagId)
}

@GetMapping(ExperienceApi.EXPERIENCE_PATH_VARIABLE_URL)
fun getExperience(@PathVariable("experienceId") experienceId: UUID): DetailExperience.Response {
fun getExperience(@PathVariable("experienceId") experienceId: UUID): GetExperience.DetailExperience {
return experienceGetService.getExperienceDetailById(experienceId)
}

Expand Down
Loading

0 comments on commit 51cd663

Please sign in to comment.