Skip to content

Commit

Permalink
fix: marketId & visitlist fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 5, 2024
1 parent 4343551 commit 87b2497
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import com.likelion.apimodule.customer.dto.TotalOrder;
import com.likelion.apimodule.order.dto.MenuOrder;
import com.likelion.coremodule.VisitList.domain.VisitList;
import com.likelion.coremodule.VisitList.exception.VisitErrorCode;
import com.likelion.coremodule.VisitList.exception.VisitException;
import com.likelion.coremodule.VisitList.service.VisitListQueryService;
import com.likelion.coremodule.customer.service.CustomerQueryService;
import com.likelion.coremodule.menu.domain.Menu;
import com.likelion.coremodule.menu.service.MenuQueryService;
import com.likelion.coremodule.order.domain.Order;
Expand All @@ -24,8 +25,7 @@
@Service
@RequiredArgsConstructor
public class CustomerFIndUseCase {

private final CustomerQueryService customerQueryService;

private final MenuQueryService menuQueryService;
private final OrderQueryService orderQueryService;
private final UserQueryService userQueryService;
Expand All @@ -52,40 +52,46 @@ public List<TotalOrder> getTotalOrder(Long storeId) {
List<OrderItem> orderItems = entry.getValue();
Order order = orderQueryService.findOrderById(orderItems.get(0).getOrder().getId());
User user = userQueryService.findById(order.getUser().getUserId());
VisitList visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.getUserId());

List<MenuOrder> menuOrders = orderItems.stream()
.map(item -> {

Menu menu = menuQueryService.findMenuById(item.getMenu().getId());

return new MenuOrder(
menu.getName(),
menu.getImageUrl(),
item.getQuantity(),
menu.getPrice() * item.getQuantity()
);
})
.collect(Collectors.toList());

Integer totalPrice = menuOrders.stream()
.mapToInt(MenuOrder::totalPrice)
.sum();

TotalOrder totalOrder = new TotalOrder(
order.getPickUpRoute(),
order.getVisitHour().toString(),
order.getVisitMin().toString(),
user.getName(),
visitList.getVisit_status(),
order.getCreatedAt(),
order.getId(),
order.getOrderNum(),
menuOrders,
totalPrice
);

totalOrders.add(totalOrder);

VisitList visitList;
if (visitListQueryService.countVisitListByStoreAndUser(storeId, user.getUserId()) > 0) {
visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.getUserId());

List<MenuOrder> menuOrders = orderItems.stream()
.map(item -> {

Menu menu = menuQueryService.findMenuById(item.getMenu().getId());

return new MenuOrder(
menu.getName(),
menu.getImageUrl(),
item.getQuantity(),
menu.getPrice() * item.getQuantity()
);
})
.collect(Collectors.toList());

Integer totalPrice = menuOrders.stream()
.mapToInt(MenuOrder::totalPrice)
.sum();

TotalOrder totalOrder = new TotalOrder(
order.getPickUpRoute(),
order.getVisitHour().toString(),
order.getVisitMin().toString(),
user.getName(),
visitList.getVisit_status(),
order.getCreatedAt(),
order.getId(),
order.getOrderNum(),
menuOrders,
totalPrice
);

totalOrders.add(totalOrder);
} else {
throw new VisitException(VisitErrorCode.NO_VISIT_LIST_INFO);
}
}

return totalOrders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public Map<LocalDate, List<VisitListInfo>> findTodayVisitList(String accessToken

return new VisitListInfo(
id,
store.getMarket().getId(),
store.getId(),
store.getName(),
store.getCategory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.likelion.coremodule.store.domain.StoreCategory;

public record VisitListInfo(Long visitListId,
Long marketId,
Long storeId,
String store,
StoreCategory category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface VisitListRepository extends JpaRepository<VisitList, Long> {
List<VisitList> findVisitListsByUserUserId(Long userId);

VisitList findVisitListByStoreIdAndUserUserId(Long storeId, Long userId);

Integer countVisitListsByStoreIdAndUserUserId(Long storeId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public List<VisitList> findVisitListsByUserId(Long userId) {
return visitListRepository.findVisitListsByUserUserId(userId);
}

public Integer countVisitListByStoreAndUser(Long storeId, Long userId) {
return visitListRepository.countVisitListsByStoreIdAndUserUserId(storeId, userId);
}

public VisitList findVisitListByStoreIdAndUserId(Long storeId, Long userId) {
return visitListRepository.findVisitListByStoreIdAndUserUserId(storeId, userId);
}
Expand Down

0 comments on commit 87b2497

Please sign in to comment.