diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/EducationEntryController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/EducationEntryController.java new file mode 100644 index 0000000..d1da210 --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/EducationEntryController.java @@ -0,0 +1,196 @@ +package ru.molokoin.clientserviceteachers.controllers; + +import java.time.Duration; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.reactive.function.client.WebClient; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; + +import reactor.core.publisher.Mono; +import ru.molokoin.clientserviceteachers.entities.Course; +import ru.molokoin.clientserviceteachers.entities.EducatonEntry; +import ru.molokoin.clientserviceteachers.entities.Program; +import ru.molokoin.clientserviceteachers.entities.ProgramCretarea; +import ru.molokoin.clientserviceteachers.entities.Student; + +@Controller +@RequestMapping(path = "/") +public class EducationEntryController { + @Autowired + private WebClient client; + + @GetMapping("/educations") + public String educationEntryList(Model model) throws JsonMappingException, JsonProcessingException{ + List educations = client.method(HttpMethod.GET) + .uri("/education/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .block(); + + model.addAttribute("educations", educations); + model.addAttribute("edu", new EducatonEntry()); + System.out.println("EDUCATIONS:" + educations.toString()); + return "educations"; + } + + @GetMapping("/education-edit/{id}") + public String educationEntryById(Model model, @PathVariable Long id) { + /** + * получение списка студентов из ресурсов + * - для select поля формы + */ + List students = client.get() + .uri("/student/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("students", students); + + /** + * получение списка курсов из ресурсов + * - для select поля формы + */ + List courses = client.get() + .uri("/course/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("courses", courses); + + /** + * Получение данных об обучении из ресурсов + * - для отображения в форме редактирования + */ + EducatonEntry ee = client.get() + .uri("/education/" + id) + .retrieve() + .bodyToMono(EducatonEntry.class) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("education", ee); + return "education-edit"; + } + + @PostMapping( + path = "/education/add", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String addEducationEntry(Model model, @ModelAttribute("education") @Validated EducatonEntry ee) throws JsonMappingException, JsonProcessingException{ + /** + * получение списка студентов из ресурсов + * - для select поля формы + */ + List students = client.get() + .uri("/student/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("students", students); + + /** + * получение списка курсов из ресурсов + * - для select поля формы + */ + List courses = client.get() + .uri("/course/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("courses", courses); + + client.post() + .uri("/education/create") + .body(Mono.just(ee), EducatonEntry.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/educations"; + } + + @GetMapping(path = "/education/add") + public String addProgramFrame(Model model){ + /** + * получение списка студентов из ресурсов + * - для select поля формы + */ + List students = client.get() + .uri("/student/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("students", students); + + /** + * получение списка курсов из ресурсов + * - для select поля формы + */ + List courses = client.get() + .uri("/course/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("courses", courses); + + /** + * Создание пустого объекта, для передачи в форму для заполнения + */ + EducatonEntry education = new EducatonEntry(); + model.addAttribute("newEducation", education); + return "education-add"; + } + + @GetMapping(path = "/education/delete/{id}") + public String deleteProgram(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ + client.delete() + .uri("/education/delete/" + id) + .retrieve() + .bodyToMono(String.class) + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/educations"; + } + + @PostMapping( + path = "/education/update/{id}", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String updateProgram(@PathVariable Long id + , @ModelAttribute("edu") @Validated EducatonEntry education) throws JsonMappingException, JsonProcessingException{ + client.post() + .uri("/education/update/" + education.getId()) + .body(Mono.just(education), EducatonEntry.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/educations"; + } + + + +} diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/EducatonEntry.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/EducatonEntry.java new file mode 100644 index 0000000..1c99ac1 --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/EducatonEntry.java @@ -0,0 +1,38 @@ +package ru.molokoin.clientserviceteachers.entities; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class EducatonEntry { + private long id; + private String sertificate_number;//номер удостоверения + private String frdo_number;//ФРДО номер по реестру + private String eisot_number;//ЕИСОТ номер по реестру + private String ones;//единички (вспомогатльный столбец) + private Course course;//сведения о курсе + private Student student;//сведения о студенте + + /** + * Конструктор без id + * @param sertificate_number + * @param frdo_number + * @param eisot_number + * @param ones + * @param course + * @param student + */ + public EducatonEntry(String sertificate_number, String frdo_number, String eisot_number, String ones, + Course course, Student student) { + this.sertificate_number = sertificate_number; + this.frdo_number = frdo_number; + this.eisot_number = eisot_number; + this.ones = ones; + this.course = course; + this.student = student; + } + +} diff --git a/client-service-teachers/src/main/resources/templates/education-add.html b/client-service-teachers/src/main/resources/templates/education-add.html new file mode 100644 index 0000000..74598e6 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/education-add.html @@ -0,0 +1,59 @@ + + + + + Education-add + + + + +
+ add : Education +
+
+

Добавление обучения:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/education-edit.html b/client-service-teachers/src/main/resources/templates/education-edit.html new file mode 100644 index 0000000..94c0373 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/education-edit.html @@ -0,0 +1,59 @@ + + + + + Education-edit + + + + +
+ edit : Education +
+
+

Редактирование сведений об обучении:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/educations.html b/client-service-teachers/src/main/resources/templates/educations.html new file mode 100644 index 0000000..2704584 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/educations.html @@ -0,0 +1,76 @@ + + + + + Educations + + + + + +
+

EDUCATIONS

+ menu : auth : Educations +
+
+
+
+

Перечень обучений:

+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
idsertificate_numberfrdo_numbereisot_numberonescoursestudent +
+ +
+
+ + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ + \ No newline at end of file diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/EducationEntryController.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/EducationEntryController.java new file mode 100644 index 0000000..f243c8a --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/EducationEntryController.java @@ -0,0 +1,67 @@ +package ru.molokoin.resourceserviceapi.controllers; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import ru.molokoin.resourceserviceapi.entities.EducationEntry; +import ru.molokoin.resourceserviceapi.repositories.EducationEntryFace; + +@RestController +@RequestMapping(path = "/", consumes = {"*/*"}) +public class EducationEntryController { + @Autowired + private EducationEntryFace repo; + + @GetMapping("/education/list") + public ResponseEntity> getEducationEntries(){ + return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); + } + + @GetMapping("/education/{id}") + public ResponseEntity getEducationEntryByID(@PathVariable Integer id){ + return new ResponseEntity<>(repo.findEducationEntryById(id), HttpStatus.OK); + } + + @PostMapping(path = "/education/create", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity saveEducationEntry(@RequestBody EducationEntry educationEntry) { + repo.save(educationEntry); + return new ResponseEntity<>(educationEntry, HttpStatus.CREATED); + } + + @PutMapping(path = "/education/update/{id}", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity updateProgram(@PathVariable Integer id, @RequestBody EducationEntry educationEntry) { + EducationEntry ee = repo.findEducationEntryById(id); + ee.setSertificate_number(educationEntry.getSertificate_number()); + ee.setFrdo_number(educationEntry.getFrdo_number()); + ee.setEisot_number(educationEntry.getEisot_number()); + ee.setOnes(educationEntry.getOnes()); + ee.setCourse(educationEntry.getCourse()); + ee.setStudent(educationEntry.getStudent()); + repo.save(ee); + return new ResponseEntity<>(repo.findEducationEntryById(id), HttpStatus.CREATED); + } + + @DeleteMapping("/education/delete/{id}") + public ResponseEntity deleteProgram(@PathVariable Long id){ + EducationEntry ee = repo.findEducationEntryById(id); + System.out.println(ee.toString()); + repo.delete(ee); + return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); + } +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/EducationEntry.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/EducationEntry.java new file mode 100644 index 0000000..e9e9c29 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/EducationEntry.java @@ -0,0 +1,36 @@ +package ru.molokoin.resourceserviceapi.entities; + +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Data +public class EducationEntry { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private long id; + private String sertificate_number;//Номер удостоверения + private String frdo_number;//ФРДО номер по реестру + private String eisot_number;//ЕИСОТ номер по реестру + private String ones;//Единички (вспомогатльный столбец) + + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.SET_NULL) + private Course course;//Сведения о курсе + + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.SET_NULL) + private Student student;//Сведения о студенте +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/EducationEntryFace.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/EducationEntryFace.java new file mode 100644 index 0000000..946075a --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/EducationEntryFace.java @@ -0,0 +1,12 @@ +package ru.molokoin.resourceserviceapi.repositories; + +import java.util.List; + +import org.springframework.data.repository.ListCrudRepository; + +import ru.molokoin.resourceserviceapi.entities.EducationEntry; + +public interface EducationEntryFace extends ListCrudRepository{ + List findAll(); + EducationEntry findEducationEntryById(long id); +}