diff --git a/src/main/java/com/interplug/qcast/biz/object/ObjectController.java b/src/main/java/com/interplug/qcast/biz/object/ObjectController.java index 49a81e6f..d6fbe32a 100644 --- a/src/main/java/com/interplug/qcast/biz/object/ObjectController.java +++ b/src/main/java/com/interplug/qcast/biz/object/ObjectController.java @@ -69,8 +69,8 @@ public class ObjectController { @GetMapping("/saleStore/{saleStoreId}/list") @ResponseStatus(HttpStatus.OK) public List selectSaleStoreList( - @PathVariable String saleStoreId, String firstFlg) throws Exception { - return objectService.selectSaleStoreList(saleStoreId, firstFlg); + @PathVariable String saleStoreId, String firstFlg, String userId) throws Exception { + return objectService.selectSaleStoreList(saleStoreId, firstFlg, userId); } @Operation(description = "물건정보 목록을 조회한다.") diff --git a/src/main/java/com/interplug/qcast/biz/object/ObjectService.java b/src/main/java/com/interplug/qcast/biz/object/ObjectService.java index 7b8cbab8..4f204bed 100644 --- a/src/main/java/com/interplug/qcast/biz/object/ObjectService.java +++ b/src/main/java/com/interplug/qcast/biz/object/ObjectService.java @@ -77,6 +77,17 @@ public class ObjectService { public List selectFirstSaleStoreList(String saleStoreId, String userId) throws Exception { + // Validation + if (StringUtils.isEmpty(saleStoreId)) { + throw new QcastException( + ErrorCode.INVALID_INPUT_VALUE, + message.getMessage("common.message.required.data", "Sale Store ID")); + } + if (StringUtils.isEmpty(userId)) { + throw new QcastException( + ErrorCode.INVALID_INPUT_VALUE, + message.getMessage("common.message.required.data", "User ID")); + } // [0]. 판매점 목록 조회 List storeList = new ArrayList(); @@ -123,12 +134,62 @@ public class ObjectService { return storeList; } - public List selectSaleStoreList(String saleStoreId, String firstFlg) - throws Exception { + public List selectSaleStoreList( + String saleStoreId, String firstFlg, String userId) throws Exception { + // Validation + if (StringUtils.isEmpty(saleStoreId)) { + throw new QcastException( + ErrorCode.INVALID_INPUT_VALUE, + message.getMessage("common.message.required.data", "Sale Store ID")); + } + if (StringUtils.isEmpty(userId)) { + throw new QcastException( + ErrorCode.INVALID_INPUT_VALUE, + message.getMessage("common.message.required.data", "User ID")); + } + // [0]. 판매점 목록 조회 List storeList = new ArrayList(); storeList = objectMapper.selectSaleStoreList(saleStoreId, firstFlg); + // [1]. 판매점 목록 조회 결과 + if (storeList.size() > 0) { + StoreFavoriteRequest storeFavoriteReq = new StoreFavoriteRequest(); + storeFavoriteReq.setUserId(userId); + + // [2]. 사용자 판매점 즐겨찾기 목록 조회 (QSP -> QCAST) + StoreFavoriteResponse storeFavoriteRes = new StoreFavoriteResponse(); + storeFavoriteRes = storeFavoriteService.getStoreFavoriteList(storeFavoriteReq); + + List> data = (List>) storeFavoriteRes.getData(); + Map result = (Map) storeFavoriteRes.getResult(); + + // [3]. 판매점 목록 중, 즐겨찾기 판매점에 해당하는 경우 정렬 기준 셋팅 + if ("S".equals(result.get("resultCode"))) { + if (data.size() > 0) { + for (SaleStoreResponse saleStore : storeList) { + String storeId = saleStore.getSaleStoreId(); + if ("1".equals(saleStore.getSaleStoreLevel())) { + saleStore.setPriority("A0"); + } else { + saleStore.setPriority("B"); + } + for (Map storeFavorite : data) { + String favStoreId = (String) storeFavorite.get("storeId"); + if (storeId.equals(favStoreId)) { + saleStore.setPriority("A" + (String) storeFavorite.get("priority")); + break; + } + } + } + // [4]. 정렬 기준 sort (오름차순) + storeList.sort(Comparator.comparing(SaleStoreResponse::getPriority)); + } + } else { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, (String) result.get("resultMsg")); + } + } + return storeList; }