Skip to content

Commit 6d44973

Browse files
authored
Merge pull request #52 from Location-based-target-authentication/habranche
"전체목표조회 인증값 날짜 로직 변경"
2 parents 5ac5cc8 + f873596 commit 6d44973

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

Location-based-target-authentication/src/main/java/com/swyp/global/config/WebConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public ViewResolver viewResolver() {
1818
return resolver;
1919
}
2020

21+
22+
2123
@Override
2224
public void addResourceHandlers(ResourceHandlerRegistry registry) {
2325
registry.addResourceHandler("/swagger-ui/**")

Location-based-target-authentication/src/main/java/com/swyp/goal/controller/GoalRestController.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Location-based-target-authentication/src/main/resources/application.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ spring.config.import=classpath:application-secret.properties
99
logging.level.com.swyp.location=INFO
1010
logging.level.org.springframework.web.reactive.function.client=INFO
1111

12-
spring.mvc.view.prefix=/WEB-INF/views/
13-
spring.mvc.view.suffix=.jsp
1412

1513
# Server Configuration
1614
server.port=443

0 commit comments

Comments
 (0)