| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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);
- }
|