Skip to content

Commit

Permalink
imp: 그룹 리스트 조회시, 참여 여부를 포함하여 제공
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 14, 2024
1 parent 9262c22 commit 1d382b2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,17 @@ class GroupFacade(
}

suspend fun searchGroup(user: AuthUser, pageRequest: HeroPageRequest): Page<SearchGroupResponse> {
return groupService.findAll(pageRequest.toDefault())
.map { group -> SearchGroupResponse.from(group) }
val groups = groupService.findAll(pageRequest.toDefault())

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

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

suspend fun deleteGroupUser(user: AuthUser, groupUserId: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ class GroupUserService(
groupUserRepository.findAll()
}
}

suspend fun findByUidAndGroupIdIn(uid: Long, groupIds: List<Long>): List<GroupUser> {
return withContext(Dispatchers.IO) {
groupUserRepository.findByUidAndGroupIdIn(uid, groupIds)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ interface GroupUserRepository : JpaRepository<GroupUser, Long> {
fun findByUid(uid: Long): GroupUser?

fun countAllByGroupId(groupId: Long): Long

fun findByUidAndGroupIdIn(uid: Long, groupIds: List<Long>): List<GroupUser>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ data class SearchGroupResponse(
val name: String,
/** 비밀 그룹 여부 */
val isHidden: Boolean,
/** 그룹에 속해 있는지 여부 */
val hasJoined: Boolean,
) {
companion object {
fun from(group: Group): SearchGroupResponse {
fun from(group: Group, hasJoined: Boolean): SearchGroupResponse {
return SearchGroupResponse(
id = group.id,
userCount = group.userCount,
userCapacity = group.userCapacity,
name = group.name,
isHidden = group.isHidden,
hasJoined = hasJoined
)
}
}
Expand Down

0 comments on commit 1d382b2

Please sign in to comment.