Skip to content

Commit

Permalink
Merge pull request #37 from rework-kr/Feat/33-readDailyAgenda
Browse files Browse the repository at this point in the history
Feat/33 read daily agenda
  • Loading branch information
OneK-2 authored Jul 2, 2024
2 parents 4292549 + cf56ce8 commit 2251eb5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ReadDailyAgendaResponseDto readDailyAgenda(int year, int month, int day,
}

List<ReadDetailDailyAgendaResponseDto> result = agendaList.stream()
.sorted((a1, a2) -> Long.compare(a2.getPagingId(), a1.getPagingId()))
.map(agenda -> new ReadDetailDailyAgendaResponseDto(agenda.getId(), agenda.getTodo(), agenda.isState(), agenda.getPagingId())).toList();

return new ReadDailyAgendaResponseDto(result);
Expand Down Expand Up @@ -110,7 +111,8 @@ public UpdateDailyAgendaResponseDto updateDailyAgenda(UpdateDailyAgendaRequestDt
LocalDateTime startOfDay = createdAt.toLocalDate().atStartOfDay();
LocalDateTime endOfDay = createdAt.toLocalDate().atTime(LocalTime.MAX);

if (dailyAgendaRepository.existsByPagingIdAndCreatedAtBetween(updateDailyAgendaRequestDto.getPagingId(), startOfDay, endOfDay)) {
Optional<DailyAgenda> existingAgenda = dailyAgendaRepository.findByPagingIdAndCreatedAtBetween(updateDailyAgendaRequestDto.getPagingId(), startOfDay, endOfDay);
if (existingAgenda.isPresent() && !existingAgenda.get().getId().equals(updateDailyAgendaRequestDto.getAgendaId())) {
throw new AlreadyPagingIdException("이미 등록된 페이징번호입니다");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface DailyAgendaRepository extends JpaRepository<DailyAgenda, Long> {
List<DailyAgenda> findByMemberIdAndCreatedAtBetween(Long memberId, LocalDateTime startOfDay, LocalDateTime endOfDay);

List<DailyAgenda> findByMemberIdAndCreatedAtBetweenAndState(Long memberId, LocalDateTime startOfDay, LocalDateTime endOfDay, boolean state);

Optional<DailyAgenda> findByPagingIdAndCreatedAtBetween(Long pagingId, LocalDateTime start, LocalDateTime end);

boolean existsByPagingIdAndCreatedAtBetween(Long pagingId, LocalDateTime startOfDay, LocalDateTime endOfDay);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ void readDailyAgenda() {
DailyAgendaResponseDto.ReadDailyAgendaResponseDto readDailyAgendaResponseDto = dailyAgendaService.readDailyAgenda(year, month, day, state, null);

// then
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(0).getPagingId()).isEqualTo(1L);
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(0).getTodo()).isEqualTo("test1");
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(0).getPagingId()).isEqualTo(2L);
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(0).getTodo()).isEqualTo("test2");
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(0).isState()).isFalse();

Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(1).getPagingId()).isEqualTo(2L);
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(1).getTodo()).isEqualTo("test2");
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(1).getPagingId()).isEqualTo(1L);
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(1).getTodo()).isEqualTo("test1");
Assertions.assertThat(readDailyAgendaResponseDto.getAgendaList().get(1).isState()).isFalse();
}

Expand Down

0 comments on commit 2251eb5

Please sign in to comment.