71 lines
2.3 KiB
Java
71 lines
2.3 KiB
Java
package com.cxx.food.controller;
|
|
|
|
import com.cxx.food.dto.*;
|
|
import com.cxx.food.service.MomentService;
|
|
import com.fasterxml.jackson.annotation.JsonView;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping("/moment")
|
|
@Tag(name = "美食朋友圈")
|
|
public class MomentController {
|
|
@Resource
|
|
private MomentService momentService;
|
|
|
|
@Operation(summary = "新增朋友圈")
|
|
@PostMapping("")
|
|
public Boolean addMoment(@RequestBody @JsonView(WriteView.class) @Validated MomentDto momentDto) {
|
|
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 = "删除朋友圈")
|
|
@DeleteMapping("/{id}")
|
|
public Boolean deleteMoment(@PathVariable("id") long id) {
|
|
return momentService.deleteMoment(id);
|
|
}
|
|
|
|
@Operation(summary = "查询所有朋友圈")
|
|
@GetMapping("")
|
|
public @JsonView(ReadView.class) List<MomentDto> queryMomentList() {
|
|
return momentService.queryMomentList();
|
|
}
|
|
|
|
@Operation(summary = "查询朋友圈")
|
|
@GetMapping("/{id}")
|
|
public @JsonView(ReadView.class) List<MomentDto> queryMomentById(@PathVariable("id") long id) {
|
|
return momentService.queryMomentById(id);
|
|
}
|
|
|
|
@Operation(summary = "新增评论")
|
|
@PostMapping("/{id}/comment")
|
|
public Boolean addComment(@PathVariable("id") long id,
|
|
@RequestParam String content) {
|
|
return momentService.addComment(id, content);
|
|
}
|
|
|
|
@Operation(summary = "增加点赞")
|
|
@PostMapping("/{id}/like")
|
|
public Boolean addLike(@PathVariable("id") long id) {
|
|
return momentService.addLike(id);
|
|
}
|
|
|
|
@Operation(summary = "取消点赞")
|
|
@DeleteMapping("/{id}/like")
|
|
public Boolean deleteLike(@PathVariable("id") long id) {
|
|
return momentService.deleteLike(id);
|
|
}
|
|
}
|
|
|