/
klsfv
/
CalorieTracker
Обзор
Документация
Войти
/
klsfv
/
CalorieTracker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
server/src/main/java/com/calorietracker/controller/StatisticsController.java
49 строк
2 KB
klsfv
upload files
15 янв 2026, 03:19
15 янв 2026, 03:19
09dece5
Код
Авторство
О чём код?
package com.calorietracker.controller; import com.calorietracker.dto.DailyStatisticsDto; import com.calorietracker.dto.WeeklyStatisticsDto; import com.calorietracker.service.StatisticsService; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; import java.time.LocalDate; @RestController @RequestMapping("/api/v1/statistics") public class StatisticsController { private final StatisticsService statisticsService; public StatisticsController(StatisticsService statisticsService) { this.statisticsService = statisticsService; } @GetMapping("/daily/{date}") public ResponseEntity<DailyStatisticsDto> getDaily( @PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date, Authentication authentication) { String userId = authentication.getName(); DailyStatisticsDto stats = statisticsService.getDaily(userId, date); return ResponseEntity.ok(stats); } @GetMapping("/weekly") public ResponseEntity<WeeklyStatisticsDto> getWeekly( @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, Authentication authentication) { String userId = authentication.getName(); if (startDate == null) { startDate = LocalDate.now().minusDays(6); } if (endDate == null) { endDate = LocalDate.now(); } WeeklyStatisticsDto stats = statisticsService.getWeekly(userId, startDate, endDate); return ResponseEntity.ok(stats); } }