Skip to content

Commit

Permalink
[48] 일반 유저와 파트너 유저의 주문 리스트 api 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
ohsuha committed Nov 1, 2024
1 parent d122f0a commit 2c7d1b4
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;

import org.example.commerce_site.application.order.OrderFacade;
import org.example.commerce_site.attribute.UserRoles;
import org.example.commerce_site.common.exception.CustomException;
import org.example.commerce_site.common.exception.ErrorCode;
import org.example.commerce_site.common.response.ApiSuccessResponse;
Expand Down Expand Up @@ -60,20 +61,18 @@ public ApiSuccessResponse.PageList<OrderResponse.Get> getOrders(
@RequestParam(value = "keyword", required = false) String keyword,
@RequestAttribute("user_id") String userAuthId
) {
Collection<? extends GrantedAuthority> authorities = SecurityContextHolder
.getContext()
.getAuthentication()
.getAuthorities();

Optional<String> primaryAuthority = authorities.stream()
.findFirst()
.map(GrantedAuthority::getAuthority);

if (primaryAuthority.isEmpty()) {
throw new CustomException(ErrorCode.ACCESS_DENIED);
}
return ApiSuccessResponse.success(
OrderResponse.Get.of(orderFacade.getOrderList(page, size, keyword, userAuthId, UserRoles.ROLE_USER.name())));
}

@GetMapping("/partner")
public ApiSuccessResponse.PageList<OrderResponse.Get> getPartnerOrders(
@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "size", defaultValue = "10") int size,
@RequestParam(value = "keyword", required = false) String keyword,
@RequestAttribute("user_id") String userAuthId
) {
return ApiSuccessResponse.success(
OrderResponse.Get.of(orderFacade.getOrderList(page, size, keyword, userAuthId, primaryAuthority.get())));
OrderResponse.Get.of(orderFacade.getOrderList(page, size, keyword, userAuthId, UserRoles.ROLE_PARTNER.name())));
}
}

0 comments on commit 2c7d1b4

Please sign in to comment.