51 lines
1.9 KiB
Java
51 lines
1.9 KiB
Java
package ru.ulstu.aspirant.controller;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import ru.ulstu.aspirant.model.Report;
|
|
import ru.ulstu.aspirant.service.AspirantService;
|
|
import ru.ulstu.indicator.model.Indicator;
|
|
import ru.ulstu.model.OffsetablePageRequest;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.IntStream;
|
|
|
|
@Controller
|
|
@RequestMapping("aspirant")
|
|
public class AspirantController {
|
|
private static final Integer DEFAULT_PAGE_SIZE = 1;
|
|
private static final Integer DEFAULT_PAGE_NUMBER = 1;
|
|
private final AspirantService aspirantService;
|
|
|
|
public AspirantController(AspirantService aspirantService) {
|
|
this.aspirantService = aspirantService;
|
|
}
|
|
|
|
@GetMapping("aspirantReport")
|
|
public String createReport(Model model,
|
|
@RequestParam Optional<Integer> page,
|
|
@RequestParam Optional<Integer> size) {
|
|
int currentPage = page.orElse(DEFAULT_PAGE_NUMBER);
|
|
int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
|
|
|
|
Page<Indicator> indicators = aspirantService.getIndicatorsByCourse(new OffsetablePageRequest(currentPage - 1, pageSize));
|
|
model.addAttribute("indicators", indicators);
|
|
int totalPages = indicators.getTotalPages();
|
|
if (totalPages > 0) {
|
|
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
|
|
.boxed()
|
|
.collect(Collectors.toList());
|
|
model.addAttribute("pageNumbers", pageNumbers);
|
|
}
|
|
|
|
model.addAttribute("report", new Report());
|
|
return "aspirant/editReport";
|
|
}
|
|
}
|