package com.zhujizheng.IHome.collect.controller; import com.zhujizheng.IHome.collect.dto.PYCollectDTO; import com.zhujizheng.IHome.collect.service.PYCollectService; import com.zhujizheng.IHome.collect.vo.PYCollectVO; import com.zhujizheng.IHome.util.response.ResponseResult; import com.zhujizheng.IHome.util.response.RestResultGenerator; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; /** * Created with IntelliJ IDEA *

* Author: yons * Date: 2021/03/20 * Time: 01:48 * Description: * Copyright © 2021年 com.zhujizheng. All rights reserved. */ @Api("收藏相关") @RestController @RequestMapping("/collect") @Slf4j public class PYCollectController { @Autowired private PYCollectService collectService; @ApiOperation("添加收藏数据") @ApiImplicitParam(name = "collectDTO", value = "添加的收藏数据", required = true, dataType = "PYCollectDTO") @PostMapping("/push") public ResponseResult pushCollect(@Validated @RequestBody PYCollectDTO pushDTO) { System.out.println("pushDTO = " + pushDTO); PYCollectVO vo = collectService.pushCollectWithDTO(pushDTO); if (vo == null) { return RestResultGenerator.genErrorResult("收藏失败"); } else { return RestResultGenerator.genResult(vo, "收藏成功"); } } @ApiOperation("获取收藏数据") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", paramType = "path", required = true, dataType = "int"), @ApiImplicitParam(name = "collectId", value = "收藏id", paramType = "path", required = true, dataType = "int"), }) @GetMapping("/pull/{userId}/{collectId}") public ResponseResult getCollectWithId(@PathVariable int userId, @PathVariable int collectId) { List voList = collectService.getAllCollect(userId, collectId); if (voList == null) { return RestResultGenerator.genErrorResult("获取收藏数据失败"); } return RestResultGenerator.genResult(voList, "获取收藏数据成功"); } @ApiOperation("获取收藏数据,指定type") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", paramType = "path", required = true, dataType = "int"), @ApiImplicitParam(name = "collectId", value = "收藏id", paramType = "path", required = true, dataType = "int"), @ApiImplicitParam(name = "type", value = "收藏类型", paramType = "path", required = true, dataType = "int") }) @GetMapping("/pull/{userId}/{collectId}/{type}") public ResponseResult getCollectWithType(@PathVariable int userId, @PathVariable int collectId, @PathVariable int type) { List voList = collectService.getCollectWithType(userId, collectId, type); if (voList == null) { return RestResultGenerator.genErrorResult("获取收藏数据失败"); } return RestResultGenerator.genResult(voList, "获取收藏数据成功"); } @ApiOperation("取消收藏") @ApiImplicitParam(name = "collectId", value = "收藏id", paramType = "path", required = true, dataType = "int") @GetMapping("/cancel/{collectId}") public ResponseResult updateCollect(@PathVariable int collectId) { log.info("取消收藏,collectId: " + collectId); int result = collectService.cancelCollectWithId(collectId); if (result == 0) { return RestResultGenerator.genErrorResult("取消失败"); } else { return RestResultGenerator.genResult(collectId, "取消成功"); } } }