esoe 7 months ago
parent
commit
8421f3fa53
  1. 39
      client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/TeachersController.java
  2. 44
      client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Teacher.java
  3. 1
      client-service-teachers/src/main/resources/static/teachers.md
  4. 0
      client-service-teachers/src/main/resources/templates/index.html
  5. 24
      client-service-teachers/src/main/resources/templates/teachers.html

39
client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/TeachersController.java

@ -1,20 +1,36 @@
package ru.molokoin.clientserviceteachers.controllers; 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.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; 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.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; 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 = "/") @RequestMapping(path = "/")
public class TeachersController { public class TeachersController {
@GetMapping("/teachers") @GetMapping("/teachers/resend")
public String info(){ public String infoResend(){
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN); 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); restTemplate.exchange("http://resource-service-api:8181/teacher/list", HttpMethod.GET, httpEntity, String.class);
return response.getBody(); 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<String> response =
restTemplate.exchange("http://resource-service-api:8181/teacher/list", HttpMethod.GET, null, String.class);
String json = response.getBody();
ObjectMapper objectMapper = new ObjectMapper();
List<Teacher> teachers = objectMapper.readValue(json, new TypeReference<List<Teacher>>() {});
model.addAttribute("teachers", teachers);
return "teachers";
}
} }

44
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;
}
}

1
client-service-teachers/src/main/resources/static/teachers.md

@ -0,0 +1 @@
# teachers.md

0
client-service-teachers/src/main/resources/templates/index.html

24
client-service-teachers/src/main/resources/templates/teachers.html

@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>Teacher</title>
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script>
</head>
<body>
<zero-md th:src="@{/teachers.md}"></zero-md>
<br><br>
<!-- <span th:text="${teacher.id}"></span>
<br><br>
<span th:text="${teacher.first_name}"></span> -->
<tbody>
<tr th:each="teacher: ${teachers}">
<td th:text="${teacher.id}" />
<td th:text="${teacher.first_name}" />
</tr>
</tbody>
</body>
</html>
Loading…
Cancel
Save