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 { /** * 封装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 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 findByItemIdAndUserIdPrivate(Integer itemId, Integer userId, Pageable pageable); }