Add aspirant indicator read action

This commit is contained in:
Anton Romanov 2025-01-30 00:44:48 +04:00
parent d4a797cfc3
commit 290bec8f88
5 changed files with 62 additions and 1 deletions

View File

@ -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<Indicator> indicators = aspirantService.getIndicatorsByCourse();
return "aspirant/editReport";
}
}

View File

@ -42,7 +42,11 @@ public class Aspirant extends BaseEntity {
private Base base; private Base base;
public Aspirant() { public Aspirant() {
}
public Aspirant(String name, Course course) {
this.name = name;
this.course = course;
} }
public String getSurname() { public String getSurname() {

View File

@ -4,15 +4,22 @@ import org.springframework.stereotype.Service;
import ru.ulstu.admin.model.AspirantForm; import ru.ulstu.admin.model.AspirantForm;
import ru.ulstu.aspirant.model.Aspirant; import ru.ulstu.aspirant.model.Aspirant;
import ru.ulstu.aspirant.repository.AspirantRepository; 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; import java.util.List;
@Service @Service
public class AspirantService { public class AspirantService {
private final AspirantRepository aspirantRepository; private final AspirantRepository aspirantRepository;
private final IndicatorService indicatorService;
public AspirantService(AspirantRepository aspirantRepository) { public AspirantService(AspirantRepository aspirantRepository,
IndicatorService indicatorService) {
this.aspirantRepository = aspirantRepository; this.aspirantRepository = aspirantRepository;
this.indicatorService = indicatorService;
} }
public List<Aspirant> getAspirants() { public List<Aspirant> getAspirants() {
@ -30,4 +37,15 @@ public class AspirantService {
public void deleteAspirant(AspirantForm aspirantForm) { public void deleteAspirant(AspirantForm aspirantForm) {
aspirantRepository.deleteById(aspirantForm.getId()); 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<Indicator> getIndicatorsByCourse() {
Aspirant aspirant = getAspirantByUser(UserUtils.getCurrentUserLogin());
return indicatorService.getIndicatorsByCourse(aspirant.getCourse());
}
} }

View File

@ -1,8 +1,16 @@
package ru.ulstu.indicator.repository; package ru.ulstu.indicator.repository;
import org.springframework.data.jpa.repository.JpaRepository; 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 ru.ulstu.indicator.model.Indicator;
import java.util.List;
public interface IndicatorRepository extends JpaRepository<Indicator, Integer> { public interface IndicatorRepository extends JpaRepository<Indicator, Integer> {
Indicator findByName(String name); Indicator findByName(String name);
@Query("select i from Indicator i WHERE :course member of i.courses")
List<Indicator> findAllByCourse(@Param("course") Course course);
} }

View File

@ -2,6 +2,7 @@ package ru.ulstu.indicator.service;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.ulstu.admin.model.IndicatorForm; import ru.ulstu.admin.model.IndicatorForm;
import ru.ulstu.indicator.model.Course;
import ru.ulstu.indicator.model.Indicator; import ru.ulstu.indicator.model.Indicator;
import ru.ulstu.indicator.repository.IndicatorRepository; import ru.ulstu.indicator.repository.IndicatorRepository;
@ -34,4 +35,8 @@ public class IndicatorService {
public void deleteIndicator(IndicatorForm indicatorForm) { public void deleteIndicator(IndicatorForm indicatorForm) {
indicatorRepository.deleteById(indicatorForm.getId()); indicatorRepository.deleteById(indicatorForm.getId());
} }
public List<Indicator> getIndicatorsByCourse(Course course) {
return indicatorRepository.findAllByCourse(course);
}
} }