From 55055776c4387c00b9ccba5fc225baffc5b8eca3 Mon Sep 17 00:00:00 2001 From: esoe Date: Fri, 26 Apr 2024 16:42:54 +0300 Subject: [PATCH] selection in th works! --- .../controllers/ProgramController.java | 153 ++++++++++++++++++ .../ProgramCretareaController.java | 2 +- .../entities/Program.java | 39 +++++ .../main/resources/templates/program-add.html | 57 +++++++ .../resources/templates/program-edit.html | 56 +++++++ .../main/resources/templates/programs.html | 74 +++++++++ .../controllers/ProgramController.java | 68 ++++++++ .../resourceserviceapi/entities/Program.java | 34 ++++ .../repositories/ProgramRepositoryFace.java | 12 ++ 9 files changed, 494 insertions(+), 1 deletion(-) create mode 100644 client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java create mode 100644 client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java create mode 100644 client-service-teachers/src/main/resources/templates/program-add.html create mode 100644 client-service-teachers/src/main/resources/templates/program-edit.html create mode 100644 client-service-teachers/src/main/resources/templates/programs.html create mode 100644 resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java create mode 100644 resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Program.java create mode 100644 resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramRepositoryFace.java diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java new file mode 100644 index 0000000..fd574ad --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java @@ -0,0 +1,153 @@ +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.Program; +import ru.molokoin.clientserviceteachers.entities.ProgramCretarea; + +@Controller +@RequestMapping(path = "/") +public class ProgramController { + @Autowired + private WebClient client; + + @GetMapping("/programs") + public String teacherList(Model model) throws JsonMappingException, JsonProcessingException{ + List programs = client.method(HttpMethod.GET) + .uri("/program/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .block(); + + model.addAttribute("programs", programs); + model.addAttribute("p", new Program()); + System.out.println("PROGRAMS:" + programs.toString()); + return "programs"; + } + + @GetMapping("/program-edit/{id}") + public String teacherById(Model model, @PathVariable Long id) { + /** + * получение критериев из ресурсов + */ + List pcl = client.get() + .uri("/cretarea/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("pcl", pcl); + + /** + * Получение программы из ресурсов + */ + Program p = client.get() + .uri("/program/" + id) + .retrieve() + .bodyToMono(Program.class) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("program", p); + return "program-edit"; + } + + @PostMapping( + path = "/program/add", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String addProgram(Model model, @ModelAttribute("program") @Validated Program p) throws JsonMappingException, JsonProcessingException{ + /** + * получение критериев из ресурсов + */ + List pcl = client.get() + .uri("/cretarea/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("pcl", pcl); + System.out.println("#######PCL#######"); + System.out.println("pcl: " + pcl.toString()); + + client.post() + .uri("/program/create") + .body(Mono.just(p), Program.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/programs"; + } + + @GetMapping(path = "/program/add") + public String addTeacherFrame(Model model){ + /** + * получение критериев из ресурсов + */ + List pcl = client.get() + .uri("/cretarea/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("pcl", pcl); + + Program program = new Program(); + model.addAttribute("newProgram", program); + return "program-add"; + } + + @GetMapping(path = "/program/delete/{id}") + public String deleteTeacher(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ + client.delete() + .uri("/program/delete/" + id) + .retrieve() + .bodyToMono(String.class) + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/programs"; + } + + @PostMapping( + path = "/program/update/{id}", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String updateTeacher(@PathVariable Long id + , @ModelAttribute("p") @Validated Program program) throws JsonMappingException, JsonProcessingException{ + client.post() + .uri("/teacher/update/" + program.getId()) + .body(Mono.just(program), Program.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/programs"; + } + + + +} diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramCretareaController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramCretareaController.java index 47d8a4c..cd7f235 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramCretareaController.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramCretareaController.java @@ -112,7 +112,7 @@ public class ProgramCretareaController { System.out.println("##########################################"); System.out.println("##########################################"); System.out.println("DELETE-MESAGE# " + message); - return "redirect:/program-cretarias"; + return "redirect:/program-cretareas"; } /** diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java new file mode 100644 index 0000000..ede41e6 --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java @@ -0,0 +1,39 @@ +package ru.molokoin.clientserviceteachers.entities; + +import jakarta.annotation.Nullable; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Program { + private long id; + private String name;//Наименование + private Integer lenght;//длительность программы + private String study_direction;//направление обучения: обязательное-производственное (учесть в ограничениях) + private Integer price; + // @Nullable + private ProgramCretarea cretarea; + + /** + * конструктор со всеми полями сущности, за исключением id + * Подготовить все варианты конструкторов + * @param name + * @param lenght + * @param study_direction + * @param price + * @param cretarea + */ + public Program(String name, Integer lenght, String study_direction, Integer price, ProgramCretarea cretarea) { + this.name = name; + this.lenght = lenght; + this.study_direction = study_direction; + this.price = price; + this.cretarea = cretarea; + } + + + +} diff --git a/client-service-teachers/src/main/resources/templates/program-add.html b/client-service-teachers/src/main/resources/templates/program-add.html new file mode 100644 index 0000000..085e82f --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/program-add.html @@ -0,0 +1,57 @@ + + + + + Program-add + + + + +
+ add : program +
+
+

Добавление программы обучения:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + + + + +
+
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/program-edit.html b/client-service-teachers/src/main/resources/templates/program-edit.html new file mode 100644 index 0000000..7c6e367 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/program-edit.html @@ -0,0 +1,56 @@ + + + + + Program-edit + + + + +
+ edit : program +
+
+

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

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

PROGRAMS

+ menu : auth +
+
+
+
+

Перечень программ обучения:

+
+ + + + + + + + + + + + + + + + + + + + + + + +
idnamelenghtstudy_directionpricecretarea + +
+ +
+
+ + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ + + \ No newline at end of file diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java new file mode 100644 index 0000000..eabdaf0 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java @@ -0,0 +1,68 @@ +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.Program; +import ru.molokoin.resourceserviceapi.repositories.ProgramRepositoryFace; + +@RestController +@RequestMapping(path = "/", consumes = {"*/*"}) +public class ProgramController { + @Autowired + private ProgramRepositoryFace repo; + + @GetMapping("/program/list") + public ResponseEntity> getPrograms(){ + return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); + } + + @GetMapping("/program/{id}") + public ResponseEntity getTeacherByID(@PathVariable Integer id){ + return new ResponseEntity<>(repo.findProgramById(id), HttpStatus.OK); + } + + @PostMapping(path = "/program/create", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity saveTeacher(@RequestBody Program program) { + repo.save(program); + return new ResponseEntity<>(program, HttpStatus.CREATED); + } + + @PutMapping(path = "/program/update/{id}", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity updateProgram(@PathVariable Integer id, @RequestBody Program program) { + Program p = repo.findProgramById(id); + p.setName(program.getName()); + p.setLenght(program.getLenght()); + p.setStudy_direction(program.getStudy_direction()); + p.setPrice(program.getPrice()); + p.setCretarea(program.getCretarea()); + repo.save(p); + return new ResponseEntity<>(repo.findProgramById(id), HttpStatus.CREATED); + } + + @DeleteMapping("/program/delete/{id}") + public ResponseEntity deleteCretarea(@PathVariable Long id){ + Program p = repo.findProgramById(id); + System.out.println(p.toString()); + repo.delete(p); + return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); + } + + +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Program.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Program.java new file mode 100644 index 0000000..ef73760 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Program.java @@ -0,0 +1,34 @@ +package ru.molokoin.resourceserviceapi.entities; + +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import jakarta.annotation.Nullable; +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 Program { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private long id; + private String name;//Наименование + private Integer lenght;//длительность программы + private String study_direction;//направление обучения: обязательное-производственное (учесть в ограничениях) + private Integer price; + + @ManyToOne(fetch = FetchType.EAGER, optional = false) + @OnDelete(action = OnDeleteAction.SET_NULL) + // @Nullable + private ProgramCretarea cretarea; +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramRepositoryFace.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramRepositoryFace.java new file mode 100644 index 0000000..0ac2dcf --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramRepositoryFace.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.Program; + +public interface ProgramRepositoryFace extends ListCrudRepository{ + List findAll(); + Program findProgramById(long id); +}