From 290bec8f88058f570259fb2f7f0ef91ec96b2e95 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 30 Jan 2025 00:44:48 +0400 Subject: [PATCH] Add aspirant indicator read action --- .../controller/AspirantController.java | 26 +++++++++++++++++++ .../ru/ulstu/aspirant/model/Aspirant.java | 4 +++ .../aspirant/service/AspirantService.java | 20 +++++++++++++- .../repository/IndicatorRepository.java | 8 ++++++ .../indicator/service/IndicatorService.java | 5 ++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/aspirant/controller/AspirantController.java diff --git a/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java b/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java new file mode 100644 index 0000000..91f953c --- /dev/null +++ b/src/main/java/ru/ulstu/aspirant/controller/AspirantController.java @@ -0,0 +1,26 @@ +package ru.ulstu.aspirant.controller; + +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 ru.ulstu.aspirant.service.AspirantService; +import ru.ulstu.indicator.model.Indicator; + +import java.util.List; + +@Controller +@RequestMapping("aspirant") +public class AspirantController { + private final AspirantService aspirantService; + + public AspirantController(AspirantService aspirantService) { + this.aspirantService = aspirantService; + } + + @GetMapping("aspirantReport") + public String createReport(Model model) { + List indicators = aspirantService.getIndicatorsByCourse(); + return "aspirant/editReport"; + } +} diff --git a/src/main/java/ru/ulstu/aspirant/model/Aspirant.java b/src/main/java/ru/ulstu/aspirant/model/Aspirant.java index 50571a5..a13d965 100644 --- a/src/main/java/ru/ulstu/aspirant/model/Aspirant.java +++ b/src/main/java/ru/ulstu/aspirant/model/Aspirant.java @@ -42,7 +42,11 @@ public class Aspirant extends BaseEntity { private Base base; public Aspirant() { + } + public Aspirant(String name, Course course) { + this.name = name; + this.course = course; } public String getSurname() { diff --git a/src/main/java/ru/ulstu/aspirant/service/AspirantService.java b/src/main/java/ru/ulstu/aspirant/service/AspirantService.java index da93fc3..bf718c7 100644 --- a/src/main/java/ru/ulstu/aspirant/service/AspirantService.java +++ b/src/main/java/ru/ulstu/aspirant/service/AspirantService.java @@ -4,15 +4,22 @@ import org.springframework.stereotype.Service; import ru.ulstu.admin.model.AspirantForm; import ru.ulstu.aspirant.model.Aspirant; import ru.ulstu.aspirant.repository.AspirantRepository; +import ru.ulstu.indicator.model.Course; +import ru.ulstu.indicator.model.Indicator; +import ru.ulstu.indicator.service.IndicatorService; +import ru.ulstu.user.UserUtils; import java.util.List; @Service public class AspirantService { private final AspirantRepository aspirantRepository; + private final IndicatorService indicatorService; - public AspirantService(AspirantRepository aspirantRepository) { + public AspirantService(AspirantRepository aspirantRepository, + IndicatorService indicatorService) { this.aspirantRepository = aspirantRepository; + this.indicatorService = indicatorService; } public List getAspirants() { @@ -30,4 +37,15 @@ public class AspirantService { public void deleteAspirant(AspirantForm aspirantForm) { aspirantRepository.deleteById(aspirantForm.getId()); } + + public Aspirant getAspirantByUser(String currentUserLogin) { + //return aspirantRepository.getAspirantByLogin(); + //TODO: read aspirant + return aspirantRepository.findAll().stream().findAny().orElse(new Aspirant("default", Course.FIRST)); + } + + public List getIndicatorsByCourse() { + Aspirant aspirant = getAspirantByUser(UserUtils.getCurrentUserLogin()); + return indicatorService.getIndicatorsByCourse(aspirant.getCourse()); + } } diff --git a/src/main/java/ru/ulstu/indicator/repository/IndicatorRepository.java b/src/main/java/ru/ulstu/indicator/repository/IndicatorRepository.java index dce70b2..911fbbd 100644 --- a/src/main/java/ru/ulstu/indicator/repository/IndicatorRepository.java +++ b/src/main/java/ru/ulstu/indicator/repository/IndicatorRepository.java @@ -1,8 +1,16 @@ package ru.ulstu.indicator.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import ru.ulstu.indicator.model.Course; import ru.ulstu.indicator.model.Indicator; +import java.util.List; + public interface IndicatorRepository extends JpaRepository { Indicator findByName(String name); + + @Query("select i from Indicator i WHERE :course member of i.courses") + List findAllByCourse(@Param("course") Course course); } diff --git a/src/main/java/ru/ulstu/indicator/service/IndicatorService.java b/src/main/java/ru/ulstu/indicator/service/IndicatorService.java index 27f9286..6c96f09 100644 --- a/src/main/java/ru/ulstu/indicator/service/IndicatorService.java +++ b/src/main/java/ru/ulstu/indicator/service/IndicatorService.java @@ -2,6 +2,7 @@ package ru.ulstu.indicator.service; import org.springframework.stereotype.Service; import ru.ulstu.admin.model.IndicatorForm; +import ru.ulstu.indicator.model.Course; import ru.ulstu.indicator.model.Indicator; import ru.ulstu.indicator.repository.IndicatorRepository; @@ -34,4 +35,8 @@ public class IndicatorService { public void deleteIndicator(IndicatorForm indicatorForm) { indicatorRepository.deleteById(indicatorForm.getId()); } + + public List getIndicatorsByCourse(Course course) { + return indicatorRepository.findAllByCourse(course); + } }