修bug,顺便修改接口名

This commit is contained in:
KilLze
2025-12-28 02:17:09 +08:00
parent 4c70bd3c6f
commit dfc9508827
2 changed files with 9 additions and 10 deletions

View File

@@ -36,7 +36,7 @@ public class PostController {
* @param postDTO 动态信息
* @return 发布的动态对象
*/
@PostMapping(consumes = "application/json")
@PostMapping( "/addPost")
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
// 调用 Service 层处理发布动态业务逻辑
Post result = postService.createPost(postDTO);
@@ -49,7 +49,7 @@ public class PostController {
* @param postIds 动态ID
* @return 删除结果
*/
@DeleteMapping
@PostMapping("/deletePost")
public Result<String> deleteById(@RequestParam List<Long> postIds){
int deletedCount = postService.deletePostById(postIds);
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
@@ -60,7 +60,7 @@ public class PostController {
* @param postId 动态ID
* @return 动态对象
*/
@GetMapping("/{postId}")
@PostMapping("/postById/{postId}")
public Result<PostEditVO> getPostById(@PathVariable Long postId) {
PostEditVO postEditVO = postService.getPostForEdit(postId);
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
@@ -72,7 +72,7 @@ public class PostController {
* @param postRequestDTO 动态信息
* @return 更新后的动态对象
*/
@PutMapping("/{postId}")
@PostMapping("/updatePost/{postId}")
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
PostEditVO result = postService.updatePost(postId, postRequestDTO);
return Result.success(ResultCode.SUCCESS_REVIEW, "动态更新成功", result);

View File

@@ -225,9 +225,8 @@ public class PostServiceImpl implements PostService {
throw new RuntimeException("无权限修改此动态");
}
post.setContent(postRequestDTO.getContent());
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
}
// 如果请求中的mediaOssKeys不为null即使是空列表则更新为新值
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
// 1. 文本内容审核
Map textResult;
@@ -239,11 +238,11 @@ public class PostServiceImpl implements PostService {
// 文本审核结果
String textSuggestion = (String) textResult.get("suggestion");
// 2. 图片审核(如果有)
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
// 2. 图片审核(如果有媒体文件
if (post.getMediaOssKeys() != null && !post.getMediaOssKeys().isEmpty()) {
Map imageResult;
try {
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaOssKeys());
imageResult = greenImageScan.imageScan(post.getMediaOssKeys());
} catch (Exception e) {
throw new RuntimeException(e);
}