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 58aa5027..afbdfc82 100644 --- a/src/main/java/com/interplug/qcast/biz/object/ObjectController.java +++ b/src/main/java/com/interplug/qcast/biz/object/ObjectController.java @@ -1,15 +1,31 @@ package com.interplug.qcast.biz.object; -import com.interplug.qcast.biz.object.dto.*; +import java.util.List; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import com.interplug.qcast.biz.object.dto.ObjectRequest; +import com.interplug.qcast.biz.object.dto.ObjectResponse; +import com.interplug.qcast.biz.object.dto.PlanReqRequest; +import com.interplug.qcast.biz.object.dto.PlanReqResponse; +import com.interplug.qcast.biz.object.dto.PlanRequest; +import com.interplug.qcast.biz.object.dto.PrefResponse; +import com.interplug.qcast.biz.object.dto.SaleStoreResponse; +import com.interplug.qcast.biz.object.dto.UploadRequest; +import com.interplug.qcast.biz.object.dto.WindSpeedResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; @Slf4j @RestController @@ -17,7 +33,7 @@ import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @Tag(name = "ObjectController", description = "물건정보 관련 API") public class ObjectController { - // @Autowired private ObjectService objectService; + // @Autowired private ObjectService objectService; private final ObjectService objectService; @Operation(description = "물건정보 도도부현을 조회한다.") @@ -44,9 +60,9 @@ public class ObjectController { @Operation(description = "판매점 목록을 조회한다.") @GetMapping("/saleStore/{saleStoreId}/list") @ResponseStatus(HttpStatus.OK) - public List selectSaleStoreList(@PathVariable String saleStoreId) - throws Exception { - return objectService.selectSaleStoreList(saleStoreId); + public List selectSaleStoreList(@PathVariable String saleStoreId, + String userId) throws Exception { + return objectService.selectSaleStoreList(saleStoreId, userId); } @Operation(description = "물건정보 목록을 조회한다.") @@ -115,12 +131,8 @@ public class ObjectController { @Operation(description = "견적서 파일을 다운로드한다.") @PostMapping("/file/{objectNo}/{no}") @ResponseStatus(HttpStatus.OK) - public void fileDownload( - HttpServletRequest request, - HttpServletResponse response, - @PathVariable String objectNo, - @PathVariable String no) - throws Exception { + public void fileDownload(HttpServletRequest request, HttpServletResponse response, + @PathVariable String objectNo, @PathVariable String no) throws Exception { UploadRequest uploadRequest = new UploadRequest(); uploadRequest.setObjectNo(objectNo); 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 6a77a1e1..36fecf6b 100644 --- a/src/main/java/com/interplug/qcast/biz/object/ObjectService.java +++ b/src/main/java/com/interplug/qcast/biz/object/ObjectService.java @@ -1,14 +1,5 @@ package com.interplug.qcast.biz.object; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.interplug.qcast.biz.object.dto.*; -import com.interplug.qcast.config.Exception.ErrorCode; -import com.interplug.qcast.config.Exception.QcastException; -import com.interplug.qcast.config.message.Messages; -import com.interplug.qcast.util.InterfaceQsp; -import io.micrometer.common.util.StringUtils; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -17,11 +8,11 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Comparator; import java.util.List; import java.util.Map; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -29,6 +20,30 @@ import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import org.springframework.util.FileCopyUtils; import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.interplug.qcast.biz.object.dto.ObjectRequest; +import com.interplug.qcast.biz.object.dto.ObjectResponse; +import com.interplug.qcast.biz.object.dto.PlanReqRequest; +import com.interplug.qcast.biz.object.dto.PlanReqResponse; +import com.interplug.qcast.biz.object.dto.PlanRequest; +import com.interplug.qcast.biz.object.dto.PlanResponse; +import com.interplug.qcast.biz.object.dto.PrefResponse; +import com.interplug.qcast.biz.object.dto.SaleStoreResponse; +import com.interplug.qcast.biz.object.dto.UploadRequest; +import com.interplug.qcast.biz.object.dto.UploadResponse; +import com.interplug.qcast.biz.object.dto.WindSpeedResponse; +import com.interplug.qcast.biz.storeFavorite.StoreFavoriteService; +import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteRequest; +import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteResponse; +import com.interplug.qcast.config.Exception.ErrorCode; +import com.interplug.qcast.config.Exception.QcastException; +import com.interplug.qcast.config.message.Messages; +import com.interplug.qcast.util.InterfaceQsp; +import io.micrometer.common.util.StringUtils; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; @Slf4j @Service @@ -36,7 +51,8 @@ import org.springframework.web.util.UriComponentsBuilder; public class ObjectService { private final InterfaceQsp interfaceQsp; - @Autowired Messages message; + @Autowired + Messages message; @Value("${file.ini.root.path}") private String baseDirPath; @@ -46,6 +62,8 @@ public class ObjectService { private final ObjectMapper objectMapper; + private final StoreFavoriteService storeFavoriteService; + public List selectPrefList() throws Exception { return objectMapper.selectPrefList(); } @@ -58,12 +76,53 @@ public class ObjectService { return objectMapper.selectWindSpeedList(city); } - public List selectSaleStoreList(String saleStoreId) throws Exception { + public List selectSaleStoreList(String saleStoreId, String userId) + throws Exception { + + // [0]. 판매점 목록 조회 + List storeList = new ArrayList(); + if ("T01".equals(saleStoreId)) { - return objectMapper.selectSaleStoreAllList(); + storeList = objectMapper.selectSaleStoreAllList(); } else { - return objectMapper.selectSaleStoreList(saleStoreId); + storeList = objectMapper.selectSaleStoreList(saleStoreId); } + + // [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(); + saleStore.setPriority("B"); + for (Map storeFavorite : data) { + String favStoreId = (String) storeFavorite.get("storeId"); + if (storeId.equals(favStoreId)) { + saleStore.setPriority("A" + (String) storeFavorite.get("priority")); + } + } + } + // [4]. 정렬 기준 sort (오름차순) + storeList.sort(Comparator.comparing(SaleStoreResponse::getPriority)); + } + } else { + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, (String) result.get("resultMsg")); + } + } + + return storeList; + } public SaleStoreResponse selectSaleStoreInfo(String saleStoreId) throws Exception { @@ -96,13 +155,11 @@ public class ObjectService { // Validation if (StringUtils.isEmpty(objectRequest.getSaleStoreId())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Sale Store ID")); } if (StringUtils.isEmpty(objectRequest.getSaleStoreLevel())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Sale Store Level")); } @@ -131,11 +188,8 @@ public class ObjectService { objectRequest.setObjectNo(objectNo); // 물건정보 등록 - objectRequest.setAddress( - objectRequest.getPrefName() - + ((!StringUtils.isEmpty(objectRequest.getAddress())) - ? objectRequest.getAddress() - : "")); + objectRequest.setAddress(objectRequest.getPrefName() + + ((!StringUtils.isEmpty(objectRequest.getAddress())) ? objectRequest.getAddress() : "")); objectRequest.setAddresseeCompanyName( objectRequest.getObjectName() + ' ' + objectRequest.getObjectNameOmit()); objectRequest.setAddresseeCompanyNameOmit(objectRequest.getObjectNameOmit()); @@ -167,9 +221,8 @@ public class ObjectService { planReqRequest.setPlanReqNo(objectRequest.getPlanReqNo()); planReqRequest.setObjectNo(objectRequest.getObjectNo()); - String strResponse = - interfaceQsp.callApi( - HttpMethod.POST, QSP_API_URL + "/api/planReq/updateObjectNo", planReqRequest); + String strResponse = interfaceQsp.callApi(HttpMethod.POST, + QSP_API_URL + "/api/planReq/updateObjectNo", planReqRequest); if (!"".equals(strResponse)) { com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper() @@ -178,8 +231,8 @@ public class ObjectService { Map map = (Map) response.getResult(); if ("E".equals(String.valueOf(map.get("resultCode")))) { - throw new QcastException( - ErrorCode.INTERNAL_SERVER_ERROR, String.valueOf(map.get("resultMsg"))); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, + String.valueOf(map.get("resultMsg"))); } } } @@ -198,13 +251,11 @@ public class ObjectService { // Validation if (StringUtils.isEmpty(objectRequest.getSaleStoreId())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Sale Store ID")); } if (StringUtils.isEmpty(objectRequest.getSaleStoreLevel())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Sale Store Level")); } @@ -221,18 +272,13 @@ public class ObjectService { } // 물건정보 수정 - objectRequest.setAddress( - objectRequest.getPrefName() - + ((!StringUtils.isEmpty(objectRequest.getAddress())) - ? objectRequest.getAddress() - : "")); + objectRequest.setAddress(objectRequest.getPrefName() + + ((!StringUtils.isEmpty(objectRequest.getAddress())) ? objectRequest.getAddress() : "")); objectRequest.setAddresseeCompanyName( objectRequest.getObjectName() + ' ' + objectRequest.getObjectNameOmit()); objectRequest.setAddresseeCompanyNameOmit(objectRequest.getObjectNameOmit()); - objectRequest.setContentsPath( - baseDirPath - + "\\\\" - + (tempChgFlg ? objectRequest.getNewObjectNo() : objectRequest.getObjectNo())); + objectRequest.setContentsPath(baseDirPath + "\\\\" + + (tempChgFlg ? objectRequest.getNewObjectNo() : objectRequest.getObjectNo())); result += objectMapper.updateObject(objectRequest); // 임시저장에서 저장상태로 돌리기 @@ -250,9 +296,8 @@ public class ObjectService { planReqRequest.setPlanReqNo(objectRequest.getPlanReqNo()); planReqRequest.setObjectNo(objectRequest.getNewObjectNo()); - String strResponse = - interfaceQsp.callApi( - HttpMethod.POST, QSP_API_URL + "/api/planReq/updateObjectNo", planReqRequest); + String strResponse = interfaceQsp.callApi(HttpMethod.POST, + QSP_API_URL + "/api/planReq/updateObjectNo", planReqRequest); if (!"".equals(strResponse)) { com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper() @@ -261,8 +306,8 @@ public class ObjectService { Map map = (Map) response.getResult(); if ("E".equals(String.valueOf(map.get("resultCode")))) { - throw new QcastException( - ErrorCode.INTERNAL_SERVER_ERROR, String.valueOf(map.get("resultMsg"))); + throw new QcastException(ErrorCode.INTERNAL_SERVER_ERROR, + String.valueOf(map.get("resultMsg"))); } } } @@ -270,9 +315,8 @@ public class ObjectService { } // 모든 변경 완료 후 재호출 - objectResponse = - objectMapper.selectObjectDetail( - (tempChgFlg ? objectRequest.getNewObjectNo() : objectRequest.getObjectNo())); + objectResponse = objectMapper.selectObjectDetail( + (tempChgFlg ? objectRequest.getNewObjectNo() : objectRequest.getObjectNo())); return objectResponse; } @@ -281,8 +325,7 @@ public class ObjectService { // Validation if (StringUtils.isEmpty(objectRequest.getObjectNo())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Object No")); } @@ -295,8 +338,7 @@ public class ObjectService { public String insertPlan(PlanRequest planRequest) throws Exception { // Validation if (StringUtils.isEmpty(planRequest.getObjectNo())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Object No")); } @@ -322,60 +364,44 @@ public class ObjectService { // Validation if (StringUtils.isEmpty(planReqRequest.getSaleStoreId())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Sale Store ID")); } if (StringUtils.isEmpty(planReqRequest.getSaleStoreLevel())) { - throw new QcastException( - ErrorCode.INVALID_INPUT_VALUE, + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, message.getMessage("common.message.required.data", "Sale Store Level")); } PlanReqResponse response = null; /* [1]. QSP API (url + param) Setting */ - String encodedSchTitle = - URLEncoder.encode( - StringUtils.isEmpty(planReqRequest.getSchTitle()) ? "" : planReqRequest.getSchTitle(), - StandardCharsets.UTF_8); - String encodedSchAddress = - URLEncoder.encode( - StringUtils.isEmpty(planReqRequest.getSchAddress()) - ? "" - : planReqRequest.getSchAddress(), - StandardCharsets.UTF_8); + String encodedSchTitle = URLEncoder.encode( + StringUtils.isEmpty(planReqRequest.getSchTitle()) ? "" : planReqRequest.getSchTitle(), + StandardCharsets.UTF_8); + String encodedSchAddress = URLEncoder.encode( + StringUtils.isEmpty(planReqRequest.getSchAddress()) ? "" : planReqRequest.getSchAddress(), + StandardCharsets.UTF_8); String encodedSchSaleStoreName = - URLEncoder.encode( - StringUtils.isEmpty(planReqRequest.getSchSaleStoreName()) - ? "" - : planReqRequest.getSchSaleStoreName(), - StandardCharsets.UTF_8); + URLEncoder.encode(StringUtils.isEmpty(planReqRequest.getSchSaleStoreName()) ? "" + : planReqRequest.getSchSaleStoreName(), StandardCharsets.UTF_8); String encodedSchPlanReqName = - URLEncoder.encode( - StringUtils.isEmpty(planReqRequest.getSchPlanReqName()) - ? "" - : planReqRequest.getSchPlanReqName(), - StandardCharsets.UTF_8); + URLEncoder.encode(StringUtils.isEmpty(planReqRequest.getSchPlanReqName()) ? "" + : planReqRequest.getSchPlanReqName(), StandardCharsets.UTF_8); String url = QSP_API_URL + "/api/planReq/list"; - String apiUrl = - UriComponentsBuilder.fromHttpUrl(url) - .queryParam("saleStoreId", planReqRequest.getSaleStoreId()) - .queryParam("saleStoreLevel", planReqRequest.getSaleStoreLevel()) - .queryParam("schPlanReqNo", planReqRequest.getSchPlanReqNo()) - .queryParam("schTitle", encodedSchTitle) - .queryParam("schAddress", encodedSchAddress) - .queryParam("schSaleStoreName", encodedSchSaleStoreName) - .queryParam("schPlanReqName", encodedSchPlanReqName) - .queryParam("schPlanStatCd", planReqRequest.getSchPlanStatCd()) - .queryParam("schDateGbn", planReqRequest.getSchDateGbn()) - .queryParam("schStartDt", planReqRequest.getSchStartDt()) - .queryParam("schEndDt", planReqRequest.getSchEndDt()) - .queryParam("startRow", planReqRequest.getStartRow()) - .queryParam("endRow", planReqRequest.getEndRow()) - .build() - .toUriString(); + String apiUrl = UriComponentsBuilder.fromHttpUrl(url) + .queryParam("saleStoreId", planReqRequest.getSaleStoreId()) + .queryParam("saleStoreLevel", planReqRequest.getSaleStoreLevel()) + .queryParam("schPlanReqNo", planReqRequest.getSchPlanReqNo()) + .queryParam("schTitle", encodedSchTitle).queryParam("schAddress", encodedSchAddress) + .queryParam("schSaleStoreName", encodedSchSaleStoreName) + .queryParam("schPlanReqName", encodedSchPlanReqName) + .queryParam("schPlanStatCd", planReqRequest.getSchPlanStatCd()) + .queryParam("schDateGbn", planReqRequest.getSchDateGbn()) + .queryParam("schStartDt", planReqRequest.getSchStartDt()) + .queryParam("schEndDt", planReqRequest.getSchEndDt()) + .queryParam("startRow", planReqRequest.getStartRow()) + .queryParam("endRow", planReqRequest.getEndRow()).build().toUriString(); /* [2]. QSP API CALL -> Response */ String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null); @@ -394,9 +420,8 @@ public class ObjectService { return response; } - public void fileDownload( - HttpServletRequest request, HttpServletResponse response, UploadRequest uploadRequest) - throws Exception { + public void fileDownload(HttpServletRequest request, HttpServletResponse response, + UploadRequest uploadRequest) throws Exception { InputStream inputStream = null; @@ -406,12 +431,8 @@ public class ObjectService { if (uploadResponse != null) { // 첨부파일 물리적 경로 - String filePath = - baseDirPath - + File.separator - + uploadResponse.getObjectNo() - + File.separator - + uploadResponse.getFaileName(); + String filePath = baseDirPath + File.separator + uploadResponse.getObjectNo() + + File.separator + uploadResponse.getFaileName(); File file = new File(filePath); if (file.exists()) { diff --git a/src/main/java/com/interplug/qcast/biz/object/dto/SaleStoreResponse.java b/src/main/java/com/interplug/qcast/biz/object/dto/SaleStoreResponse.java index 72fb9df5..8884ecd8 100644 --- a/src/main/java/com/interplug/qcast/biz/object/dto/SaleStoreResponse.java +++ b/src/main/java/com/interplug/qcast/biz/object/dto/SaleStoreResponse.java @@ -32,4 +32,8 @@ public class SaleStoreResponse { @Schema(description = "영업사원 메일주소") private String businessChargerMail; + + @Schema(description = "정렬") + private String priority; + } diff --git a/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteController.java b/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteController.java index f9248c5b..860a5ff4 100644 --- a/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteController.java +++ b/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteController.java @@ -1,13 +1,20 @@ package com.interplug.qcast.biz.storeFavorite; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteRequest; +import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteResponse; import com.interplug.qcast.biz.user.dto.UserResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; @Slf4j @RestController @@ -15,20 +22,30 @@ import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @Tag(name = "StoreFavorite", description = "Store Favorite 관련 API") public class StoreFavoriteController { - private final StoreFavoriteService storeFavService; + private final StoreFavoriteService storeFavService; - @Operation(description = "Store Favorite 정보를 등록/수정 한다.(동기화)") - @PutMapping("/store-favorite-save") - @ResponseStatus(HttpStatus.OK) - public UserResponse setStoreFavoriteSave(@RequestBody StoreFavoriteRequest req) throws Exception { - UserResponse userResponse = new UserResponse(); + @Operation(description = "Store Favorite 정보를 등록/수정 한다.(동기화)") + @PutMapping("/store-favorite-save") + @ResponseStatus(HttpStatus.OK) + public UserResponse setStoreFavoriteSave(@RequestBody StoreFavoriteRequest req) throws Exception { + UserResponse userResponse = new UserResponse(); - int resultCnt = storeFavService.setStoreFavoriteSave(req); + int resultCnt = storeFavService.setStoreFavoriteSave(req); - if (resultCnt > 0) userResponse.setCode("200"); - else userResponse.setCode("500"); + if (resultCnt > 0) + userResponse.setCode("200"); + else + userResponse.setCode("500"); - return userResponse; - } + return userResponse; + } -} \ No newline at end of file + @Operation(description = "User Store Favorite 목록을 조회한다.") + @GetMapping("/list") + @ResponseStatus(HttpStatus.OK) + public StoreFavoriteResponse getStoreFavoriteList(@ModelAttribute StoreFavoriteRequest req) + throws Exception { + return storeFavService.getStoreFavoriteList(req); + } + +} diff --git a/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteService.java b/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteService.java index ff7121a0..800e30fe 100644 --- a/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteService.java +++ b/src/main/java/com/interplug/qcast/biz/storeFavorite/StoreFavoriteService.java @@ -1,17 +1,64 @@ package com.interplug.qcast.biz.storeFavorite; -import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteRequest; -import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; +import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteRequest; +import com.interplug.qcast.biz.storeFavorite.dto.StoreFavoriteResponse; +import com.interplug.qcast.config.Exception.ErrorCode; +import com.interplug.qcast.config.Exception.QcastException; +import com.interplug.qcast.config.message.Messages; +import com.interplug.qcast.util.InterfaceQsp; +import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class StoreFavoriteService { - private final StoreFavoriteMapper storeFavoriteMapper; + private final StoreFavoriteMapper storeFavoriteMapper; - public int setStoreFavoriteSave(StoreFavoriteRequest req) throws Exception { - return storeFavoriteMapper.setStoreFavoriteSave(req); + private final InterfaceQsp interfaceQsp; + + @Autowired + Messages message; + + @Value("${qsp.url}") + private String QSP_API_URL; + + public int setStoreFavoriteSave(StoreFavoriteRequest req) throws Exception { + return storeFavoriteMapper.setStoreFavoriteSave(req); + } + + public StoreFavoriteResponse getStoreFavoriteList(StoreFavoriteRequest req) throws Exception { + + StoreFavoriteResponse response = null; + + /* [0]. Validation Check */ + if ("".equals(req.getUserId())) { + // [msg] {0} is required input value. + throw new QcastException(ErrorCode.INVALID_INPUT_VALUE, + message.getMessage("common.message.required.data", "User Id")); } + /* [1]. QSP API (url + param) Setting */ + String url = QSP_API_URL + "/api/user/storeFavoriteInfoList"; + String apiUrl = UriComponentsBuilder.fromHttpUrl(url).queryParam("userId", req.getUserId()) + .build().toUriString(); + /* [2]. QSP API CALL -> Response */ + String strResponse = interfaceQsp.callApi(HttpMethod.GET, apiUrl, null); + + if (!"".equals(strResponse)) { + ObjectMapper om = + new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + response = om.readValue(strResponse, StoreFavoriteResponse.class); + } else { + // [msg] No data + throw new QcastException(ErrorCode.NOT_FOUND, message.getMessage("common.message.no.data")); + } + return response; + } } diff --git a/src/main/java/com/interplug/qcast/biz/storeFavorite/dto/StoreFavoriteResponse.java b/src/main/java/com/interplug/qcast/biz/storeFavorite/dto/StoreFavoriteResponse.java new file mode 100644 index 00000000..16a0d205 --- /dev/null +++ b/src/main/java/com/interplug/qcast/biz/storeFavorite/dto/StoreFavoriteResponse.java @@ -0,0 +1,13 @@ +package com.interplug.qcast.biz.storeFavorite.dto; + +import lombok.Data; + +@Data +public class StoreFavoriteResponse { + /** API response result */ + private Object result; + /** API response data */ + private Object data; +} + +