NoteDAO.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package nju.seec.helper.data.dao;
  2. import nju.seec.helper.data.entity.Note;
  3. import nju.seec.helper.util.exception.HelperException;
  4. import org.springframework.data.domain.Page;
  5. import org.springframework.data.domain.Pageable;
  6. import org.springframework.data.jpa.repository.JpaRepository;
  7. import org.springframework.data.jpa.repository.Query;
  8. import org.springframework.stereotype.Repository;
  9. /**
  10. * @author cst
  11. */
  12. @Repository
  13. public interface NoteDAO extends JpaRepository<Note, Integer> {
  14. /**
  15. * 封装findById
  16. *
  17. * @param noteId
  18. * @return
  19. */
  20. default Note findNoteById(Integer noteId) {
  21. return findById(noteId).orElseThrow(() -> HelperException.of(HelperException.ExceptionType.NOT_FOUND, "找不到评论"));
  22. }
  23. /**
  24. * 查询公开帖子
  25. *
  26. * @param itemId
  27. * @param pageable
  28. * @return
  29. */
  30. @Query("select n from Note n where n.itemId=?1 and n.type='PUBLIC'")
  31. Page<Note> findByItemIdPublic(Integer itemId, Pageable pageable);
  32. /**
  33. * 查询私人帖子
  34. *
  35. * @param itemId
  36. * @param userId
  37. * @param pageable
  38. * @return
  39. */
  40. @Query("select n from Note n where n.itemId=?1 and n.userId=?2 and n.type='PRIVATE'")
  41. Page<Note> findByItemIdAndUserIdPrivate(Integer itemId, Integer userId, Pageable pageable);
  42. }