Skip to content

Commit

Permalink
Merge pull request #124 from KUSITMS-29th-TEAM-B/fix/flight-121
Browse files Browse the repository at this point in the history
fix: 상위 태그 내 하위 태그 조회 API 오류 수정
  • Loading branch information
whereami2048 authored May 21, 2024
2 parents 162ada4 + bd6b922 commit 7bdf955
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class ExperienceGetService(
}

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

return GetExperience.Response(experiences)
}

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

Expand Down
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 @@ -20,8 +23,8 @@ class ExperienceController(
@RequestParam("parent-tag") parentTagId: UUID,
@RequestParam("child-tag", required = false) childTagId: UUID?
) : GetExperience.Response =
when (childTagId){
null -> experienceGetService.getExperienceByYearAndParentTag(year, parentTagId)
when {
childTagId == null -> experienceGetService.getExperienceByYearAndParentTag(year, parentTagId)
else -> experienceGetService.getExperienceByYearAndChildTag(year, childTagId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TagCreateService(
fun createChildTag(request: CreateTag.Request, parentTagId: UUID): CreateTag.Response {
return getAuthenticationPrincipal()
.also {
val userChildTags = tagReader.readAllChildTagsByUserId(it, parentTagId)
val userChildTags = tagReader.readAllChildTagsByUserIdAndParentTagId(it, parentTagId)
validateTagCountLimit(userChildTags.size)
validateDuplicatedName(userChildTags, request.name)
}.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TagGetService(
@Transactional(readOnly = true)
fun getAllChildTagsByParentTagId(parentTagId: UUID): GetChildTag.Response {
val tagDetails = getAuthenticationPrincipal().let {
tagReader.readAllChildTagsByUserId(it, parentTagId).map { tag ->
tagReader.readAllChildTagsByUserIdAndParentTagId(it, parentTagId).map { tag ->
GetParentTag.TagDetail(tag.id, tag.name)
}
}
Expand Down Expand Up @@ -84,23 +84,22 @@ class TagGetService(

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

val tagSummaries = experienceGroup.map {
val childTag = tagReader.readById(it.key)
val childTags = getAllChildTagsByParentTagId(parentTagId).tags.map { tagReader.readById(it.id) }
var totalExperienceCount = 0

val childTagDetails = childTags.map {
val experiences = experienceReader.readByChildTagIdAndYear(it.id, year)
totalExperienceCount += experiences.size
GetChildTag.ChildTagSummary(
childTag.id,
childTag.name,
it.value.size
it.id,
it.name,
experiences.size
)
}

return GetChildTag.TotalTagInfo(
experiences.size,
tagSummaries
totalExperienceCount,
childTagDetails
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ interface ExperienceRepository {
fun findByYearAndParentTagId(year: Int, parentTagId: UUID): List<Experience>
fun findByYearAndChildTagId(year: Int, childTagId: UUID): List<Experience>
fun findByUserIdAndParentTagId(userId: UUID, parentTagId: UUID): List<Experience>
fun findByUserIdAndParentTagIdAndYearDesc(year: Int, parentTagId: UUID, userId: UUID): List<Experience>
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ class ExperienceReader(
return experienceRepository.findByUserIdAndYearDesc(year, userId)
}

fun readByYearAndTagId(year: Int, parentTagId: UUID) : List<Experience> {
fun readByYearAndParentTagId(year: Int, parentTagId: UUID) : List<Experience> {
return experienceRepository.findByYearAndParentTagId(year, parentTagId)
}

fun readByUserIdAndParentTagId(userId: UUID, parentTagId: UUID): List<Experience> {
return experienceRepository.findByUserIdAndParentTagId(userId, parentTagId)
}

fun readByUserIdAndParentTagIdAndYearDesc(year: Int, parentTagId: UUID, userId: UUID): List<Experience> {
return experienceRepository.findByUserIdAndParentTagIdAndYearDesc(year, parentTagId, userId)
}

fun readByChildTagIdAndYear(childTagId: UUID, year: Int): List<Experience> {
return experienceRepository.findByYearAndChildTagId(year, childTagId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface TagRepository {
fun save(newTag : Tag)
fun findById(id : UUID) : Tag
fun findAllParentTagsByUserId(userId: UUID): List<Tag>
fun findAllChildTagsByUserId(userId: UUID, parentId: UUID): List<Tag>
fun findAllChildTagsByUserIdAndParentTagId(userId: UUID, parentId: UUID): List<Tag>
fun deleteByTagId(tagId: UUID)
fun isExistById(tagId: UUID): Boolean
fun findByParentTagIds(tagParentTagIds: List<UUID>): List<Tag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class TagReader(
return tagRepository.findAllParentTagsByUserId(userId)
}

fun readAllChildTagsByUserId(userId: UUID, parentId: UUID): List<Tag> {
return tagRepository.findAllChildTagsByUserId(userId, parentId)
fun readAllChildTagsByUserIdAndParentTagId(userId: UUID, parentId: UUID): List<Tag> {
return tagRepository.findAllChildTagsByUserIdAndParentTagId(userId, parentId)
}

fun readById(tagId: UUID): Tag {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,15 @@ public List<Experience> findByUserIdAndParentTagId(UUID userId, UUID parentTagId

return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}

@Override
public List<Experience> findByUserIdAndParentTagIdAndYearDesc(int year, UUID parentTagId, UUID userId) {
LocalDateTime startYear = LocalDateTime.of(year, 1, 1, 0, 0);
LocalDateTime endYear = LocalDateTime.of(year, 12, 31, 23, 59);

List<ExperienceJpaEntity> experienceJpaEntities = experienceJpaRepository
.findByUserIdAndParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(
userId, parentTagId, startYear, endYear);
return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface ExperienceJpaRepository extends JpaRepository<ExperienceJpaEnti
List<ExperienceJpaEntity> findByParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID parentTagId, LocalDateTime startYear, LocalDateTime endYear);
List<ExperienceJpaEntity> findByChildTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID childTagId, LocalDateTime startYear, LocalDateTime endYear);
List<ExperienceJpaEntity> findByUserIdAndParentTagId(UUID userId, UUID parentTagId);
List<ExperienceJpaEntity> findByUserIdAndParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(
UUID userId, UUID parentTagId, LocalDateTime startYear, LocalDateTime endYear);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.bamyanggang.domainmodule.domain.tag.aggregate.Tag;
import com.bamyanggang.domainmodule.domain.tag.exception.TagException.NotFoundTag;
import com.bamyanggang.domainmodule.domain.tag.repository.TagRepository;
import com.bamyanggang.persistence.common.exception.PersistenceException.NotFound;
import com.bamyanggang.persistence.tag.jpa.entity.TagJpaEntity;
import com.bamyanggang.persistence.tag.jpa.repository.TagJpaRepository;
import com.bamyanggang.persistence.tag.mapper.TagMapper;
Expand Down Expand Up @@ -31,7 +30,7 @@ public List<Tag> findAllParentTagsByUserId(UUID userId) {
}

@Override
public List<Tag> findAllChildTagsByUserId(UUID userId, UUID parentTagId) {
public List<Tag> findAllChildTagsByUserIdAndParentTagId(UUID userId, UUID parentTagId) {
List<TagJpaEntity> childTagJpaEntities = tagJpaRepository.findAllByUserIdAndParentTagId(userId, parentTagId);
return childTagJpaEntities.stream().map(tagMapper::toDomainEntity).toList();
}
Expand Down

0 comments on commit 7bdf955

Please sign in to comment.