Skip to content

Commit

Permalink
fix: 상위 태그 내 하위 태그 조회 API 로직 수정(#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
whereami2048 committed May 21, 2024
1 parent a4d2515 commit bd6b922
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
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 @@ -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 @@ -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 bd6b922

Please sign in to comment.