From 8421f3fa5341a184852d67f7300f04ea6df3c775 Mon Sep 17 00:00:00 2001 From: esoe Date: Fri, 12 Apr 2024 16:54:53 +0300 Subject: [PATCH] qqq --- .../controllers/TeachersController.java | 39 ++++++++++++++-- .../entities/Teacher.java | 44 +++++++++++++++++++ .../src/main/resources/static/teachers.md | 1 + .../src/main/resources/templates/index.html | 0 .../main/resources/templates/teachers.html | 24 ++++++++++ 5 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Teacher.java create mode 100644 client-service-teachers/src/main/resources/static/teachers.md create mode 100644 client-service-teachers/src/main/resources/templates/index.html create mode 100644 client-service-teachers/src/main/resources/templates/teachers.html diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/TeachersController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/TeachersController.java index ee2fbbc..bc78991 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/TeachersController.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/TeachersController.java @@ -1,20 +1,36 @@ package ru.molokoin.clientserviceteachers.controllers; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; -@RestController +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import jakarta.servlet.http.HttpServletRequest; +import ru.molokoin.clientserviceteachers.entities.Teacher; + +@Controller @RequestMapping(path = "/") public class TeachersController { - @GetMapping("/teachers") - public String info(){ + @GetMapping("/teachers/resend") + public String infoResend(){ RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); @@ -24,4 +40,21 @@ public class TeachersController { restTemplate.exchange("http://resource-service-api:8181/teacher/list", HttpMethod.GET, httpEntity, String.class); return response.getBody(); } + + @GetMapping("/teachers") + public String listThy(Model model) throws JsonMappingException, JsonProcessingException{ + Teacher teacher = new Teacher( + 2, "first_name", "second_name", "last_name", "employee_id", "snils" + ); + model.addAttribute("teacher", teacher); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = + restTemplate.exchange("http://resource-service-api:8181/teacher/list", HttpMethod.GET, null, String.class); + String json = response.getBody(); + ObjectMapper objectMapper = new ObjectMapper(); + List teachers = objectMapper.readValue(json, new TypeReference>() {}); + model.addAttribute("teachers", teachers); + return "teachers"; + } } diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Teacher.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Teacher.java new file mode 100644 index 0000000..9b42e2e --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Teacher.java @@ -0,0 +1,44 @@ +package ru.molokoin.clientserviceteachers.entities; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Сущьность преподавателя + * добавить данные: + * - телефоны (список) + * - эл почты (список) + * - программы которые преподает + * - график работы + * - основное место работы (офис, наимеование ОП) + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Teacher implements Serializable{ + private long id; + private String first_name;//Имя + private String second_name;//Фамилия + private String last_name;//Отчество + private String employee_id; + private String snils; + + // подготовить конструкторы на все варианты внесения информации о преподавателях + public Teacher(String first_name, String second_name, String last_name){ + this.first_name = first_name; + this.second_name = second_name; + this.last_name = last_name; + } + + //конструктор - все аргуметы кроме id + public Teacher(String first_name, String second_name, String last_name, String employee_id, String snils){ + this.first_name = first_name; + this.second_name = second_name; + this.last_name = last_name; + this.employee_id = employee_id; + this.snils = snils; + } +} \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/static/teachers.md b/client-service-teachers/src/main/resources/static/teachers.md new file mode 100644 index 0000000..e3aaae0 --- /dev/null +++ b/client-service-teachers/src/main/resources/static/teachers.md @@ -0,0 +1 @@ +# teachers.md \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/index.html b/client-service-teachers/src/main/resources/templates/index.html new file mode 100644 index 0000000..e69de29 diff --git a/client-service-teachers/src/main/resources/templates/teachers.html b/client-service-teachers/src/main/resources/templates/teachers.html new file mode 100644 index 0000000..3bb9d05 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/teachers.html @@ -0,0 +1,24 @@ + + + + + Teacher + + + + + +

+ + + + + + + + + +