diff --git a/src/main/java/com/tiki/server/note/adapter/NoteFinder.java b/src/main/java/com/tiki/server/note/adapter/NoteFinder.java index 97e2b44a..0cf4c97e 100644 --- a/src/main/java/com/tiki/server/note/adapter/NoteFinder.java +++ b/src/main/java/com/tiki/server/note/adapter/NoteFinder.java @@ -18,12 +18,20 @@ public class NoteFinder { private final NoteRepository noteRepository; - public List findByCreatedAtBeforeOrderByModifiedAtDesc(final LocalDateTime createdAt, final PageRequest pageRequest) { - return noteRepository.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageRequest); + public List findByCreatedAtBeforeOrderByModifiedAtDesc( + final LocalDateTime createdAt, + final PageRequest pageRequest, + final long teamId + ) { + return noteRepository.findByTeamIdAndCreatedAtBeforeOrderByCreatedDesc(createdAt, pageRequest, teamId); } - public List findByCreatedAtAfterOrderByModifiedAtAsc(final LocalDateTime createdAt, final PageRequest pageRequest) { - return noteRepository.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageRequest); + public List findByCreatedAtAfterOrderByModifiedAtAsc( + final LocalDateTime createdAt, + final PageRequest pageRequest, + final long teamId + ) { + return noteRepository.findByTeamIdAndCreatedAtAfterOrderByCreatedAtAsc(createdAt, pageRequest, teamId); } public Note findById(final long noteId) { diff --git a/src/main/java/com/tiki/server/note/repository/NoteRepository.java b/src/main/java/com/tiki/server/note/repository/NoteRepository.java index 46a7804e..67c1fbdf 100644 --- a/src/main/java/com/tiki/server/note/repository/NoteRepository.java +++ b/src/main/java/com/tiki/server/note/repository/NoteRepository.java @@ -11,9 +11,9 @@ public interface NoteRepository extends JpaRepository { - @Query("SELECT n FROM Note n WHERE n.createdAt < :createdAt ORDER BY n.createdAt DESC") - List findByCreatedAtBeforeOrderByModifiedAtDesc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable); + @Query("SELECT n FROM Note n WHERE n.teamId = :teamId AND n.createdAt < :createdAt ORDER BY n.createdAt DESC") + List findByTeamIdAndCreatedAtBeforeOrderByCreatedDesc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable, long teamId); - @Query("SELECT n FROM Note n WHERE n.createdAt > :createdAt ORDER BY n.createdAt ASC") - List findByCreatedAtAfterOrderByModifiedAtAsc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable); + @Query("SELECT n FROM Note n WHERE n.teamId = :teamId AND n.createdAt > :createdAt ORDER BY n.createdAt ASC") + List findByTeamIdAndCreatedAtAfterOrderByCreatedAtAsc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable, long teamId); } diff --git a/src/main/java/com/tiki/server/note/service/NoteService.java b/src/main/java/com/tiki/server/note/service/NoteService.java index 3f5e3e89..3888b4ef 100644 --- a/src/main/java/com/tiki/server/note/service/NoteService.java +++ b/src/main/java/com/tiki/server/note/service/NoteService.java @@ -139,7 +139,7 @@ public NoteListGetServiceResponse getNote( ) { memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId); PageRequest pageable = PageRequest.of(INIT_NUM, PAGE_SIZE); - List noteList = getNotes(createdAt, sortOrder, pageable); + List noteList = getNotes(createdAt, sortOrder, pageable, teamId); List noteGetResponses = noteList.stream() .map(note -> NoteGetResponse.of(note, getMemberName(note.getMemberId(), teamId))) .toList(); @@ -191,11 +191,11 @@ private void updateNoteTimeBlockManager(final List timeBlockIds, final lon noteTimeBlockManagerDeleter.deleteByNoteIdAndTimeBlockId(noteId, idsToRemove); } - private List getNotes(final LocalDateTime createdAt, final SortOrder sortOrder, final PageRequest pageable) { + private List getNotes(final LocalDateTime createdAt, final SortOrder sortOrder, final PageRequest pageable, final long teamId) { if (sortOrder == SortOrder.DESC) { - return noteFinder.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageable); + return noteFinder.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageable, teamId); } - return noteFinder.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageable); + return noteFinder.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageable, teamId); } private List getTimeBlocksMappedByNote(final long noteId) {