Browse Source

ProductService, move ProductController from controller.cms package to controller package

xuchaolang 6 years ago
parent
commit
6991a10393

+ 1 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/controller/MerchantController.java

@@ -32,7 +32,7 @@ public class MerchantController {
         List<Poster> posters = posterRepo.find(findSample, start, offset, new Sort(direction, sortKey));
 
         if (null == posters){
-            posters = new ArrayList<Poster>();
+            posters = new ArrayList<>();
         }
 
         log.info("Find Posters, len={}, merchantId={}", posters.size(), merchantId);

+ 108 - 5
rankin-product-service/src/main/java/cn/rankin/productservice/controller/ProductController.java

@@ -1,19 +1,26 @@
 package cn.rankin.productservice.controller;
 
-import cn.rankin.data.api.product.entity.Product;
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.common.utils.enums.BaseOrderEnum;
+import cn.rankin.data.api.product.dto.*;
+import cn.rankin.data.api.product.entity.*;
+import cn.rankin.data.api.product.entity.Package;
+import cn.rankin.productservice.code.ProductServiceAPICode;
 import cn.rankin.productservice.service.PackageService;
 import cn.rankin.productservice.service.ProductService;
-import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping(value = "/product")
-@Slf4j
 public class ProductController {
 
     @Autowired
@@ -22,10 +29,106 @@ public class ProductController {
     @Autowired
     private PackageService packageService;
 
+    @RequestMapping(method = RequestMethod.GET)
+    public APIResult<Page<Product>> search(ProductSearchDTO searchDTO) {
+        Product product = new Product();
+        String code = searchDTO.getCode();
+        if (!StringUtils.isEmpty(code)) {
+            product.setCode("%" + code + "%");
+        }
+
+        String name = searchDTO.getName();
+        if (!StringUtils.isEmpty(name)) {
+            product.setName("%" + name + "%");
+        }
+
+        product.setType(searchDTO.getType());
+
+        LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
+        sort.put("gmtModified", BaseOrderEnum.DESC);
+
+        APIResult<Page<Product>> pageAPIResult = productService.search(product, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
+
+        return pageAPIResult;
+    }
+
+    @RequestMapping(value = "/2/{productId}", method = RequestMethod.GET)
+    public APIResult getProduct(@PathVariable("productId") String productId) {
+        return productService.get(productId);
+    }
+
+    @RequestMapping(value = "/{productId}", method = RequestMethod.GET)
+    public APIResult getProduct2(@PathVariable("productId") String productId) {
+        Map<String, Object> product = productService.getProduct(productId);
+        if(null == product){
+            return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
+        } else{
+            return APIResult.ok(product);
+        }
+
+    }
+
+    @RequestMapping(value = "/course", method = RequestMethod.PUT)
+    public APIResult updateCourse(@RequestBody CourseDTO courseDTO) {
+        return productService.update(courseDTO);
+    }
+
+    @RequestMapping(value = "/support", method = RequestMethod.PUT)
+    public APIResult<Support> updateSupport(@RequestBody SupportDTO supportDTO) {
+        return productService.update(supportDTO);
+    }
+
+    @RequestMapping(value = "/package", method = RequestMethod.PUT)
+    public APIResult<Package> updatePackage(@RequestBody PackageDTO packageDTO) {
+        return productService.update(packageDTO);
+    }
+
+    @RequestMapping(value = "/training", method = RequestMethod.PUT)
+    public APIResult<Training> updateTraining(@RequestBody TrainingDTO dto) {
+        return productService.update(dto);
+    }
+
+    @RequestMapping(value = "/course", method = RequestMethod.POST)
+    public APIResult<Course> createCourse(@RequestBody CourseDTO courseDTO) {
+        return productService.create(courseDTO);
+    }
+
+    @RequestMapping(value = "/support", method = RequestMethod.POST)
+    public APIResult<Support> createSupport(@RequestBody SupportDTO supportDTO) {
+        return productService.create(supportDTO);
+    }
+
+    @RequestMapping(value = "/package", method = RequestMethod.POST)
+    public APIResult<Package> createPackage(@RequestBody PackageDTO packageDTO) {
+        return productService.create(packageDTO);
+    }
+
+    @RequestMapping(value = "/package/{productId}", method = RequestMethod.GET)
+    public APIResult<Package> getPackage(@PathVariable("productId") String productId) {
+        return productService.getPackage(productId);
+    }
+
+
+    @RequestMapping(value = "/training", method = RequestMethod.POST)
+    public APIResult<Training> createTraining(@RequestBody TrainingDTO dto) {
+        return productService.create(dto);
+    }
+
+    @RequestMapping(value = "/{productId}", method = RequestMethod.DELETE)
+    public APIResult delete(@PathVariable("productId") String productId) {
+        return productService.delete(productId);
+    }
+
+    @RequestMapping(value = "/ids", method = RequestMethod.GET)
+    public APIResult<List<Product>> findByPids(@RequestParam("id") List<String> pidList) {
+        return productService.findByPids(pidList);
+    }
+
+
     @RequestMapping(value = "/{pid}/relatedPkg", method = RequestMethod.GET)
     public List<Product> getRelatedPkg(@PathVariable("pid") String pid, @RequestParam("merchantId") String merchantId, @RequestParam("start") Long start,
-                                   @RequestParam("offset") Integer offset, @RequestParam("sortKey") String sortKey,
-                                   @RequestParam("direction") Sort.Direction direction) {
+                                       @RequestParam("offset") Integer offset, @RequestParam("sortKey") String sortKey,
+                                       @RequestParam("direction") Sort.Direction direction) {
 
         //get pkgs
         List<Product> pkgs = productService.getRelatedPackages(pid, merchantId, start, offset, sortKey, Sort.Direction.ASC);

+ 0 - 120
rankin-product-service/src/main/java/cn/rankin/productservice/controller/cms/ProductController.java

@@ -1,120 +0,0 @@
-package cn.rankin.productservice.controller.cms;
-
-import cn.rankin.common.utils.api.model.APIResult;
-import cn.rankin.common.utils.api.page.Page;
-import cn.rankin.common.utils.enums.BaseOrderEnum;
-import cn.rankin.data.api.product.dto.*;
-import cn.rankin.data.api.product.entity.*;
-import cn.rankin.data.api.product.entity.Package;
-import cn.rankin.productservice.code.ProductServiceAPICode;
-import cn.rankin.productservice.service.ProductService;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-@RestController
-@RequestMapping(value = "/product")
-public class ProductController {
-
-    @Autowired
-    private ProductService productService;
-
-    @RequestMapping(method = RequestMethod.GET)
-    public APIResult<Page<Product>> search(ProductSearchDTO searchDTO) {
-        Product product = new Product();
-        String code = searchDTO.getCode();
-        if (!StringUtils.isEmpty(code)) {
-            product.setCode("%" + code + "%");
-        }
-
-        String name = searchDTO.getName();
-        if (!StringUtils.isEmpty(name)) {
-            product.setName("%" + name + "%");
-        }
-
-        product.setType(searchDTO.getType());
-
-        LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap<>();
-        sort.put("gmtModified", BaseOrderEnum.DESC);
-
-        APIResult<Page<Product>> pageAPIResult = productService.search(product, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
-
-        return pageAPIResult;
-    }
-
-    @RequestMapping(value = "/2/{productId}", method = RequestMethod.GET)
-    public APIResult getProduct(@PathVariable("productId") String productId) {
-        return productService.get(productId);
-    }
-
-    @RequestMapping(value = "/{productId}", method = RequestMethod.GET)
-    public APIResult getProduct2(@PathVariable("productId") String productId) {
-        Map<String, Object> product = productService.getProduct(productId);
-        if(null == product){
-            return APIResult.error(ProductServiceAPICode.NOT_EXISTS);
-        }else{
-            return APIResult.ok(product);
-        }
-
-    }
-
-    @RequestMapping(value = "/course", method = RequestMethod.PUT)
-    public APIResult updateCourse(@RequestBody CourseDTO courseDTO) {
-        return productService.update(courseDTO);
-    }
-
-    @RequestMapping(value = "/support", method = RequestMethod.PUT)
-    public APIResult<Support> updateSupport(@RequestBody SupportDTO supportDTO) {
-        return productService.update(supportDTO);
-    }
-
-    @RequestMapping(value = "/package", method = RequestMethod.PUT)
-    public APIResult<Package> updatePackage(@RequestBody PackageDTO packageDTO) {
-        return productService.update(packageDTO);
-    }
-
-    @RequestMapping(value = "/training", method = RequestMethod.PUT)
-    public APIResult<Training> updateTraining(@RequestBody TrainingDTO dto) {
-        return productService.update(dto);
-    }
-
-    @RequestMapping(value = "/course", method = RequestMethod.POST)
-    public APIResult<Course> createCourse(@RequestBody CourseDTO courseDTO) {
-        return productService.create(courseDTO);
-    }
-
-    @RequestMapping(value = "/support", method = RequestMethod.POST)
-    public APIResult<Support> createSupport(@RequestBody SupportDTO supportDTO) {
-        return productService.create(supportDTO);
-    }
-
-    @RequestMapping(value = "/package", method = RequestMethod.POST)
-    public APIResult<Package> createPackage(@RequestBody PackageDTO packageDTO) {
-        return productService.create(packageDTO);
-    }
-
-    @RequestMapping(value = "/package/{productId}", method = RequestMethod.GET)
-    public APIResult<Package> getPackage(@PathVariable("productId") String productId) {
-        return productService.getPackage(productId);
-    }
-
-
-    @RequestMapping(value = "/training", method = RequestMethod.POST)
-    public APIResult<Training> createTraining(@RequestBody TrainingDTO dto) {
-        return productService.create(dto);
-    }
-
-    @RequestMapping(value = "/{productId}", method = RequestMethod.DELETE)
-    public APIResult delete(@PathVariable("productId") String productId) {
-        return productService.delete(productId);
-    }
-
-    @RequestMapping(value = "/ids", method = RequestMethod.GET)
-    public APIResult<List<Product>> findByPids(@RequestParam("id") List<String> pidList) {
-        return productService.findByPids(pidList);
-    }
-}