|
@@ -1,18 +1,51 @@
|
|
|
package cn.rankin.userservice.controller;
|
|
|
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
+import cn.rankin.common.utils.api.page.Page;
|
|
|
import cn.rankin.data.api.user.dto.CollectionDTO;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import cn.rankin.data.api.user.entity.Collection;
|
|
|
+import cn.rankin.userservice.code.UserServiceAPICode;
|
|
|
+import cn.rankin.userservice.service.CollectionService;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/user/collection")
|
|
|
public class CollectionController {
|
|
|
|
|
|
+ protected static final int MAX_SIZE = 1000;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CollectionService collectionService;
|
|
|
+
|
|
|
@RequestMapping(method = RequestMethod.PUT)
|
|
|
public APIResult<Boolean> put(@RequestBody CollectionDTO collectionDTO) {
|
|
|
- return null;
|
|
|
+ return collectionService.put(collectionDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(method = RequestMethod.GET)
|
|
|
+ public APIResult<List<Collection>> getCollections(@RequestParam("userId") String userId, @RequestParam(value = "size", required = false) Integer size) {
|
|
|
+ if (StringUtils.isEmpty(userId)) {
|
|
|
+ return APIResult.error(UserServiceAPICode.PARAMETER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (size == 0 || size == null) {
|
|
|
+ size = MAX_SIZE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return collectionService.gets(userId, size);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/page", method = RequestMethod.GET)
|
|
|
+ public APIResult<Page<Collection>> getPage(@RequestParam("userId") String userId, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
|
|
|
+ return collectionService.getPage(userId, pageNo, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(method = RequestMethod.DELETE)
|
|
|
+ public APIResult<Boolean> delete(@RequestParam("userId") String userId, @RequestParam("pid") String productId) {
|
|
|
+ return collectionService.delete(userId, productId);
|
|
|
}
|
|
|
}
|