diff --git a/src/main/kotlin/com/hero/alignlab/common/extension/QuerydslExtension.kt b/src/main/kotlin/com/hero/alignlab/common/extension/QuerydslExtension.kt index c77df6a..a16a55f 100644 --- a/src/main/kotlin/com/hero/alignlab/common/extension/QuerydslExtension.kt +++ b/src/main/kotlin/com/hero/alignlab/common/extension/QuerydslExtension.kt @@ -44,7 +44,7 @@ fun NumberPath.isEquals(parameter: Long?): BooleanExpression? { } fun StringPath.isContains(parameter: String?): BooleanExpression? { - return parameter?.takeIf { param -> param.isNotEmpty() }?.let { param -> this.contains(param) } + return parameter?.let { param -> this.contains(param) } } fun NumberPath.isIn(parameters: Set?): BooleanExpression? { diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt index 166a8f7..26a9c1f 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt @@ -252,8 +252,8 @@ class GroupFacade( } } - suspend fun searchGroup(user: AuthUser, tagName: String?, pageRequest: HeroPageRequest): Page { - val groups = groupService.findByTagNameAndPage(tagName, pageRequest.toDefault()) + suspend fun searchGroup(user: AuthUser, keyword: String?, pageRequest: HeroPageRequest): Page { + val groups = groupService.findByKeywordAndPage(keyword, pageRequest.toDefault()) val groupUserByUid = groups.content.map { group -> group.id } .run { groupUserService.findByUidAndGroupIdIn(user.uid, this) } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupService.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupService.kt index da37edb..df8e479 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupService.kt @@ -55,9 +55,9 @@ class GroupService( return groupRepository.save(group) } - suspend fun findByTagNameAndPage(tagName: String?, pageable: Pageable): Page { + suspend fun findByKeywordAndPage(keyword: String?, pageable: Pageable): Page { return withContext(Dispatchers.IO) { - groupRepository.findByTagNameAndPage(tagName, pageable) + groupRepository.findByKeywordAndPage(keyword, pageable) } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepository.kt b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepository.kt index bff8386..c5f2337 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepository.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepository.kt @@ -5,5 +5,5 @@ import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable interface GroupQRepository { - fun findByTagNameAndPage(tagName: String?, pageable: Pageable): Page + fun findByKeywordAndPage(keyword: String?, pageable: Pageable): Page } \ No newline at end of file diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepositoryImpl.kt b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepositoryImpl.kt index 16f0449..e3120eb 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepositoryImpl.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/infrastructure/GroupQRepositoryImpl.kt @@ -15,13 +15,13 @@ import org.springframework.data.domain.Pageable class GroupQRepositoryImpl( private val queryFactory: JPAQueryFactory, ) : GroupQRepository { - override fun findByTagNameAndPage(tagName: String?, pageable: Pageable): Page { + override fun findByKeywordAndPage(keyword: String?, pageable: Pageable): Page { val groups = queryFactory .selectDistinct(group) .from(group) .leftJoin(groupTagMap).on(group.id.eq(groupTagMap.groupId)) .leftJoin(groupTag).on(groupTagMap.tagId.eq(groupTag.id)) - .where(groupTag.name.isContains(tagName)) + .where(group.name.isContains(keyword)?.or(groupTag.name.isContains(keyword))) .offset(pageable.offset) .limit(pageable.pageSize.toLong()) .orderBy(getGroupOrderSpecifier(pageable)) @@ -32,7 +32,7 @@ class GroupQRepositoryImpl( .from(group) .leftJoin(groupTagMap).on(group.id.eq(groupTagMap.groupId)) .leftJoin(groupTag).on(groupTagMap.tagId.eq(groupTag.id)) - .where(groupTag.name.isContains(tagName)) + .where(group.name.isContains(keyword)?.or(groupTag.name.isContains(keyword))) .orderBy(getGroupOrderSpecifier(pageable)) .fetchOne() ?: 0L @@ -40,11 +40,11 @@ class GroupQRepositoryImpl( } private fun getGroupOrderSpecifier(pageable: Pageable): OrderSpecifier?>? { - val order = pageable.sort.firstOrNull() ?: return null + val order = pageable.sort.firstOrNull() ?: return group.createdAt.desc() val orderSpecifier: ComparableExpressionBase> = when (order.property) { "createdAt" -> group.createdAt "name" -> group.name - "ownerUid" -> group.ownerUid + "userCount" -> group.userCount else -> group.createdAt } return if (order.isDescending) orderSpecifier.desc() else orderSpecifier.asc() diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupResource.kt b/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupResource.kt index 3411d28..18f9180 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupResource.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupResource.kt @@ -49,10 +49,10 @@ class GroupResource( @GetMapping("/api/v1/groups") suspend fun searchGroups( user: AuthUser, - @RequestParam(required = false) tagName: String?, + @RequestParam(required = false) keyword: String?, @ParameterObject pageRequest: HeroPageRequest, ): PageResponse { - return groupFacade.searchGroup(user, tagName, pageRequest).wrapPage() + return groupFacade.searchGroup(user, keyword, pageRequest).wrapPage() } @Operation(summary = "그룹 생성")