Skip to content

Commit

Permalink
feat : 주문 내역 상세 조회 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunWoo9930 committed Nov 20, 2024
1 parent 0f73d2e commit 5f0e23c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jangburich.domain.store.domain.StoreUpdateRequestDTO;
import com.jangburich.domain.store.dto.condition.StoreSearchCondition;
import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType;
import com.jangburich.domain.store.dto.response.OrdersDetailResponse;
import com.jangburich.domain.store.dto.response.OrdersGetResponse;
import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse;
import com.jangburich.domain.store.dto.response.SearchStoresResponse;
Expand Down Expand Up @@ -122,4 +123,12 @@ public ResponseCustom<List<OrdersGetResponse>> getOrders(Authentication authenti
AuthenticationParser.parseUserId(authentication));
return ResponseCustom.OK(ordersLast);
}

@Operation(summary = "주문 상세 조회", description = "가게에 있는 주문을 상세 조회합니다")
@GetMapping("/orders/{ordersId}")
public ResponseCustom<OrdersDetailResponse> getOrders(Authentication authentication, @RequestParam Long orderId) {
return ResponseCustom.OK(
storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.jangburich.domain.store.dto.response;

import java.time.LocalDateTime;
import java.util.List;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@RequiredArgsConstructor
public class OrdersDetailResponse {
private Long id;
private String teamName;
private String teamUserName;
private List<Menu> menus;
private LocalDateTime dateTime;
private Integer amount;
private Integer totalPrice;
private Integer discountPrice;

@Getter
@Setter
public static class Menu {
private String menuName;
private Integer amount;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jangburich.domain.store.exception;

public class OrdersNotFoundException extends RuntimeException {
public OrdersNotFoundException() {
super("해당 가게를 찾을 수 없습니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import com.jangburich.domain.store.domain.StoreUpdateRequestDTO;
import com.jangburich.domain.store.dto.condition.StoreSearchCondition;
import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType;
import com.jangburich.domain.store.dto.response.OrdersDetailResponse;
import com.jangburich.domain.store.dto.response.OrdersGetResponse;
import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse;
import com.jangburich.domain.store.dto.response.SearchStoresResponse;
import com.jangburich.domain.store.exception.OrdersNotFoundException;
import com.jangburich.domain.store.repository.StoreRepository;
import com.jangburich.domain.store.repository.StoreTeamRepository;
import com.jangburich.domain.team.domain.Team;
Expand Down Expand Up @@ -271,17 +273,51 @@ public List<OrdersGetResponse> getOrdersLast(String userId) {
OrdersGetResponse newOrdersGetResponse = new OrdersGetResponse();
List<Cart> carts = cartRepository.findAllByOrders(orders);
newOrdersGetResponse.setId(orders.getId());
newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() :carts.get(0).getMenu().getName() + "외 " + (carts.size() - 1) + "개");
newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() :
carts.get(0).getMenu().getName() + "외 " + (carts.size() - 1) + "개");
newOrdersGetResponse.setCount(carts.size());
newOrdersGetResponse.setDate(orders.getUpdatedAt());
Integer price = 0;
for (Cart cart : carts) {
price += cart.getMenu().getPrice();
price += (cart.getMenu().getPrice() * cart.getQuantity());
}
newOrdersGetResponse.setPrice(price);
ordersGetResponses.add(newOrdersGetResponse);
}

return ordersGetResponses;
}

public OrdersDetailResponse getOrderDetails(String userId, Long orderId) {
OrdersDetailResponse ordersDetailResponse = new OrdersDetailResponse();

userRepository.findByProviderId(userId)
.orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION));

Orders orders = ordersRepository.findById(orderId).orElseThrow(OrdersNotFoundException::new);

ordersDetailResponse.setId(orders.getId());
ordersDetailResponse.setTeamName(orders.getTeam().getName());
ordersDetailResponse.setTeamUserName(orders.getUser().getName());

List<Cart> carts = cartRepository.findAllByOrders(orders);
List<OrdersDetailResponse.Menu> menus = new ArrayList<>();
Integer amount = 0;
Integer price = 0;
for (Cart cart : carts) {
OrdersDetailResponse.Menu menu = new OrdersDetailResponse.Menu();
menu.setMenuName(cart.getMenu().getName());
menu.setAmount(cart.getQuantity());
menus.add(menu);
amount += cart.getQuantity();
price += (cart.getQuantity() * cart.getMenu().getPrice());
}
ordersDetailResponse.setMenus(menus);
ordersDetailResponse.setDateTime(orders.getUpdatedAt());
ordersDetailResponse.setAmount(amount);
ordersDetailResponse.setTotalPrice(price);
ordersDetailResponse.setDiscountPrice(0);

return ordersDetailResponse;
}
}

0 comments on commit 5f0e23c

Please sign in to comment.