90 lines
2.8 KiB
Java
90 lines
2.8 KiB
Java
package com.bao.dating.controller;
|
|
|
|
|
|
import com.bao.dating.anno.Log;
|
|
import com.bao.dating.common.Result;
|
|
import com.bao.dating.common.ResultCode;
|
|
import com.bao.dating.pojo.dto.PostRequestDTO;
|
|
import com.bao.dating.pojo.entity.Post;
|
|
import com.bao.dating.pojo.vo.PostEditVO;
|
|
import com.bao.dating.service.PostService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 动态接口
|
|
*
|
|
* @author KilLze
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/posts")
|
|
public class PostController {
|
|
|
|
@Autowired
|
|
private PostService postService;
|
|
|
|
/**
|
|
* 上传媒体文件接口 like
|
|
* @param files 媒体文件数组
|
|
* @return 上传后的文件URL列表
|
|
*/
|
|
@Log
|
|
@PostMapping(value = "/upload", consumes = "multipart/form-data")
|
|
public Result<List<String>> uploadMedia(@RequestParam("files") MultipartFile[] files) {
|
|
List<String> fileUrls = postService.uploadMedia(files);
|
|
return Result.success(ResultCode.SUCCESS, "文件上传成功", fileUrls);
|
|
}
|
|
|
|
/**
|
|
* 发布动态接口 - JSON格式请求
|
|
* @param postDTO 动态信息
|
|
* @return 发布的动态对象
|
|
*/
|
|
@Log
|
|
@PostMapping( "/createPost")
|
|
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
|
// 调用 Service 层处理发布动态业务逻辑
|
|
Post result = postService.createPost(postDTO);
|
|
return Result.success(ResultCode.SUCCESS, "动态发布成功,等待审核。", result);
|
|
}
|
|
|
|
/**
|
|
* 批量删除动态
|
|
*
|
|
* @param postIds 动态ID
|
|
* @return 删除结果
|
|
*/
|
|
@Log
|
|
@PostMapping("/deletePost")
|
|
public Result<String> deleteById(@RequestBody List<Long> postIds){
|
|
int deletedCount = postService.deletePostById(postIds);
|
|
return Result.success(ResultCode.SUCCESS_DELETE, "成功删除" + deletedCount + "条动态", null);
|
|
}
|
|
|
|
/**
|
|
* 根据ID查询动态接口
|
|
* @param postId 动态ID
|
|
* @return 动态对象
|
|
*/
|
|
@GetMapping("/{postId}")
|
|
public Result<PostEditVO> getPostById(@PathVariable Long postId) {
|
|
PostEditVO postEditVO = postService.getPostForEdit(postId);
|
|
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
|
|
}
|
|
|
|
/**
|
|
* 更新动态接口
|
|
* @param postId 动态ID
|
|
* @param postRequestDTO 动态信息
|
|
* @return 更新后的动态对象
|
|
*/
|
|
@Log
|
|
@PostMapping("/{postId}/updatePost")
|
|
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
|
|
PostEditVO result = postService.updatePost(postId, postRequestDTO);
|
|
return Result.success(ResultCode.SUCCESS, "动态更新成功", result);
|
|
}
|
|
} |