Skip to content

Commit

Permalink
feat: 북마크한 경험 조회 APi 구현(#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
whereami2048 committed May 20, 2024
1 parent 253c09b commit 7f033e4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package com.bamyanggang.apimodule.domain.experience.application.service
import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.experience.application.dto.ExperienceYear
import com.bamyanggang.apimodule.domain.experience.application.dto.GetExperience
import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkReader
import com.bamyanggang.domainmodule.domain.experience.aggregate.Experience
import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceContent
import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceStrongPoint
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 @@ -16,6 +19,7 @@ class ExperienceGetService(
private val experienceReader: ExperienceReader,
private val strongPointReader: StrongPointReader,
private val tagReader: TagReader,
private val bookMarkReader: BookmarkReader
) {
@Transactional(readOnly = true)
fun getExperienceDetailById(experienceId: UUID) : GetExperience.DetailExperience {
Expand Down Expand Up @@ -49,11 +53,36 @@ class ExperienceGetService(
return GetExperience.Response(experiences)
}

@Transactional(readOnly = true)
fun getBookMarkExperiences(jobDescriptionId: UUID): GetExperience.Response {
val experienceIds = bookMarkReader.readByStatusOnAndJobDescriptionId(jobDescriptionId).map { it.experienceId }

val detailExperiences = experienceReader.readByIds(experienceIds).map {
val detailParentTag = convertParentTag(it.parentTagId)
val detailChildTag = convertChildTag(it.childTagId)
val detailStrongPoints = convertStrongPoints(it.strongPoints)
val detailContents = convertDetailExperienceContent(it.contents)

GetExperience.DetailExperience(
id = it.id,
title = it.title,
parentTag = detailParentTag,
childTag = detailChildTag,
strongPoints = detailStrongPoints,
contents = detailContents,
startedAt = it.startedAt,
endedAt = it.endedAt
)
}

return GetExperience.Response(detailExperiences)
}

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

return GetExperience.DetailExperience(
id = experience.id,
Expand All @@ -67,31 +96,31 @@ class ExperienceGetService(
)
}

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

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

private fun convertDetailExperienceContent(experience: Experience) =
experience.contents.map { GetExperience.DetailExperienceContent(
private fun convertDetailExperienceContent(contents: List<ExperienceContent>) =
contents.map { GetExperience.DetailExperienceContent(
it.question,
it.answer
)
}

private fun convertStrongPoints(experience: Experience) =
experience.strongPoints.map { it.strongPointId }.let {
private fun convertStrongPoints(strongPoints: List<ExperienceStrongPoint>) =
strongPoints.map { it.strongPointId }.let {
strongPointReader.readByIds(it).map { strongPoint ->
GetExperience.DetailStrongPoint(
strongPoint.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ object ExperienceApi {
const val BASE_URL = "/api/experiences"
const val EXPERIENCE_PATH_VARIABLE_URL = "$BASE_URL/{experienceId}"
const val ALL_YEARS = "$BASE_URL/all-years"
const val BOOKMARK_EXPERIENCE_URL = "$BASE_URL/{jobDescriptionId}"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.bamyanggang.apimodule.domain.experience.presentation

import com.bamyanggang.apimodule.domain.experience.application.dto.*
import com.bamyanggang.apimodule.domain.experience.application.dto.CreateExperience
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.GetExperience
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 @@ -15,6 +18,13 @@ class ExperienceController(
private val experienceEditService: ExperienceEditService,
private val experienceGetService: ExperienceGetService
) {
@GetMapping(ExperienceApi.BOOKMARK_EXPERIENCE_URL)
fun getBookMarkExperiences(
@PathVariable("jobDescriptionId") jobDescriptionId: UUID
) : GetExperience.Response{
return experienceGetService.getBookMarkExperiences(jobDescriptionId)
}

@GetMapping(ExperienceApi.BASE_URL)
fun getExperienceByFilter(@RequestParam("year") year: Int,
@RequestParam("parent-tag") parentTagId: UUID,
Expand Down

0 comments on commit 7f033e4

Please sign in to comment.