esoe
6 months ago
13 changed files with 469 additions and 10 deletions
@ -0,0 +1,153 @@
@@ -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.Organization; |
||||
import ru.molokoin.clientserviceteachers.entities.Student; |
||||
|
||||
@Controller |
||||
@RequestMapping(path = "/") |
||||
public class StudentController { |
||||
@Autowired |
||||
private WebClient client; |
||||
|
||||
@GetMapping("/students") |
||||
public String studentList(Model model) throws JsonMappingException, JsonProcessingException{ |
||||
List<Student> students = client.method(HttpMethod.GET) |
||||
.uri("/student/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Student>>(){}) |
||||
.block(); |
||||
|
||||
model.addAttribute("students", students); |
||||
model.addAttribute("stu", new Student()); |
||||
System.out.println("STUDENTS:" + students.toString()); |
||||
return "students"; |
||||
} |
||||
|
||||
@GetMapping("/student-edit/{id}") |
||||
public String studentById(Model model, @PathVariable Long id) { |
||||
/** |
||||
* получение списка организаций из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Organization> orgs = client.get() |
||||
.uri("/organization/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Organization>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("orgs", orgs); |
||||
|
||||
/** |
||||
* Получение сведений о студенте из ресурсов |
||||
*/ |
||||
Student stu = client.get() |
||||
.uri("/student/" + id) |
||||
.retrieve() |
||||
.bodyToMono(Student.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("student", stu); |
||||
return "student-edit"; |
||||
} |
||||
|
||||
@PostMapping( |
||||
path = "/student/add", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String addStudent(Model model, @ModelAttribute("student") @Validated Student stu) throws JsonMappingException, JsonProcessingException{ |
||||
/** |
||||
* получение списка организаций из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Organization> orgs = client.get() |
||||
.uri("/organization/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Organization>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("orgs", orgs); |
||||
|
||||
client.post() |
||||
.uri("/student/create") |
||||
.body(Mono.just(stu), Student.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/students"; |
||||
} |
||||
|
||||
@GetMapping(path = "/student/add") |
||||
public String addStudentFrame(Model model){ |
||||
/** |
||||
* получение списка организаций из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Organization> orgs = client.get() |
||||
.uri("/organization/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Organization>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("orgs", orgs); |
||||
|
||||
/** |
||||
* Создание нового объекта, для последующего заполнения данными из формы |
||||
*/ |
||||
Student student = new Student(); |
||||
model.addAttribute("newStudent", student); |
||||
return "student-add"; |
||||
} |
||||
|
||||
@GetMapping(path = "/student/delete/{id}") |
||||
public String deleteStudent(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ |
||||
client.delete() |
||||
.uri("/student/delete/" + id) |
||||
.retrieve() |
||||
.bodyToMono(String.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/students"; |
||||
} |
||||
|
||||
@PostMapping( |
||||
path = "/student/update/{id}", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String updateStudent(@PathVariable Long id |
||||
, @ModelAttribute("stu") @Validated Student student) throws JsonMappingException, JsonProcessingException{ |
||||
client.post() |
||||
.uri("/student/update/" + student.getId()) |
||||
.body(Mono.just(student), Student.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/students"; |
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
package ru.molokoin.clientserviceteachers.entities; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Data |
||||
public class Student implements Serializable{ |
||||
private long id; |
||||
private String first_name;//Имя
|
||||
private String second_name;//Отчество
|
||||
private String last_name;//Фамилия
|
||||
private String profession;//Профессия
|
||||
private String category;//Категория (ИТР или рабочий)
|
||||
private String direction;//Структурное подразделение
|
||||
private String snils;//СНИЛС
|
||||
private Date berth;//Дата рождения
|
||||
private String sitizenship;//Гражданство
|
||||
private String sex;//Пол (Муж/Жен)
|
||||
private Organization organization;//Организация - работодатель
|
||||
|
||||
/** |
||||
* Конструктор со всеми полями сущности кроме id |
||||
* @param first_name |
||||
* @param second_name |
||||
* @param last_name |
||||
* @param profession |
||||
* @param category |
||||
* @param direction |
||||
* @param snils |
||||
* @param berth |
||||
* @param sitizenship |
||||
* @param sex |
||||
* @param organization |
||||
*/ |
||||
public Student(String first_name, String second_name, String last_name, String profession, String category, |
||||
String direction, String snils, Date berth, String sitizenship, String sex, Organization organization) { |
||||
this.first_name = first_name; |
||||
this.second_name = second_name; |
||||
this.last_name = last_name; |
||||
this.profession = profession; |
||||
this.category = category; |
||||
this.direction = direction; |
||||
this.snils = snils; |
||||
this.berth = berth; |
||||
this.sitizenship = sitizenship; |
||||
this.sex = sex; |
||||
this.organization = organization; |
||||
} |
||||
} |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Student-add</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> |
||||
<header> |
||||
add : student |
||||
</header> |
||||
<main> |
||||
<h2>Добавление сведений о суденте:</h2> |
||||
<form th:action="@{/student/add}" method="post" th:object="${newStudent}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${newStudent.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Имя: </label> |
||||
<input type="text" th:field="${newStudent.first_name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Отчество: </label> |
||||
<input type="text" th:field="${newStudent.second_name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Фамилия: </label> |
||||
<input type="text" th:field="${newStudent.last_name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Профессия: </label> |
||||
<input type="text" th:field="${newStudent.profession}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Категория работника (ИТР/рабочий): </label> |
||||
<input type="text" th:field="${newStudent.category}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Структурное подразделение: </label> |
||||
<input type="text" th:field="${newStudent.direction}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>СИЛС: </label> |
||||
<input type="text" th:field="${newStudent.snils}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Дата рождения: </label> |
||||
<input type="date" th:field="${newStudent.berth}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Гражданство: </label> |
||||
<input type="text" th:field="${newStudent.sitizenship}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Пол: </label> |
||||
<input type="text" th:field="${newStudent.sex}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Организация:</label> |
||||
<select th:field="${newStudent.organization.id}"> |
||||
<option value="0" disabled >выберите организацию</option> |
||||
<option th:each="option : ${orgs}" th:value="${option.id}" th:text="${option.name_short}"></option> |
||||
</select> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/students}" th:method="get"> |
||||
<input type="submit" value="ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
</main> |
||||
</body> |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Student-edit</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> |
||||
<header> |
||||
edit : student |
||||
</header> |
||||
<main> |
||||
<h2>Редактирование сведений о студенте:</h2> |
||||
<form th:action="@{/student/add}" method="post" th:object="${student}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${student.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Имя: </label> |
||||
<input type="text" th:field="${student.first_name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Отчество: </label> |
||||
<input type="text" th:field="${student.second_name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Фамилия: </label> |
||||
<input type="text" th:field="${student.last_name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Профессия: </label> |
||||
<input type="text" th:field="${student.profession}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Категория (ИТР или рабочий): </label> |
||||
<input type="text" th:field="${student.category}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Структурное подразделение: </label> |
||||
<input type="text" th:field="${student.direction}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>СНИЛС: </label> |
||||
<input type="text" th:field="${student.snils}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Дата рождения: </label> |
||||
<input type="date" th:field="${student.berth}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Гражданство: </label> |
||||
<input type="text" th:field="${student.sitizenship}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Пол (Муж/Жен): </label> |
||||
<input type="text" th:field="${student.sex}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Организация - работодатель: </label> |
||||
<select th:field="${student.organization.id}"> |
||||
<option value="0" disabled >выберите организацию</option> |
||||
<option th:each="option : ${orgs}" th:value="${option.id}" th:text="${option.name_short}"></option> |
||||
</select> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/students}" th:method="get"> |
||||
<input type="submit" value="ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
</main> |
||||
</body> |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Students</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> |
||||
<header> |
||||
<h1>Students</h1> |
||||
menu : auth : Students |
||||
<br> |
||||
</header> |
||||
<main> |
||||
<div class="main-wraper"> |
||||
<h2>Перечень студентов:</h2> |
||||
<form th:action="@{/students}" method="get" th:object="${stu}"></form> |
||||
<table> |
||||
<thead> |
||||
<tr> |
||||
<th>id</th> |
||||
<th>first_name</th> |
||||
<th>second_name</th> |
||||
<th>last_name</th> |
||||
<th>profession</th> |
||||
<th>category</th> |
||||
<th>direction</th> |
||||
<th>snils</th> |
||||
<th>berth</th> |
||||
<th>sitizenship</th> |
||||
<th>sex</th> |
||||
<th>organization</th> |
||||
<th> |
||||
<!-- Переход на страницу добавления записи о новом студенте --> |
||||
<form th:action="@{/student/add}" th:method="get"> |
||||
<input type="submit" value="ADD --|>"/> |
||||
</form> |
||||
</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr th:each="stu: ${students}"> |
||||
<td> |
||||
<input type="text" id="id" name="id" th:value="${stu.id}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="first_name" name="first_name" th:value="${stu.first_name}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="second_name" name="second_name" th:value="${stu.second_name}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="last_name" name="last_name" th:value="${stu.last_name}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="profession" name="profession" th:value="${stu.profession}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="category" name="category" th:value="${stu.category}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="direction" name="direction" th:value="${stu.direction}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="snils" name="snils" th:value="${stu.snils}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="berth" name="berth" th:value="${stu.berth}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="sitizenship" name="sitizenship" th:value="${stu.sitizenship}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="sex" name="sex" th:value="${stu.sex}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="organization" name="organization" th:value="${stu.organization.name_short}" readonly /> |
||||
</td> |
||||
<td> |
||||
<form th:action="@{student-edit/{id}(id=${stu.id})}" th:method="get"> |
||||
<input type="submit" value="--|>"/> |
||||
</form> |
||||
<form th:action="@{/student/delete/{id}(id=${stu.id})}" th:method="get"> |
||||
<input type="submit" value="X"/> |
||||
</form> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</table> |
||||
</div> |
||||
</main> |
||||
|
||||
</body> |
||||
</html> |
After Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
Loading…
Reference in new issue