feat:更新朋友圈功能

This commit is contained in:
2025-06-25 19:56:09 +08:00
parent 5a29a2146e
commit a7119309a2
6 changed files with 34 additions and 14 deletions

View File

@@ -24,6 +24,13 @@ public class MomentController {
return momentService.addMoment(momentDto);
}
@Operation(summary = "更新朋友圈")
@PutMapping("/{id}")
public Boolean updateMoment(@PathVariable("id") long id,
@RequestBody @JsonView(WriteView.class) @Validated MomentDto momentDto) {
return momentService.updateMoment(id, momentDto);
}
@Operation(summary = "查询朋友圈")
@GetMapping("")
public @JsonView(ReadView.class) List<MomentDto> queryMoment() {
@@ -32,9 +39,9 @@ public class MomentController {
@Operation(summary = "新增评论")
@PostMapping("/{id}/comment")
public Boolean addMoment(@PathVariable("id") long id,
@RequestBody @JsonView(WriteView.class) @Validated CommentDto commentDto) {
return momentService.addComment(id, commentDto);
public Boolean addComment(@PathVariable("id") long id,
@RequestParam String content) {
return momentService.addComment(id, content);
}
}

View File

@@ -1,16 +1,16 @@
package com.cxx.food.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cxx.food.dto.*;
import com.cxx.food.vo.FoodQueryVo;
import java.util.List;
public interface MomentService {
Boolean addMoment(MomentDto momentDto);
Boolean updateMoment(Long id, MomentDto momentDto);
List<MomentDto> queryMoment();
Boolean addComment(Long momentId, CommentDto commentDto);
Boolean addComment(Long momentId, String content);
}

View File

@@ -33,6 +33,18 @@ public class MomentServiceImpl implements MomentService {
return momentMapper.insert(moment) == 1;
}
@Override
public Boolean updateMoment(Long id, MomentDto momentDto) {
if (momentMapper.selectById(id) == null) {
throw new CustomException("该朋友圈不存在");
}
Moment moment = new Moment();
BeanUtils.copyProperties(momentDto, moment);
moment.setId(id);
return momentMapper.updateById(moment) == 1;
}
@Override
public List<MomentDto> queryMoment() {
// TODO 只能查询好友的朋友圈
@@ -40,13 +52,13 @@ public class MomentServiceImpl implements MomentService {
}
@Override
public Boolean addComment(Long momentId, CommentDto commentDto) {
public Boolean addComment(Long momentId, String content) {
if (momentMapper.selectById(momentId) == null) {
throw new CustomException("该朋友圈不存在");
}
Comment comment = new Comment();
BeanUtils.copyProperties(commentDto, comment);
comment.setContent(content);
comment.setMomentId(momentId);
return commentMapper.insert(comment) == 1;
}