Kaynağa Gözat

improvement: 增加私有笔记功能(原评论功能)

ChenSiTong 6 yıl önce
ebeveyn
işleme
e5d1f95679

+ 4 - 0
src/main/java/nju/seec/helper/HelperApplication.java

@@ -2,13 +2,17 @@ package nju.seec.helper;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 /**
  * @author cst
  */
 @SpringBootApplication
 @EnableJpaRepositories(basePackages = "nju.seec.helper.data.dao")
+@EnableCaching
+@EnableTransactionManagement
 public class HelperApplication {
 
     public static void main(String[] args) {

+ 0 - 43
src/main/java/nju/seec/helper/data/dao/CommentDAO.java

@@ -1,43 +0,0 @@
-package nju.seec.helper.data.dao;
-
-import nju.seec.helper.data.entity.Comment;
-import nju.seec.helper.util.exception.HelperException;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-import java.util.List;
-
-/**
- * @author cst
- */
-@Repository
-public interface CommentDAO extends JpaRepository<Comment, Integer> {
-    /**
-     * 封装findById
-     *
-     * @param commentId
-     * @return
-     */
-    default Comment findCommentById(Integer commentId) {
-        return findById(commentId).orElseThrow(() -> HelperException.of(HelperException.ExceptionType.NOT_FOUND, "找不到评论"));
-    }
-
-    /**
-     * 根据Item ID查询
-     *
-     * @param itemId
-     * @param pageable
-     * @return
-     */
-    Page<Comment> findByItemIdAndFatherCommentIsNull(Integer itemId, Pageable pageable);
-
-    /**
-     * 子贴
-     *
-     * @param comment
-     * @return
-     */
-    List<Comment> findByFatherCommentOrderByPublishTimeAsc(Comment comment);
-}

+ 46 - 0
src/main/java/nju/seec/helper/data/dao/NoteDAO.java

@@ -0,0 +1,46 @@
+package nju.seec.helper.data.dao;
+
+import nju.seec.helper.data.entity.Note;
+import nju.seec.helper.util.exception.HelperException;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author cst
+ */
+@Repository
+public interface NoteDAO extends JpaRepository<Note, Integer> {
+    /**
+     * 封装findById
+     *
+     * @param noteId
+     * @return
+     */
+    default Note findNoteById(Integer noteId) {
+        return findById(noteId).orElseThrow(() -> HelperException.of(HelperException.ExceptionType.NOT_FOUND, "找不到评论"));
+    }
+
+    /**
+     * 查询公开帖子
+     *
+     * @param itemId
+     * @param pageable
+     * @return
+     */
+    @Query("select n from Note n where n.itemId=?1 and n.type='PUBLIC'")
+    Page<Note> findByItemIdPublic(Integer itemId, Pageable pageable);
+
+    /**
+     * 查询私人帖子
+     *
+     * @param itemId
+     * @param userId
+     * @param pageable
+     * @return
+     */
+    @Query("select n from Note n where n.itemId=?1 and n.userId=?2 and n.type='PRIVATE'")
+    Page<Note> findByItemIdAndUserIdPrivate(Integer itemId, Integer userId, Pageable pageable);
+}

+ 8 - 5
src/main/java/nju/seec/helper/data/entity/Comment.java → src/main/java/nju/seec/helper/data/entity/Note.java

@@ -1,6 +1,7 @@
 package nju.seec.helper.data.entity;
 
 import lombok.Data;
+import nju.seec.helper.util.enums.NoteType;
 import nju.seec.helper.util.enums.UserType;
 import org.hibernate.annotations.CreationTimestamp;
 
@@ -12,8 +13,8 @@ import java.time.LocalDateTime;
  */
 @Data
 @Entity
-@Table(name = "comment")
-public class Comment {
+@Table(name = "note")
+public class Note {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     private Integer id;
@@ -31,13 +32,15 @@ public class Comment {
     @Column(name = "user_type")
     private UserType userType;
 
+    @Enumerated(EnumType.STRING)
+    private NoteType type;
+
     private String content;
 
     @Column(name = "publish_time", updatable = false)
     @CreationTimestamp
     private LocalDateTime publishTime;
 
-    @ManyToOne
-    @JoinColumn(name = "father_comment_id")
-    private Comment fatherComment;
+    @Column(name = "reference_note_id")
+    private Integer referenceNoteId;
 }

+ 0 - 40
src/main/java/nju/seec/helper/logic/service/CommentService.java

@@ -1,40 +0,0 @@
-package nju.seec.helper.logic.service;
-
-import nju.seec.helper.logic.vo.CommentVO;
-import nju.seec.helper.util.enums.UserType;
-import nju.seec.helper.web.dto.CommentDTO;
-import org.springframework.data.domain.Pageable;
-
-import java.util.List;
-
-/**
- * @author cst
- */
-public interface CommentService {
-    /**
-     * 发布评论
-     *
-     * @param userId
-     * @param username
-     * @param userType
-     * @param commentDTO
-     * @return
-     */
-    CommentVO create(Integer userId, String username, UserType userType, CommentDTO commentDTO);
-
-    /**
-     * 获取评论
-     *
-     * @param itemId
-     * @param pageable
-     * @return
-     */
-    List<CommentVO> getComments(Integer itemId, Pageable pageable);
-
-    /**
-     * 删除评论
-     *
-     * @param commentId
-     */
-    void deleteComment(Integer commentId);
-}

+ 59 - 0
src/main/java/nju/seec/helper/logic/service/NoteService.java

@@ -0,0 +1,59 @@
+package nju.seec.helper.logic.service;
+
+import nju.seec.helper.logic.vo.NoteVO;
+import nju.seec.helper.util.enums.UserType;
+import nju.seec.helper.web.dto.NoteDTO;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+/**
+ * @author cst
+ */
+public interface NoteService {
+    /**
+     * 发布评论
+     *
+     * @param userId
+     * @param username
+     * @param userType
+     * @param noteDTO
+     * @return
+     */
+    NoteVO create(Integer userId, String username, UserType userType, NoteDTO noteDTO);
+
+    /**
+     * 获取公开评论
+     *
+     * @param itemId
+     * @param pageable
+     * @return
+     */
+    List<NoteVO> getPublicNotes(Integer itemId, Pageable pageable);
+
+    /**
+     * 获取私有评论
+     *
+     * @param userId
+     * @param itemId
+     * @param pageable
+     * @return
+     */
+    List<NoteVO> getPrivateNotes(Integer userId, Integer itemId, Pageable pageable);
+
+    /**
+     * 获取评论
+     *
+     * @param userId
+     * @param noteId
+     * @return
+     */
+    NoteVO getNote(Integer userId, Integer noteId);
+
+    /**
+     * 删除评论
+     *
+     * @param noteId
+     */
+    void deleteNote(Integer noteId);
+}

+ 0 - 70
src/main/java/nju/seec/helper/logic/service/impl/CommentServiceImpl.java

@@ -1,70 +0,0 @@
-package nju.seec.helper.logic.service.impl;
-
-import nju.seec.helper.data.dao.CommentDAO;
-import nju.seec.helper.data.entity.Comment;
-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 org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * @author cst
- */
-@Service
-public class CommentServiceImpl implements CommentService {
-    private final CommentDAO commentDAO;
-
-    public CommentServiceImpl(CommentDAO commentDAO) {
-        this.commentDAO = commentDAO;
-    }
-
-    @Override
-    public CommentVO create(Integer userId, String username, UserType userType, CommentDTO commentDTO) {
-        Comment comment = new Comment();
-        comment.setUserId(userId);
-        comment.setUsername(username);
-        comment.setUserType(userType);
-        comment.setItemId(commentDTO.getItemId());
-        comment.setContent(commentDTO.getContent());
-
-        Integer fatherCommentId = commentDTO.getFatherCommentId();
-
-        if (fatherCommentId != null && fatherCommentId > 0) {
-            Comment fatherComment = commentDAO.findCommentById(fatherCommentId);
-            comment.setFatherComment(fatherComment);
-        }
-        comment = commentDAO.save(comment);
-        return new CommentVO(comment);
-    }
-
-    @Override
-    public List<CommentVO> getComments(Integer itemId, Pageable pageable) {
-        Page<Comment> commentPage = commentDAO.findByItemIdAndFatherCommentIsNull(itemId, pageable);
-        List<Comment> comments = commentPage.getContent();
-        return comments
-                .stream()
-                .map(this::getCommentVO)
-                .collect(Collectors.toList());
-    }
-
-    private CommentVO getCommentVO(Comment comment) {
-        List<Comment> childComments = commentDAO.findByFatherCommentOrderByPublishTimeAsc(comment);
-        return new CommentVO(
-                comment, childComments
-                .stream()
-                .map(this::getCommentVO)
-                .collect(Collectors.toList())
-        );
-    }
-
-    @Override
-    public void deleteComment(Integer commentId) {
-        commentDAO.deleteById(commentId);
-    }
-}

+ 2 - 4
src/main/java/nju/seec/helper/logic/service/impl/CourseServiceImpl.java

@@ -1,10 +1,8 @@
 package nju.seec.helper.logic.service.impl;
 
 import nju.seec.helper.data.dao.CourseDAO;
-import nju.seec.helper.data.entity.Course;
 import nju.seec.helper.logic.service.CourseService;
 import nju.seec.helper.logic.vo.CourseVO;
-import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
@@ -26,8 +24,8 @@ public class CourseServiceImpl implements CourseService {
     @Override
     public List<CourseVO> getTeacherCourses(Integer teacherId, Pageable pageable) {
         // TODO
-        Page<Course> page = courseDAO.findByTeacherId(teacherId, pageable);
-        return page
+        return courseDAO
+                .findByTeacherId(teacherId, pageable)
                 .getContent()
                 .stream()
                 .map(CourseVO::new)

+ 81 - 0
src/main/java/nju/seec/helper/logic/service/impl/NoteServiceImpl.java

@@ -0,0 +1,81 @@
+package nju.seec.helper.logic.service.impl;
+
+import nju.seec.helper.data.dao.NoteDAO;
+import nju.seec.helper.data.entity.Note;
+import nju.seec.helper.logic.service.NoteService;
+import nju.seec.helper.logic.vo.NoteVO;
+import nju.seec.helper.util.enums.NoteType;
+import nju.seec.helper.util.enums.UserType;
+import nju.seec.helper.web.dto.NoteDTO;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author cst
+ */
+@Service
+public class NoteServiceImpl implements NoteService {
+    private final NoteDAO noteDAO;
+
+    public NoteServiceImpl(NoteDAO noteDAO) {
+        this.noteDAO = noteDAO;
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public NoteVO create(Integer userId, String username, UserType userType, NoteDTO noteDTO) {
+        Note note = new Note();
+        note.setUserId(userId);
+        note.setUsername(username);
+        note.setUserType(userType);
+        note.setItemId(noteDTO.getItemId());
+        note.setType(noteDTO.getType());
+        note.setContent(noteDTO.getContent());
+        note.setReferenceNoteId(noteDTO.getReferenceNoteId());
+        note = noteDAO.save(note);
+        return new NoteVO(note);
+    }
+
+    @Transactional(readOnly = true)
+    @Override
+    public List<NoteVO> getPublicNotes(Integer itemId, Pageable pageable) {
+        return noteDAO
+                .findByItemIdPublic(itemId, pageable)
+                .getContent()
+                .stream()
+                .map(NoteVO::new)
+                .collect(Collectors.toList());
+    }
+
+    @Transactional(readOnly = true)
+    @Override
+    public List<NoteVO> getPrivateNotes(Integer userId, Integer itemId, Pageable pageable) {
+        return noteDAO
+                .findByItemIdAndUserIdPrivate(itemId, userId, pageable)
+                .getContent()
+                .stream()
+                .map(NoteVO::new)
+                .collect(Collectors.toList());
+    }
+
+    @Transactional(readOnly = true)
+    @Override
+    public NoteVO getNote(Integer userId, Integer noteId) {
+        Note note = noteDAO.findNoteById(noteId);
+        if (note.getType() != NoteType.PUBLIC && !note.getUserId().equals(userId)) {
+            return null;
+        } else {
+            return new NoteVO(note);
+        }
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void deleteNote(Integer noteId) {
+        noteDAO.deleteById(noteId);
+    }
+}

+ 2 - 3
src/main/java/nju/seec/helper/logic/service/impl/QuestionServiceImpl.java

@@ -1,7 +1,6 @@
 package nju.seec.helper.logic.service.impl;
 
 import nju.seec.helper.data.dao.QuestionDAO;
-import nju.seec.helper.data.entity.Question;
 import nju.seec.helper.logic.service.QuestionService;
 import nju.seec.helper.logic.vo.QuestionVO;
 import org.springframework.stereotype.Service;
@@ -22,8 +21,8 @@ public class QuestionServiceImpl implements QuestionService {
 
     @Override
     public List<QuestionVO> getQuestions(String key) {
-        List<Question> questions = questionDAO.findByStemContains(key);
-        return questions
+        return questionDAO
+                .findByStemContains(key)
                 .stream()
                 .map(QuestionVO::new)
                 .collect(Collectors.toList());

+ 10 - 5
src/main/java/nju/seec/helper/logic/service/impl/QuizServiceImpl.java

@@ -43,7 +43,8 @@ public class QuizServiceImpl implements QuizService {
                 .stream()
                 .map(questionDAO::findQuestionById)
                 .collect(Collectors.toList());
-        Quiz quiz = quizDAO.findBySlideIdAndType(quizDTO.getSlideId(), quizDTO.getType())
+        Quiz quiz = quizDAO
+                .findBySlideIdAndType(quizDTO.getSlideId(), quizDTO.getType())
                 .orElseGet(() -> {
                     Quiz newQuiz = new Quiz();
                     newQuiz.setSlideId(quizDTO.getSlideId());
@@ -57,7 +58,8 @@ public class QuizServiceImpl implements QuizService {
 
     @Override
     public QuizVO teacherGetQuiz(int slideId, QuizType quizType) {
-        return quizDAO.findBySlideIdAndType(slideId, quizType)
+        return quizDAO
+                .findBySlideIdAndType(slideId, quizType)
                 .map(QuizVO::new)
                 .orElseThrow(() -> HelperException.of(HelperException.ExceptionType.NOT_FOUND, "找不到测验"));
     }
@@ -87,16 +89,19 @@ public class QuizServiceImpl implements QuizService {
 //                break;
 //        }
 
-        Quiz quiz = quizDAO.findBySlideIdAndType(slideId, quizType)
+        Quiz quiz = quizDAO
+                .findBySlideIdAndType(slideId, quizType)
                 .orElseThrow(() -> HelperException.of(HelperException.ExceptionType.NOT_FOUND, "找不到测验"));
-        return submitAnswerDAO.findByQuizIdAndStudentId(quiz.getId(), 1)
+        return submitAnswerDAO
+                .findByQuizIdAndStudentId(quiz.getId(), 1)
                 .map(submitAnswer -> new StudentQuizVO(quiz, submitAnswer))
                 .orElseGet(() -> new StudentQuizVO(quiz));
     }
 
     @Override
     public void answerQuiz(Integer studentId, SubmitAnswerDTO submitAnswerDTO) {
-        SubmitAnswer submitAnswer = submitAnswerDAO.findByQuizIdAndStudentId(submitAnswerDTO.getQuizId(), studentId)
+        SubmitAnswer submitAnswer = submitAnswerDAO
+                .findByQuizIdAndStudentId(submitAnswerDTO.getQuizId(), studentId)
                 .orElse(new SubmitAnswer());
         Integer submitNum = submitAnswer.getSubmitNum();
         submitAnswer.setSubmitNum((submitNum == null ? 0 : submitNum) + 1);

+ 8 - 10
src/main/java/nju/seec/helper/logic/service/impl/SlideServiceImpl.java

@@ -11,7 +11,6 @@ import nju.seec.helper.util.enums.SlideState;
 import nju.seec.helper.util.exception.HelperException;
 import nju.seec.helper.web.dto.SlideDTO;
 import org.springframework.beans.BeanUtils;
-import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
@@ -34,9 +33,8 @@ public class SlideServiceImpl implements SlideService {
 
     @Override
     public List<SlideVO> teacherGetSlides(Integer teacherId, Integer courseId, String key, Pageable pageable) {
-        Page<Slide> slidePage = slideDAO.findByTeacherIdAndCourseIdAndNameContains(teacherId, courseId, key, pageable);
-
-        return slidePage
+        return slideDAO
+                .findByTeacherIdAndCourseIdAndNameContains(teacherId, courseId, key, pageable)
                 .getContent()
                 .stream()
                 .map(SlideVO::new)
@@ -45,9 +43,8 @@ public class SlideServiceImpl implements SlideService {
 
     @Override
     public List<SlideVO> teacherGetSlides(Integer teacherId, String key, Pageable pageable) {
-        Page<Slide> slidePage = slideDAO.findByTeacherIdAndNameContains(teacherId, key, pageable);
-
-        return slidePage
+        return slideDAO
+                .findByTeacherIdAndNameContains(teacherId, key, pageable)
                 .getContent()
                 .stream()
                 .map(SlideVO::new)
@@ -95,7 +92,8 @@ public class SlideServiceImpl implements SlideService {
         slide.setState(slideDTO.getState());
         slide.setName(slideDTO.getName());
         slide.setItems(
-                slideDTO.getItems()
+                slideDTO
+                        .getItems()
                         .stream()
                         .map(itemDTO -> {
                             Item item = new Item();
@@ -130,8 +128,8 @@ public class SlideServiceImpl implements SlideService {
 
     @Override
     public List<SlideVO> studentGetSlides(Integer studentId, Integer courseId, String key, Pageable pageable) {
-        Page<Slide> slidePage = slideDAO.findByCourseIdAndStateNotInAndNameContains(courseId, Collections.singleton(SlideState.DRAFT), key, pageable);
-        return slidePage
+        return slideDAO
+                .findByCourseIdAndStateNotInAndNameContains(courseId, Collections.singleton(SlideState.DRAFT), key, pageable)
                 .getContent()
                 .stream()
                 .map(SlideVO::new)

+ 0 - 53
src/main/java/nju/seec/helper/logic/vo/CommentVO.java

@@ -1,53 +0,0 @@
-package nju.seec.helper.logic.vo;
-
-import lombok.Data;
-import nju.seec.helper.data.entity.Comment;
-import nju.seec.helper.util.enums.UserType;
-
-import java.time.LocalDateTime;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author cst
- */
-@Data
-public class CommentVO {
-    private Integer id;
-
-    private Integer itemId;
-
-    private Integer userId;
-
-    private String username;
-
-    private UserType userType;
-
-    private String content;
-
-    private LocalDateTime publishTime;
-
-    private List<CommentVO> followComments;
-
-    public CommentVO(Comment comment) {
-        this.id = comment.getId();
-        this.itemId = comment.getItemId();
-        this.userId = comment.getUserId();
-        this.username = comment.getUsername();
-        this.userType = comment.getUserType();
-        this.content = comment.getContent();
-        this.publishTime = comment.getPublishTime();
-        this.followComments = Collections.emptyList();
-    }
-
-    public CommentVO(Comment comment, List<CommentVO> comments) {
-        this.id = comment.getId();
-        this.itemId = comment.getItemId();
-        this.userId = comment.getUserId();
-        this.username = comment.getUsername();
-        this.userType = comment.getUserType();
-        this.content = comment.getContent();
-        this.publishTime = comment.getPublishTime();
-        this.followComments = comments;
-    }
-}

+ 36 - 0
src/main/java/nju/seec/helper/logic/vo/NoteVO.java

@@ -0,0 +1,36 @@
+package nju.seec.helper.logic.vo;
+
+import lombok.Data;
+import nju.seec.helper.data.entity.Note;
+import nju.seec.helper.util.enums.NoteType;
+import nju.seec.helper.util.enums.UserType;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author cst
+ */
+@Data
+public class NoteVO {
+    private Integer id;
+    private Integer itemId;
+    private Integer userId;
+    private String username;
+    private UserType userType;
+    private String content;
+    private NoteType type;
+    private LocalDateTime publishTime;
+    private Integer referenceNoteId;
+
+    public NoteVO(Note note) {
+        this.id = note.getId();
+        this.itemId = note.getItemId();
+        this.userId = note.getUserId();
+        this.username = note.getUsername();
+        this.userType = note.getUserType();
+        this.content = note.getContent();
+        this.type = note.getType();
+        this.publishTime = note.getPublishTime();
+        this.referenceNoteId = note.getReferenceNoteId();
+    }
+}

+ 8 - 0
src/main/java/nju/seec/helper/util/enums/NoteType.java

@@ -0,0 +1,8 @@
+package nju.seec.helper.util.enums;
+
+/**
+ * @author cst
+ */
+public enum NoteType {
+    PUBLIC, PRIVATE
+}

+ 0 - 54
src/main/java/nju/seec/helper/web/controller/CommentController.java

@@ -1,54 +0,0 @@
-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();
-    }
-}

+ 65 - 0
src/main/java/nju/seec/helper/web/controller/NoteController.java

@@ -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();
+    }
+}

+ 4 - 4
src/main/java/nju/seec/helper/web/controller/SlideController.java

@@ -21,7 +21,7 @@ import java.util.List;
 /**
  * @author cst
  */
-@Api(tags = "幻灯片")
+@Api(tags = "幻灯片(由于无登录功能,故用户信息暂时通过参数传入)")
 @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
 @RestController
 @RequestMapping("/api/slide")
@@ -87,13 +87,13 @@ public class SlideController {
     public PageResourceResponse<SlideVO> studentGetSlides(@PathVariable Integer courseId,
                                                           @RequestParam(required = false, defaultValue = "") String key,
                                                           @ApiParam(hidden = true) @PageableDefault(size = Integer.MAX_VALUE, sort = "updateTime", direction = Sort.Direction.DESC) Pageable pageable) {
-        List<SlideVO> slideVOs = slideService.studentGetSlides(1, courseId, key, pageable);
-        return PageResourceResponse.of(slideVOs, PageResourceResponse.PageInfo.of(pageable.getPageNumber(), slideVOs.size()));
+        List<SlideVO> slides = slideService.studentGetSlides(2, courseId, key, pageable);
+        return PageResourceResponse.of(slides, PageResourceResponse.PageInfo.of(pageable.getPageNumber(), slides.size()));
     }
 
     @ApiOperation(value = "学生根据ID获取幻灯片")
     @GetMapping("/student/{slideId:\\d+}")
     public ResourceResponse<SlideVO> studentGetSlide(@PathVariable("slideId") int slideId) {
-        return ResourceResponse.of(slideService.studentGetOneSlide(1, slideId));
+        return ResourceResponse.of(slideService.studentGetOneSlide(2, slideId));
     }
 }

+ 4 - 2
src/main/java/nju/seec/helper/web/dto/CommentDTO.java → src/main/java/nju/seec/helper/web/dto/NoteDTO.java

@@ -1,6 +1,7 @@
 package nju.seec.helper.web.dto;
 
 import lombok.Data;
+import nju.seec.helper.util.enums.NoteType;
 
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
@@ -9,10 +10,11 @@ import javax.validation.constraints.NotNull;
  * @author cst
  */
 @Data
-public class CommentDTO {
+public class NoteDTO {
     @NotNull
     private Integer itemId;
-    private Integer fatherCommentId;
+    private Integer referenceNoteId;
     @NotBlank
     private String content;
+    private NoteType type;
 }