|
|
@@ -0,0 +1,54 @@
|
|
|
+package nju.seec.helper.web.controller;
|
|
|
+
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import nju.seec.helper.logic.service.CommentService;
|
|
|
+import nju.seec.helper.logic.vo.CommentVO;
|
|
|
+import nju.seec.helper.util.enums.UserType;
|
|
|
+import nju.seec.helper.web.dto.CommentDTO;
|
|
|
+import nju.seec.helper.web.response.EmptyResponse;
|
|
|
+import nju.seec.helper.web.response.PageResourceResponse;
|
|
|
+import nju.seec.helper.web.response.ResourceResponse;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.web.PageableDefault;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author cst
|
|
|
+ */
|
|
|
+@Api(tags = "评论")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/comment")
|
|
|
+public class CommentController {
|
|
|
+ private final CommentService commentService;
|
|
|
+
|
|
|
+ public CommentController(CommentService commentService) {
|
|
|
+ this.commentService = commentService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/teacher")
|
|
|
+ public ResourceResponse<CommentVO> teacherComment(@RequestBody CommentDTO commentDTO) {
|
|
|
+ return ResourceResponse.of(commentService.create(1, "teacher", UserType.TEACHER, commentDTO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/student")
|
|
|
+ public ResourceResponse<CommentVO> studentComment(@RequestBody CommentDTO commentDTO) {
|
|
|
+ return ResourceResponse.of(commentService.create(1, "student", UserType.STUDENT, commentDTO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/item/{itemId}")
|
|
|
+ public PageResourceResponse<CommentVO> getComments(@PathVariable("itemId") Integer itemId,
|
|
|
+ @ApiParam(hidden = true) @PageableDefault(size = Integer.MAX_VALUE, sort = "publishTime", direction = Sort.Direction.DESC) Pageable pageable) {
|
|
|
+ List<CommentVO> comments = commentService.getComments(itemId, pageable);
|
|
|
+ return PageResourceResponse.of(comments, PageResourceResponse.PageInfo.of(pageable.getPageNumber(), comments.size()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/{commentId}")
|
|
|
+ public EmptyResponse deleteComment(@PathVariable("commentId") Integer commentId) {
|
|
|
+ commentService.deleteComment(commentId);
|
|
|
+ return EmptyResponse.getInstance();
|
|
|
+ }
|
|
|
+}
|