seminar/src/main/java/ru/ulstu/statistic/controller/StatisticController.java
2025-04-03 11:36:21 +04:00

38 lines
1.5 KiB
Java

package ru.ulstu.statistic.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.ulstu.report.service.ReportPeriodService;
import ru.ulstu.statistic.model.StatisticForm;
import ru.ulstu.statistic.service.StatisticService;
@Controller
@RequestMapping("statistic")
public class StatisticController {
private final ReportPeriodService reportPeriodService;
private final StatisticService statisticService;
public StatisticController(ReportPeriodService reportPeriodService,
StatisticService statisticService) {
this.reportPeriodService = reportPeriodService;
this.statisticService = statisticService;
}
@GetMapping("statistic")
public String getStatistic(Model model) {
model.addAttribute("statisticForm", new StatisticForm());
model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods());
return "/statistic/statistic";
}
@PostMapping("statistic")
public String getStatistic(StatisticForm form, Model model) {
model.addAttribute("rating", statisticService.getRating(form.getReportPeriod().getId()));
model.addAttribute("statisticForm", form);
model.addAttribute("reportPeriods", reportPeriodService.getReportPeriods());
return "/statistic/statistic";
}
}