Skip to content

Commit

Permalink
YEL-223 [fix] 검색 빈리스트시 오류 발생 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjeongs committed Mar 9, 2024
1 parent 066142b commit ab7ee4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ List<User> findAllByGroupContainingName(@Param("groupName") String groupName,
List<User> findAllByOtherGroupContainingName(@Param("groupName") String groupName,
@Param("keyword") String keyword, @Param("uuidList") List<String> uuidList);

@Query("select u from User u " +
"where u.group.groupName like CONCAT('%', :keyword, '%') " +
"and u.uuid not in :uuidList " +
"and u not in :friendList " +
"and u.deletedAt is null " +
"order by u.name ASC ")
List<User> findAllByGroupContaining(@Param("keyword") String keyword, @Param("uuidList") List<String> uuidList, @Param("friendList") List<User> friendList);


@Query("select u from User u "
+ "where u.group.groupName = :groupName "
+ "and u.uuid not in :uuidList "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.yello.server.domain.user.repository;

import static com.yello.server.domain.user.entity.QUser.user;
import static com.yello.server.global.common.ErrorCode.AUTH_UUID_NOT_FOUND_USER_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.DEVICE_TOKEN_NOT_FOUND_USER_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.USERID_NOT_FOUND_USER_EXCEPTION;
import static com.yello.server.global.common.ErrorCode.YELLOID_NOT_FOUND_USER_EXCEPTION;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.QueryMetadata;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.exception.UserNotFoundException;
import java.util.List;
Expand All @@ -21,6 +26,7 @@
public class UserRepositoryImpl implements UserRepository {

private final UserJpaRepository userJpaRepository;
private final JPAQueryFactory jpaQueryFactory;

@Override
public User save(User user) {
Expand Down Expand Up @@ -155,7 +161,20 @@ public List<User> findAllByOtherGroupContainingYelloId(String groupName, String

@Override
public List<User> findAllByGroupNameContainingAndFriendListNotContaining(String keyword, List<String> uuidList, List<User> friendList) {
return userJpaRepository.findAllByGroupContaining(keyword, uuidList, friendList);
BooleanBuilder whereClause = new BooleanBuilder();

whereClause.and(user.group.groupName.like("%" + keyword + "%"));
whereClause.and(user.uuid.notIn(uuidList));
whereClause.and(user.deletedAt.isNull());
if(!friendList.isEmpty()) {
whereClause.and(user.notIn(friendList));
}

return jpaQueryFactory.selectFrom(user)
.where(whereClause)
.orderBy(user.name.asc())
.fetch();

}

@Override
Expand Down

0 comments on commit ab7ee4e

Please sign in to comment.