Skip to content

Commit

Permalink
Merge pull request #184 from Team-Tiki/fix-/183-find-notes
Browse files Browse the repository at this point in the history
[FIX] 노트 조회 로직 수정
  • Loading branch information
paragon0107 authored Nov 29, 2024
2 parents d786c06 + 5624fbb commit 73fb9eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/main/java/com/tiki/server/note/adapter/NoteFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ public class NoteFinder {

private final NoteRepository noteRepository;

public List<Note> findByCreatedAtBeforeOrderByModifiedAtDesc(final LocalDateTime createdAt, final PageRequest pageRequest) {
return noteRepository.findByCreatedAtBeforeOrderByModifiedAtDesc(createdAt, pageRequest);
public List<Note> findByCreatedAtBeforeOrderByModifiedAtDesc(
final LocalDateTime createdAt,
final PageRequest pageRequest,
final long teamId
) {
return noteRepository.findByTeamIdAndCreatedAtBeforeOrderByCreatedDesc(createdAt, pageRequest, teamId);
}

public List<Note> findByCreatedAtAfterOrderByModifiedAtAsc(final LocalDateTime createdAt, final PageRequest pageRequest) {
return noteRepository.findByCreatedAtAfterOrderByModifiedAtAsc(createdAt, pageRequest);
public List<Note> findByCreatedAtAfterOrderByModifiedAtAsc(
final LocalDateTime createdAt,
final PageRequest pageRequest,
final long teamId
) {
return noteRepository.findByTeamIdAndCreatedAtAfterOrderByCreatedAtAsc(createdAt, pageRequest, teamId);
}

public Note findById(final long noteId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

public interface NoteRepository extends JpaRepository<Note, Long> {

@Query("SELECT n FROM Note n WHERE n.createdAt < :createdAt ORDER BY n.createdAt DESC")
List<Note> 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<Note> 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<Note> 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<Note> findByTeamIdAndCreatedAtAfterOrderByCreatedAtAsc(@Param("createdAt") LocalDateTime createdAt, Pageable pageable, long teamId);
}
8 changes: 4 additions & 4 deletions src/main/java/com/tiki/server/note/service/NoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public NoteListGetServiceResponse getNote(
) {
memberTeamManagerFinder.findByMemberIdAndTeamIdOrElseThrow(memberId, teamId);
PageRequest pageable = PageRequest.of(INIT_NUM, PAGE_SIZE);
List<Note> noteList = getNotes(createdAt, sortOrder, pageable);
List<Note> noteList = getNotes(createdAt, sortOrder, pageable, teamId);
List<NoteGetResponse> noteGetResponses = noteList.stream()
.map(note -> NoteGetResponse.of(note, getMemberName(note.getMemberId(), teamId)))
.toList();
Expand Down Expand Up @@ -191,11 +191,11 @@ private void updateNoteTimeBlockManager(final List<Long> timeBlockIds, final lon
noteTimeBlockManagerDeleter.deleteByNoteIdAndTimeBlockId(noteId, idsToRemove);
}

private List<Note> getNotes(final LocalDateTime createdAt, final SortOrder sortOrder, final PageRequest pageable) {
private List<Note> 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<TimeBlock> getTimeBlocksMappedByNote(final long noteId) {
Expand Down

0 comments on commit 73fb9eb

Please sign in to comment.