-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from 28th-meetup/fix/store
Fix/store
- Loading branch information
Showing
10 changed files
with
191 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/kusitms/jipbap/food/FoodRepositoryExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.kusitms.jipbap.food; | ||
|
||
import com.kusitms.jipbap.user.User; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface FoodRepositoryExtension { | ||
List<Food> searchByNameOrderBySort(User user, Pageable pageable, String keyword, String standard, String order); | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/kusitms/jipbap/food/FoodRepositoryExtensionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.kusitms.jipbap.food; | ||
|
||
import com.kusitms.jipbap.common.utils.QueryDslUtils; | ||
import com.kusitms.jipbap.order.Review; | ||
import com.kusitms.jipbap.order.ReviewRepositoryExtension; | ||
import com.kusitms.jipbap.store.Store; | ||
import com.kusitms.jipbap.user.User; | ||
import com.querydsl.core.types.Order; | ||
import com.querydsl.core.types.OrderSpecifier; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.kusitms.jipbap.food.QFood.food; | ||
import static com.kusitms.jipbap.order.QOrder.order; | ||
import static com.kusitms.jipbap.order.QReview.review; | ||
import static com.kusitms.jipbap.store.QStore.store; | ||
import static org.springframework.util.ObjectUtils.isEmpty; | ||
|
||
@RequiredArgsConstructor | ||
public class FoodRepositoryExtensionImpl implements FoodRepositoryExtension { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
|
||
@Override | ||
public List<Food> searchByNameOrderBySort(User user, Pageable pageable, String keyword, String standard, String order) { | ||
|
||
List<OrderSpecifier<?>> orderSpecifiers = getAllOrderSpecifiersByPageable(pageable); | ||
|
||
return queryFactory.selectFrom(food) | ||
.where( | ||
containsKeyword(keyword) | ||
) | ||
.orderBy(orderSpecifiers.toArray(OrderSpecifier[]::new)) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression containsKeyword(String keyword) { | ||
if(keyword == null) { | ||
return null; | ||
} | ||
return food.name.contains(keyword); | ||
} | ||
|
||
private List<OrderSpecifier<?>> getAllOrderSpecifiersByPageable(Pageable pageable) { | ||
|
||
List<OrderSpecifier<?>> orderSpecifierList = new ArrayList<>(); | ||
|
||
if (!isEmpty(pageable.getSort())) { | ||
for (Sort.Order order : pageable.getSort()) { | ||
Order direction = order.getDirection().isAscending() ? Order.ASC : Order.DESC; | ||
switch (order.getProperty()) { | ||
// 기본 정렬조건: 추천순 | ||
case "bookmark": // 추천순 | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(direction, store, "bookmarkCount")); | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(Order.DESC, store, "id")); | ||
break; | ||
case "review": // 후기순 | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(direction, store, "reviewCount")); | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(Order.DESC, store, "id")); | ||
break; | ||
case "rate": // 평점순 | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(direction, store, "avgRate")); | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(Order.DESC, store, "id")); | ||
break; | ||
case "id": // 최신순 | ||
orderSpecifierList.add(QueryDslUtils.getSortedColumn(direction, store, "id")); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return orderSpecifierList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,4 @@ public class FoodDto { | |
private String description; | ||
private String image; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/kusitms/jipbap/store/dto/StoreFoodResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.kusitms.jipbap.store.dto; | ||
|
||
import com.kusitms.jipbap.food.dto.FoodDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class StoreFoodResponseDto { | ||
|
||
private List<StoreDetailResponseDto> stores; | ||
private List<FoodDto> foods; | ||
} |