Skip to content

Commit

Permalink
feat: 그룹 검색 응답값에 태그 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leeheefull committed Dec 11, 2024
1 parent a6c7efa commit 3e09cb7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,19 @@ class GroupFacade(

suspend fun searchGroup(user: AuthUser, keyword: String?, pageRequest: HeroPageRequest): Page<SearchGroupResponse> {
val groups = groupService.findByKeywordAndPage(keyword, pageRequest.toDefault())
val groupIds = groups.content.map { group -> group.id }

val groupUserByUid = groups.content.map { group -> group.id }
val groupUserByUid = groupIds
.run { groupUserService.findByUidAndGroupIdIn(user.uid, this) }
.associateBy { groupUser -> groupUser.groupId }

val groupTagsByGroupId = groupTagService.findGroupTagNamesByGroupIds(groupIds)

return groups
.map { group ->
val hasJoined = groupUserByUid[group.id] != null
SearchGroupResponse.from(group, hasJoined)
val groupTags = groupTagsByGroupId[group.id]
SearchGroupResponse.from(group, hasJoined, groupTags)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ class GroupTagService(
}
}

suspend fun findGroupTagNamesByGroupIds(groupIds: List<Long>): Map<Long, List<String>> {
return withContext(Dispatchers.IO) {
groupTagRepository.findByGroupIds(groupIds)
.groupBy { it.groupId }
.mapValues { entry -> entry.value.map { it.tagName } }
}
}

fun validateGroupTag(tagNames: List<String>) {
if (tagNames.size > 3) {
throw InvalidRequestException(ErrorCode.OVER_COUNT_GROUP_TAG_ERROR)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.hero.alignlab.domain.group.infrastructure

import com.hero.alignlab.domain.group.domain.GroupTag
import com.hero.alignlab.domain.group.infrastructure.result.GroupTagQueryResult

interface GroupTagQRepository {
fun findByGroupId(groupId: Long): List<GroupTag>

fun findByGroupIds(groupIds: List<Long>): List<GroupTagQueryResult>

fun deleteGroupTagMapByGroupId(groupId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.hero.alignlab.domain.group.infrastructure
import com.hero.alignlab.domain.group.domain.GroupTag
import com.hero.alignlab.domain.group.domain.QGroupTag.groupTag
import com.hero.alignlab.domain.group.domain.QGroupTagMap.groupTagMap
import com.hero.alignlab.domain.group.infrastructure.result.GroupTagQueryResult
import com.querydsl.core.types.Projections
import com.querydsl.jpa.impl.JPAQueryFactory

class GroupTagQRepositoryImpl(
Expand All @@ -15,6 +17,23 @@ class GroupTagQRepositoryImpl(
.fetch()
}

override fun findByGroupIds(groupIds: List<Long>): List<GroupTagQueryResult> {
return queryFactory
.select(
Projections.constructor(
GroupTagQueryResult::class.java,
groupTag.id,
groupTagMap.groupId,
groupTag.name,
)
)
.from(groupTag)
.join(groupTagMap).on(groupTag.id.eq(groupTagMap.tagId))
.where(groupTagMap.groupId.`in`(groupIds))
.fetch()
}


override fun deleteGroupTagMapByGroupId(groupId: Long) {
queryFactory.delete(groupTagMap)
.where(groupTagMap.groupId.eq(groupId))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.hero.alignlab.domain.group.infrastructure.result

/** QueryDsl Projection Class(수정 주의) */
class GroupTagQueryResult(
val tagId: Long,
val groupId: Long,
val tagName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ data class SearchGroupResponse(
val isHidden: Boolean,
/** 그룹에 속해 있는지 여부 */
val hasJoined: Boolean,
/** 그룹 태그 리스트 */
val tagNames: List<String>,
) {
companion object {
fun from(group: Group, hasJoined: Boolean): SearchGroupResponse {
fun from(group: Group, hasJoined: Boolean, tagNames: List<String>?): SearchGroupResponse {
return SearchGroupResponse(
id = group.id,
userCount = group.userCount,
userCapacity = group.userCapacity,
name = group.name,
isHidden = group.isHidden,
hasJoined = hasJoined
hasJoined = hasJoined,
tagNames = tagNames ?: emptyList(),
)
}
}
Expand Down

0 comments on commit 3e09cb7

Please sign in to comment.