diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/config/WebConfig.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/config/WebConfig.java index 89f9300..1d8564c 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/config/WebConfig.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/config/WebConfig.java @@ -2,18 +2,14 @@ package ru.molokoin.clientserviceteachers.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; import org.springframework.web.reactive.function.client.WebClient; @Configuration public class WebConfig { @Bean - public WebClient webClient() { + WebClient webClient() { WebClient webClient = WebClient.builder() .baseUrl("http://resource-service-api:8181") - // .defaultCookie("cookie-name", "cookie-value") - // .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .build(); return webClient; } 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 dc473f4..b10b958 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,18 +1,12 @@ package ru.molokoin.clientserviceteachers.controllers; -import java.net.URI; import java.time.Duration; -import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.annotation.Validated; @@ -20,95 +14,65 @@ import org.springframework.web.bind.annotation.DeleteMapping; 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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.reactive.function.BodyInserters; -import org.springframework.web.reactive.function.client.ClientRequest; -import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClientResponseException; 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 reactor.core.publisher.Mono; import ru.molokoin.clientserviceteachers.entities.Teacher; -import ru.molokoin.clientserviceteachers.services.TeacherService; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; + @Controller @RequestMapping(path = "/") public class TeachersController { @Autowired - WebClient client; + private WebClient client; - // @GetMapping("/teachers/resend") - // public String infoResend(){ - // RestTemplate restTemplate = new RestTemplate(); - // HttpHeaders headers = new HttpHeaders(); - // headers.setContentType(MediaType.TEXT_PLAIN); - // HttpEntity httpEntity = new HttpEntity<>(headers); - - // ResponseEntity response = - // restTemplate.exchange("http://resource-service-api:8181/teacher/list", HttpMethod.GET, httpEntity, String.class); - // return response.getBody(); - // } - @GetMapping("/teachers") - public String listThy(Model model, @ModelAttribute("teachers") @Validated List teachers) throws JsonMappingException, JsonProcessingException{ - String json = client.method(HttpMethod.GET) + public String teacherList(Model model) throws JsonMappingException, JsonProcessingException{ + // ModelAndView mav = new ModelAndView("teachers"); + + List teachers = client.method(HttpMethod.GET) .uri("/teacher/list") .retrieve() - .bodyToMono(String.class) + .bodyToMono(new ParameterizedTypeReference >(){}) .block(); - System.out.println("############################################################################"); - System.out.println("############################################################################"); - System.out.println("json :" + json); - - ObjectMapper objectMapper = new ObjectMapper(); - teachers = objectMapper.readValue(json, new TypeReference>() {}); - model.addAttribute("teachers", teachers); + + model.addAttribute("teacher_list", teachers); + model.addAttribute("t", new Teacher()); + // mav.addObject("teacher_list", teachers); + // mav.addObject("t", new Teacher()); + // mav.addObject("teacher", new Teacher()); System.out.println("TEACHERS:" + teachers.toString()); return "teachers"; + // return mav; } + /** - * сохранение записи о новом преподавателе: - * - подготовка сущности записи - * - преобразование записи в json - * - отправка post запроса на сервис-ресурсов - * - * @param entity + * Вывод сведений о преподавателе + * @param model + * @param id * @return - * @throws JsonProcessingException */ - // @PostMapping(path = "/teacher/create", - // consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE}) - // public String postMethodName(@RequestBody Teacher teacher) throws JsonProcessingException { - // String url = "http://resource-service-api:8181/teacher/create"; - // // model.addAttribute("teacher", teacher); - // RestTemplate restTemplate = new RestTemplate(); - // // HttpHeaders headers = new HttpHeaders(); - // // headers.setContentType(MediaType.APPLICATION_JSON); - // ObjectMapper objectMapper = new ObjectMapper(); - // String json = objectMapper.writeValueAsString(teacher); - // System.out.println("СООБЩЕНИЕ ИЗ СЕРВИСА-КЛИЕНТОВ:"); - // System.out.println(json); - // // ResponseEntity response = - // // restTemplate.postForEntity(url, teacher, Teacher.class); - // restTemplate.postForEntity(url, json, String.class); - // return "teachers"; - // } + @GetMapping("/teacher-edit/{id}") + public String teacherById(Model model, @PathVariable Long id) { + Teacher t = client.get() + .uri("/teacher/" + id) + .retrieve() + .bodyToMono(Teacher.class) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("teacher", t); + // System.out.println("TEACHERS:" + t.toString()); + return "teacher-edit"; + } + /** * Добавление сведений о преподавателе: @@ -119,6 +83,8 @@ public class TeachersController { * - направление пользователя на основную страницу * @param teacher * @return + * @throws JsonProcessingException + * @throws JsonMappingException */ @PostMapping( path = "/teacher/add", @@ -126,7 +92,7 @@ public class TeachersController { produces = { MediaType.APPLICATION_JSON_VALUE }) - public String postTeacher(@ModelAttribute("teacher") @Validated Teacher teacher){ + public String addTeacher(@ModelAttribute("t") @Validated Teacher teacher) throws JsonMappingException, JsonProcessingException{ client.post() .uri("/teacher/create") .body(Mono.just(teacher), Teacher.class) @@ -135,34 +101,48 @@ public class TeachersController { .timeout(Duration.ofSeconds(1)) .block(); return "redirect:/teachers"; + // return teacherList(); + } - // @GetMapping(path = "/teacher/delete/{id}") - // public String deleteTeacherByGet(@PathVariable Long id){ - // client.delete() - // .uri("/teacher/delete/" + id) - // .retrieve() - // // .toBodilessEntity() - // .bodyToMono(String.class) - // .timeout(Duration.ofSeconds(1)) - // // .onErrorResume(e -> Mono.empty()) - // .block(); - // return "redirect:/teachers"; - // } + @GetMapping( + path = "/teacher/add" + ) + public String addTeacherFrame(Model model){ + Teacher teacher = new Teacher(); + model.addAttribute("newTeacher", teacher); + return "teacher-add"; + } - @DeleteMapping(path = "/teacher/delete/{id}") - public String deleteTeacher(@PathVariable Long id){ + /** + * Удаление записи о преподавателе + * @param id + * @return + * @throws JsonProcessingException + * @throws JsonMappingException + */ + @GetMapping(path = "/teacher/delete/{id}") + public String deleteTeacher(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ client.delete() .uri("/teacher/delete/" + id) .retrieve() - // .toBodilessEntity() .bodyToMono(String.class) .timeout(Duration.ofSeconds(1)) - // .onErrorResume(e -> Mono.empty()) .block(); return "redirect:/teachers"; + // return teacherList(); } + /** + * Обновление сведений о преподавателе + * - переделать post на put запрос + * + * @param id + * @param teacher + * @return + * @throws JsonProcessingException + * @throws JsonMappingException + */ @PostMapping( path = "/teacher/update/{id}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, @@ -170,7 +150,7 @@ public class TeachersController { MediaType.APPLICATION_JSON_VALUE }) public String updateTeacher(@PathVariable Long id - , @ModelAttribute("teacher") @Validated Teacher teacher){ + , @ModelAttribute("t") @Validated Teacher teacher) throws JsonMappingException, JsonProcessingException{ System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); System.out.println(">>>>>>>>>>>>>>" + teacher.toString()); @@ -182,5 +162,6 @@ public class TeachersController { .timeout(Duration.ofSeconds(1)) .block(); return "redirect:/teachers"; + // return teacherList(); } } \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/teacher-add.html b/client-service-teachers/src/main/resources/templates/teacher-add.html new file mode 100644 index 0000000..07712f4 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/teacher-add.html @@ -0,0 +1,49 @@ + + + + + Teacher + + + + +
+ edit : teacher +
+
+

Добавление преподавателя:

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

Добавление преподавателя:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/teachers.html b/client-service-teachers/src/main/resources/templates/teachers.html index cb3843f..11b573b 100644 --- a/client-service-teachers/src/main/resources/templates/teachers.html +++ b/client-service-teachers/src/main/resources/templates/teachers.html @@ -3,7 +3,7 @@ xmlns:th="http://www.thymeleaf.org"> - Teacher + Teachers @@ -13,73 +13,59 @@ xmlns:th="http://www.thymeleaf.org">
- -
-

Добавление преподавателя:

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
+ + -

Перечень преподавателей:

- - - - - - - - - - - - - - - - - - - + +
idfirstnamesecondnamelastnameТабельный номерСНИЛСdelete
- - - - - - - - - - - - -
- -
-
- -
-
+ + + + + + + + + + + + + + + + + + + + + + +
idfirstnamesecondnamelastnameТабельный номерСНИЛС +
+ +
+
+ + + + + + + + + + + + +
+ +
+
+ +
+
diff --git a/postgres-service/dockerfile b/postgres-service/dockerfile index 1969c7e..6c369b7 100644 --- a/postgres-service/dockerfile +++ b/postgres-service/dockerfile @@ -4,4 +4,4 @@ LABEL author="esoe" LABEL description="postgres image for tech-services" LABEL version="1.0" -COPY *.sql /docker-entrypoint-initdb.d/ +# COPY *.sql /docker-entrypoint-initdb.d/