Skip to content

Commit

Permalink
fix: date type ๋ณ€๊ฒฝ
Browse files Browse the repository at this point in the history
  • Loading branch information
Haewonny committed Mar 6, 2024
1 parent b7432a3 commit 38cfad9
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main/java/ewha/lux/once/domain/home/service/HomeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -186,29 +185,29 @@ public void getPayCardHistory(Users nowUser, Long chatId) throws CustomException
public AnnounceListDto getAnnounce(Users nowUser) throws CustomException {
String nickname = nowUser.getNickname();

LocalDateTime today = LocalDateTime.now().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
LocalDateTime thisWeek = today.minusDays(7);
LocalDate today = LocalDate.now();
LocalDate thisWeek = today.minusDays(7);

List<Announcement> announcementList = announcementRepository.findAnnouncementByUsers(nowUser);

// ์˜ค๋Š˜ ์ƒ์„ฑ๋œ ์•Œ๋ฆผ
List<AnnounceDto> todayAnnounceDto = announcementList.stream()
.filter(announcement -> announcement.getCreatedAt().isEqual(today))
.filter(announcement -> announcement.getCreatedAt().toLocalDate().isEqual(today))
.sorted(Comparator.comparing(Announcement::getCreatedAt).reversed())
.map(AnnounceDto::new)
.collect(Collectors.toList());

// 7์ผ ์ด๋‚ด์— ์ƒ์„ฑ๋œ ์•Œ๋ฆผ (์˜ค๋Š˜ ์ œ์™ธ)
List<AnnounceDto> recentAnnounceDto = announcementList.stream()
.filter(announcement -> !announcement.getCreatedAt().isEqual(today)
&& announcement.getCreatedAt().isAfter(thisWeek))
.filter(announcement -> !announcement.getCreatedAt().toLocalDate().isEqual(today)
&& announcement.getCreatedAt().toLocalDate().isAfter(thisWeek))
.sorted(Comparator.comparing(Announcement::getCreatedAt).reversed())
.map(AnnounceDto::new)
.collect(Collectors.toList());

long uncheckedcnt = announcementList.stream()
.filter(announcement -> !announcement.isHasCheck()
&& announcement.getCreatedAt().isAfter(thisWeek))
&& announcement.getCreatedAt().toLocalDate().isAfter(thisWeek))
.count();

return new AnnounceListDto(nickname, uncheckedcnt, todayAnnounceDto, recentAnnounceDto);
Expand All @@ -222,4 +221,4 @@ public AnnounceDetailDto getAnnounceDetail(Long announceId) throws CustomExcepti
announcementRepository.save(announcement);
return new AnnounceDetailDto(announcement);
}
}
}

0 comments on commit 38cfad9

Please sign in to comment.