|
|
@@ -0,0 +1,65 @@
|
|
|
+package nju.seec.helper.web.controller;
|
|
|
+
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import nju.seec.helper.logic.service.NoteService;
|
|
|
+import nju.seec.helper.logic.vo.NoteVO;
|
|
|
+import nju.seec.helper.util.enums.UserType;
|
|
|
+import nju.seec.helper.web.dto.NoteDTO;
|
|
|
+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/note")
|
|
|
+public class NoteController {
|
|
|
+ private final NoteService noteService;
|
|
|
+
|
|
|
+ public NoteController(NoteService noteService) {
|
|
|
+ this.noteService = noteService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping
|
|
|
+ public ResourceResponse<NoteVO> publishNote(Integer userId, String username, String userType, @RequestBody NoteDTO noteDTO) {
|
|
|
+ return ResourceResponse.of(noteService.create(userId, username, UserType.valueOf(userType), noteDTO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/item/{itemId}/public")
|
|
|
+ public PageResourceResponse<NoteVO> getPublicNotes(@PathVariable("itemId") Integer itemId,
|
|
|
+ @ApiParam(hidden = true) @PageableDefault(size = Integer.MAX_VALUE, sort = "publishTime", direction = Sort.Direction.DESC) Pageable pageable) {
|
|
|
+ List<NoteVO> notes = noteService.getPublicNotes(itemId, pageable);
|
|
|
+ return PageResourceResponse.of(notes, PageResourceResponse.PageInfo.of(pageable.getPageNumber(), notes.size()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/item/{itemId}/private")
|
|
|
+ public PageResourceResponse<NoteVO> getPrivateNotes(@PathVariable("itemId") Integer itemId,
|
|
|
+ Integer userId,
|
|
|
+ @ApiParam(hidden = true) @PageableDefault(size = Integer.MAX_VALUE, sort = "publishTime", direction = Sort.Direction.DESC) Pageable pageable) {
|
|
|
+ List<NoteVO> notes = noteService.getPrivateNotes(itemId, userId, pageable);
|
|
|
+ return PageResourceResponse.of(notes, PageResourceResponse.PageInfo.of(pageable.getPageNumber(), notes.size()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "根据ID获取笔记")
|
|
|
+ @GetMapping("/{noteId}")
|
|
|
+ public ResourceResponse<NoteVO> getNote(@PathVariable("noteId") Integer noteId,
|
|
|
+ Integer userId) {
|
|
|
+ return ResourceResponse.of(noteService.getNote(userId, noteId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/{noteId}")
|
|
|
+ public EmptyResponse deleteNote(@PathVariable("noteId") Integer noteId) {
|
|
|
+ noteService.deleteNote(noteId);
|
|
|
+ return EmptyResponse.getInstance();
|
|
|
+ }
|
|
|
+}
|