66import eatda .domain .store .District ;
77import eatda .domain .store .Store ;
88import eatda .domain .store .StoreCategory ;
9+ import jakarta .persistence .criteria .JoinType ;
910import java .util .List ;
1011import org .springframework .data .domain .PageRequest ;
1112import org .springframework .data .domain .Pageable ;
@@ -19,20 +20,26 @@ public interface CheerRepository extends JpaRepository<Cheer, Long> {
1920 @ EntityGraph (attributePaths = {"member" , "cheerTags.values" })
2021 List <Cheer > findAllByStoreOrderByCreatedAtDesc (Store store , PageRequest pageRequest );
2122
22- default List <Cheer > findAllByConditions (@ Nullable StoreCategory category , List <CheerTagName > cheerTagNames ,
23+ default List <Cheer > findAllByConditions (@ Nullable StoreCategory category ,
24+ List <CheerTagName > cheerTagNames ,
2325 List <District > districts , Pageable pageable ) {
2426 Specification <Cheer > spec = createSpecification (category , cheerTagNames , districts );
2527 return findAll (spec , pageable );
2628 }
2729
28- private Specification <Cheer > createSpecification (@ Nullable StoreCategory category , List <CheerTagName > cheerTagNames ,
30+ private Specification <Cheer > createSpecification (@ Nullable StoreCategory category ,
31+ List <CheerTagName > cheerTagNames ,
2932 List <District > districts ) {
3033 Specification <Cheer > spec = Specification .allOf ();
3134 if (category != null ) {
3235 spec = spec .and ((root , query , cb ) -> cb .equal (root .get ("store" ).get ("category" ), category ));
3336 }
3437 if (!cheerTagNames .isEmpty ()) {
35- spec = spec .and (((root , query , cb ) -> root .get ("cheerTags" ).get ("values" ).get ("name" ).in (cheerTagNames )));
38+ spec = spec .and (((root , query , cb ) -> {
39+ query .distinct (true );
40+ return root .join ("cheerTags" ).join ("values" , JoinType .LEFT )
41+ .get ("name" ).in (cheerTagNames );
42+ }));
3643 }
3744 if (!districts .isEmpty ()) {
3845 spec = spec .and ((root , query , cb ) -> root .get ("store" ).get ("district" ).in (districts ));
0 commit comments