@@ -242,16 +242,33 @@ public ResponseEntity<?> getGoalList(@RequestParam("userId") Long userId) {
242242 List <Goal > goalList = goalService .getGoalList (userId );
243243 List <GoalAllSearchDto > goalAllDto = new ArrayList <>();
244244 for (Goal goal : goalList ) {
245- List <LocalDate > calender = goalService .DateRangeCalculator (goal .getId ());
245+ List <LocalDate > calender = goalService .DateRangeCalculator (goal .getId ()); // 목표 달력을 위한 전체 날짜값(today가 startDate의 주에 속하면 이번 주 + 다음 주 , today가 startDate의 주에 속하지 않으면 지난주 + 이번 주)
246246 System .out .println (calender );
247- List <GoalDateDto > goalDateDto = new ArrayList <>();
248- List <GoalAchievementsLog > logs = goalAchievementLogRepository .findByGoal_IdAndAchievedSuccessIsTrue (goal .getId ());
247+ List <GoalDateDto > goalDateDto = new ArrayList <>(); // 목표 달력을 위한 인증 날짜값
248+
249+ // 목표의 시작일부터 종료일까지의 모든 날짜를 생성
250+ LocalDate startDate = goal .getStartDate ();
251+ LocalDate endDate = goal .getEndDate ();
252+ List <LocalDate > allDates = new ArrayList <>();
253+ LocalDate currentDate = startDate ;
254+ while (!currentDate .isAfter (endDate )) {
255+ allDates .add (currentDate );
256+ currentDate = currentDate .plusDays (1 );
257+ }
249258
259+ // 인증 성공한 날짜들을 Set으로 변환 (속도 떄문에)
260+ Set <LocalDate > successDates = new HashSet <>();
261+ List <GoalAchievementsLog > achievementLogs = goalAchievementLogRepository
262+ .findByGoal_IdAndAchievedSuccessIsTrue (goal .getId ());
263+ for (GoalAchievementsLog log : achievementLogs ) {
264+ successDates .add (log .getAchievedAt ());
265+ }
250266
251- for (GoalAchievementsLog log : logs ) {
252- GoalDateDto dto = new GoalDateDto (log .getAchievedAt (), log .isAchievedSuccess ());
253- goalDateDto .add (dto );
254- }
267+ // 모든 날짜에 대해 인증 상태를 확인하여 DTO 생성 , 인증 성공한 날짜 확인 후 인증 날짜 값 추가
268+ for (LocalDate date : allDates ) {
269+ GoalDateDto dto = new GoalDateDto (date , successDates .contains (date ));
270+ goalDateDto .add (dto );
271+ }
255272
256273 // goalDays : 요일 String값으로 가공
257274 List <GoalDay > goalDays = goalDayRepository .findByGoalId (goal .getId ());
@@ -266,8 +283,8 @@ public ResponseEntity<?> getGoalList(@RequestParam("userId") Long userId) {
266283
267284 GoalAllSearchDto dto = new GoalAllSearchDto (goal .getId (),goal .getId (),goal .getName (),goal .getStatus (),goal .getStartDate (),goal .getEndDate (),goal .getLocationName (),goal .getLatitude (),goal .getLongitude (),goal .getRadius (),goal .getTargetCount (),goal .getAchievedCount (),
268285 goalDateDto , // 인증된 날짜들
269- calender
270- ,days .toString ()); // 날짜 값들
286+ calender // 날짜 값들
287+ ,days .toString ());
271288
272289 goalAllDto .add (dto );
273290
0 commit comments