package com.zhujizheng.IHome.privatespace.controller; import com.zhujizheng.IHome.privatespace.dto.PYPrivacySpaceDTO; import com.zhujizheng.IHome.privatespace.dto.PYPrivacySpaceUpdateDTO; import com.zhujizheng.IHome.privatespace.service.PYPrivacySpaceService; import com.zhujizheng.IHome.privatespace.vo.PYPrivacySpaceVO; 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; @Api("私密空间相关") @RestController @RequestMapping("/privacyspace") @Slf4j public class PYPrivacySpaceController { @Autowired private PYPrivacySpaceService privacySpaceService; @ApiOperation("添加文件") @ApiImplicitParam(name = "pushDTO", value = "私密空间数据", required = true, dataType = "PYPrivacySpaceDTO") @PostMapping("/push") public ResponseResult addFile(@Validated @RequestBody PYPrivacySpaceDTO pushDTO) { System.out.println("pushDTO = " + pushDTO); PYPrivacySpaceVO vo = privacySpaceService.addFile(pushDTO); if (vo == null) { return RestResultGenerator.genErrorResult("添加失败"); } else { return RestResultGenerator.genResult(vo, "添加成功"); } } @ApiOperation("修改文件") @ApiImplicitParam(name = "updateDTO", value = "私密空间数据", required = true, dataType = "PYPrivacySpaceUpdateDTO") @PostMapping("/update") public ResponseResult updateFile(@Validated @RequestBody PYPrivacySpaceUpdateDTO updateDTO) { System.out.println("updateDTO = " + updateDTO); PYPrivacySpaceVO vo = privacySpaceService.updateFile(updateDTO); 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 = "folderId", value = "文件夹id", paramType = "path", required = true, dataType = "int"), @ApiImplicitParam(name = "psId", value = "文件id", paramType = "path", required = true, dataType = "int"), }) @GetMapping("/pull/{userId}/{folderId}/{psId}") public ResponseResult getCollectWithId(@PathVariable int userId, @PathVariable int folderId, @PathVariable int psId) { List voList = privacySpaceService.getFiles(userId, folderId, psId); 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 = "folderId", value = "文件夹id", paramType = "path", required = true, dataType = "int"), @ApiImplicitParam(name = "psId", value = "文件id", paramType = "path", required = true, dataType = "int"), @ApiImplicitParam(name = "type", value = "文件类型", paramType = "path", required = true, dataType = "int") }) @GetMapping("/pull/{userId}/{folderId}/{psId}/{type}") public ResponseResult getCollectWithType(@PathVariable int userId, @PathVariable int folderId, @PathVariable int psId, @PathVariable int type) { List voList = privacySpaceService.getFilesWithType(userId, folderId, psId, type); if (voList == null) { return RestResultGenerator.genErrorResult("获取失败"); } return RestResultGenerator.genResult(voList, "获取成功"); } @ApiOperation("删除文件") @ApiImplicitParam(name = "psId", value = "文件id", paramType = "path", required = true, dataType = "int") @GetMapping("/delete/{psId}") public ResponseResult deleteFile(@PathVariable int psId) { log.info("删除文件,psId: " + psId); int result = privacySpaceService.deleteFile(psId); if (result == 0) { return RestResultGenerator.genErrorResult("删除失败"); } else { return RestResultGenerator.genResult(psId, "删除成功"); } } }