88import eatda .exception .BusinessException ;
99import java .util .List ;
1010import java .util .Optional ;
11+ import org .springframework .data .domain .Page ;
1112import org .springframework .data .domain .Pageable ;
1213import org .springframework .data .jpa .domain .Specification ;
13- import org .springframework .data .jpa .repository .EntityGraph ;
1414import org .springframework .data .jpa .repository .JpaRepository ;
1515import org .springframework .data .jpa .repository .Query ;
1616import org .springframework .lang .Nullable ;
@@ -33,16 +33,15 @@ default Store getById(Long id) {
3333 """ )
3434 List <Store > findAllByCheeredMemberId (long memberId );
3535
36- default List <Store > findAllByConditions (@ Nullable StoreCategory category ,
36+ default Page <Store > findAllByConditions (@ Nullable StoreCategory category ,
3737 List <CheerTagName > cheerTagNames ,
3838 List <District > districts ,
3939 Pageable pageable ) {
4040 Specification <Store > spec = createSpecification (category , cheerTagNames , districts );
4141 return findAll (spec , pageable );
4242 }
4343
44- @ EntityGraph (attributePaths = {"cheers" })
45- List <Store > findAll (Specification <Store > spec , Pageable pageable );
44+ Page <Store > findAll (Specification <Store > spec , Pageable pageable );
4645
4746 private Specification <Store > createSpecification (@ Nullable StoreCategory category ,
4847 List <CheerTagName > cheerTagNames ,
@@ -52,8 +51,12 @@ private Specification<Store> createSpecification(@Nullable StoreCategory categor
5251 spec = spec .and ((root , query , cb ) -> cb .equal (root .get ("category" ), category ));
5352 }
5453 if (!cheerTagNames .isEmpty ()) {
55- spec = spec .and (((root , query , cb ) ->
56- root .join ("cheers" ).join ("cheerTags" ).join ("values" ).get ("name" ).in (cheerTagNames )));
54+ spec = spec .and (((root , query , cb ) -> {
55+ if (query != null ) {
56+ query .distinct (true );
57+ }
58+ return root .join ("cheers" ).join ("cheerTags" ).join ("values" ).get ("name" ).in (cheerTagNames );
59+ }));
5760 }
5861 if (!districts .isEmpty ()) {
5962 spec = spec .and ((root , query , cb ) -> root .get ("district" ).in (districts ));
0 commit comments