Skip to content

Commit

Permalink
Merge pull request #41 from rework-kr/Bugfix/40-dailyAgenda
Browse files Browse the repository at this point in the history
FIX:: dailyAgenda 업데이트 수정
  • Loading branch information
OneK-2 authored Jul 5, 2024
2 parents a65af4d + 40646a5 commit 921d898
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public CreateDailyAgendaResponseDto createDailyAgenda(CreateDailyAgendaRequestDt
LocalDateTime startOfDay = createDailyAgendaRequestDto.getCreatedAt().atStartOfDay();
LocalDateTime endOfDay = createDailyAgendaRequestDto.getCreatedAt().atTime(LocalTime.MAX);

if (dailyAgendaRepository.existsByMemberIdAndPagingIdAndCreatedAtBetween(currentUserId,createDailyAgendaRequestDto.getPagingId(), startOfDay, endOfDay)) {
if (dailyAgendaRepository.existsByMemberIdAndPagingIdAndCreatedAtBetween(currentUserId, createDailyAgendaRequestDto.getPagingId(), startOfDay, endOfDay)) {
throw new AlreadyPagingIdException("이미 등록된 페이징번호입니다");
}

Expand Down Expand Up @@ -111,11 +111,14 @@ public UpdateDailyAgendaResponseDto updateDailyAgenda(UpdateDailyAgendaRequestDt
LocalDateTime startOfDay = createdAt.toLocalDate().atStartOfDay();
LocalDateTime endOfDay = createdAt.toLocalDate().atTime(LocalTime.MAX);

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

dailyAgenda.updatePagingId(updateDailyAgendaRequestDto.getPagingId());
dailyAgenda.setTodo(updateDailyAgendaRequestDto.getTodo());
dailyAgenda.setState(updateDailyAgendaRequestDto.isState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface DailyAgendaRepository extends JpaRepository<DailyAgenda, Long>

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

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

boolean existsByMemberIdAndPagingIdAndCreatedAtBetween(Long memberId, Long pagingId, LocalDateTime createdAt, LocalDateTime createdAt2);
}

0 comments on commit 921d898

Please sign in to comment.