Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@ public ResponseEntity<ApiResponse<UserCarbonLogSummaryResponse>> getLogsByDate(
return ResponseEntity.ok(new ApiResponse<>(true, "조회 성공", logs));
}

@GetMapping("/daily/challenge")
public ResponseEntity<ApiResponse<UserCarbonLogSummaryResponse>> getChallengeLogsByDate(
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {

UserCarbonLogSummaryResponse summaryResponse = userCarbonLogService.getChallengeLogsByUserIdAndDate(
userDetails.getUserId(), date
);

return ResponseEntity.ok(new ApiResponse<>(true, "챌린지 탄소 활동 조회 성공", summaryResponse));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface UserCarbonLogRepository extends JpaRepository<UserCarbonLog, Lo

List<UserCarbonLog> findByUserIdAndRecordedAtBetween(Long userId, LocalDateTime start, LocalDateTime end);

List<UserCarbonLog> findByUserIdAndRecordedAtBetweenAndIsFromChallengeTrue(Long userId, LocalDateTime start,
List<UserCarbonLog> findByUserIdAndRecordedAtBetweenAndIsFromChallengeFalse(Long userId, LocalDateTime start,
LocalDateTime end);

void deleteByUserId(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public interface UserCarbonLogService {

UserCarbonLogSummaryResponse getLogsByUserIdAndDate(Long userId, LocalDate date);

// 챌린지 로그만 조회
UserCarbonLogSummaryResponse getChallengeLogsByUserIdAndDate(Long userId, LocalDate date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public UserCarbonLogSummaryResponse getLogsByUserIdAndDate(Long userId, LocalDat



List<UserCarbonLog> logs = carbonLogRepository.findByUserIdAndRecordedAtBetween(userId, startOfDay,
List<UserCarbonLog> logs = carbonLogRepository.findByUserIdAndRecordedAtBetweenAndIsFromChallengeFalse(userId, startOfDay,
endOfDay);

int totalGrowthPoint = logs.stream()
Expand All @@ -115,30 +115,7 @@ public UserCarbonLogSummaryResponse getLogsByUserIdAndDate(Long userId, LocalDat
.build();
}

public UserCarbonLogSummaryResponse getChallengeLogsByUserIdAndDate(Long userId, LocalDate date) {
LocalDateTime start = date.atStartOfDay();
LocalDateTime end = date.atTime(LocalTime.MAX);

List<UserCarbonLog> logs = carbonLogRepository.findByUserIdAndRecordedAtBetweenAndIsFromChallengeTrue(
userId, start, end
);

int totalGrowthPoint = logs.stream()
.mapToInt(UserCarbonLog::getGrowthPoint)
.sum();

List<UserCarbonLogResponse> logDtos = logs.stream()
.map(log -> UserCarbonLogResponse.builder()
.product(log.getCarbonItem().getName())
.growthPoint(log.getGrowthPoint())
.build())
.toList();

return UserCarbonLogSummaryResponse.builder()
.logs(logDtos)
.totalGrowthPoint(totalGrowthPoint)
.build();
}


}
2 changes: 1 addition & 1 deletion server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ openai:
key: ${OPENAI_API_KEY}

server:
port: 8080
port: 3004

oauth:
google:
Expand Down