esoe
7 months ago
9 changed files with 339 additions and 27 deletions
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
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.ProgramCretarea; |
||||
|
||||
@Controller |
||||
@RequestMapping(path = "/") |
||||
public class ProgramCretareaController { |
||||
@Autowired |
||||
private WebClient client; |
||||
|
||||
@GetMapping("/program-cretareas") |
||||
public String programCretareaList(Model model) throws JsonMappingException, JsonProcessingException{ |
||||
List<ProgramCretarea> cretareas = client |
||||
.method(HttpMethod.GET) |
||||
.uri("/cretarea/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<ProgramCretarea>>(){}) |
||||
.block(); |
||||
|
||||
model.addAttribute("program_cretarea_list", cretareas); |
||||
model.addAttribute("pc", new ProgramCretarea()); |
||||
System.out.println("PROGRAM-CRETAREAS:" + cretareas.toString()); |
||||
return "program-cretareas"; |
||||
} |
||||
|
||||
@GetMapping("/program-cretarea-edit/{id}") |
||||
public String teacherById(Model model, @PathVariable Long id) { |
||||
ProgramCretarea pc = client.get() |
||||
.uri("/cretarea/" + id) |
||||
.retrieve() |
||||
.bodyToMono(ProgramCretarea.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("program-cretarea", pc); |
||||
return "program-cretarea-edit"; |
||||
} |
||||
|
||||
/** |
||||
* Добавление нового критерия |
||||
* и переход на страницу списка критериев |
||||
* |
||||
* @param pc |
||||
* @return |
||||
* @throws JsonMappingException |
||||
* @throws JsonProcessingException |
||||
*/ |
||||
@PostMapping( |
||||
path = "/program-cretarea/add", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String addTeacher(@ModelAttribute("program-cretarea") @Validated ProgramCretarea pc) throws JsonMappingException, JsonProcessingException{ |
||||
client.post() |
||||
.uri("/cretarea/create") |
||||
.body(Mono.just(pc), ProgramCretarea.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/program-cretareas"; |
||||
} |
||||
|
||||
/** |
||||
* Переход на страницу добавления нового критерия |
||||
* @param model |
||||
* @return |
||||
*/ |
||||
@GetMapping(path = "/program-cretarea/add") |
||||
public String addTeacherFrame(Model model){ |
||||
ProgramCretarea cretarea = new ProgramCretarea(); |
||||
model.addAttribute("newCretarea", cretarea); |
||||
return "program-cretarea-add"; |
||||
} |
||||
|
||||
/** |
||||
* Удаление критерия по id |
||||
* @param id |
||||
* @return |
||||
* @throws JsonProcessingException |
||||
* @throws JsonMappingException |
||||
*/ |
||||
@GetMapping(path = "/program-cretarea/delete/{id}") |
||||
public String deleteTeacher(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ |
||||
String message = client.delete() |
||||
.uri("/cretarea/delete/" + id) |
||||
.retrieve() |
||||
.bodyToMono(String.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
System.out.println("##########################################"); |
||||
System.out.println("##########################################"); |
||||
System.out.println("DELETE-MESAGE# " + message); |
||||
return "redirect:/program-cretarias"; |
||||
} |
||||
|
||||
/** |
||||
* Обновление сведений о критерии |
||||
* - переделать post на put запрос |
||||
* |
||||
* @param id |
||||
* @param cretarea |
||||
* @return |
||||
* @throws JsonProcessingException |
||||
* @throws JsonMappingException |
||||
*/ |
||||
@PostMapping( |
||||
path = "/cretarea/update/{id}", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String updateTeacher(@PathVariable Long id |
||||
, @ModelAttribute("pc") @Validated ProgramCretarea cretarea) throws JsonMappingException, JsonProcessingException{ |
||||
client.post() |
||||
.uri("/teacher/update/" + cretarea.getId()) |
||||
.body(Mono.just(cretarea), ProgramCretarea.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/program-cretareas"; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
package ru.molokoin.clientserviceteachers.entities; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Data |
||||
public class ProgramCretarea implements Serializable{ |
||||
private long id; |
||||
private String name;//Наименование
|
||||
private String name_short;//Наименование : сокращенно
|
||||
|
||||
/** |
||||
* подготовить конструкторы на все варианты внесения информации о преподавателях |
||||
* |
||||
* @param name |
||||
* @param name_short |
||||
*/ |
||||
public ProgramCretarea(String name, String name_short) { |
||||
this.name = name; |
||||
this.name_short = name_short; |
||||
} |
||||
|
||||
} |
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
package ru.molokoin.clientserviceteachers.services; |
||||
|
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.web.reactive.function.client.WebClient; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import reactor.core.publisher.Mono; |
||||
import ru.molokoin.clientserviceteachers.entities.Teacher; |
||||
|
||||
@Service |
||||
@AllArgsConstructor |
||||
public class TeacherService { |
||||
private final WebClient webClient; |
||||
|
||||
public Mono<Teacher> getTeacherByIdAsync(final String id){ |
||||
return webClient |
||||
.get() |
||||
.uri(String.join("", "/teacher/", id)) |
||||
.retrieve() |
||||
.bodyToMono(Teacher.class); |
||||
} |
||||
} |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Cretarea</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 : cretarea |
||||
</header> |
||||
<main> |
||||
<h2>Добавление нового критерия:</h2> |
||||
<form th:action="@{/program-cretarea/add}" method="post" th:object="${newCretarea}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${newCretarea.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Наименование: </label> |
||||
<input type="text" th:field="${newCretarea.name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Сокращенно: </label> |
||||
<input type="text" th:field="${newCretarea.name_short}" placeholder="" /> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/program-cretareas}" th:method="get"> |
||||
<input type="submit" value="ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
</main> |
||||
</body> |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
<!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> |
||||
<header> |
||||
edit : program-cretarea |
||||
</header> |
||||
<main> |
||||
<h2>Добавление критерия:</h2> |
||||
<form th:action="@{/program-cretarea/add}" method="post" th:object="${pc}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${program-cretarea.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Фамилия: </label> |
||||
<input type="text" th:field="${program-cretarea.name}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Имя: </label> |
||||
<input type="text" th:field="${program-cretarea.name_short}" placeholder="" /> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/program-cretareas}" th:method="get"> |
||||
<input type="submit" value="ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
</main> |
||||
</body> |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Cretareas</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>PROGRAM-CRETAREAS</h1> |
||||
menu : auth : title |
||||
<br> |
||||
</header> |
||||
<main> |
||||
<div class="main-wraper"> |
||||
<h2>Перечень критериев:</h2> |
||||
<form th:action="@{/program-cretareas}" method="get" th:object="${pc}"></form> |
||||
<table> |
||||
<thead> |
||||
<tr> |
||||
<th>id</th> |
||||
<th>НАИМЕНОВАНИЕ</th> |
||||
<th>КРАТКО</th> |
||||
<th> |
||||
<form th:action="@{/program-cretarea/add}" th:method="get"> |
||||
<input type="submit" value="ADD --|>"/> |
||||
</form> |
||||
</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr th:each="pc: ${program_cretarea_list}"> |
||||
<td> |
||||
<input type="text" id="id" name="id" th:value="${pc.id}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="name" name="name" th:value="${pc.name}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="name_short" name="name_short" th:value="${pc.name_short}" readonly /> |
||||
</td> |
||||
<td> |
||||
<form th:action="@{program-cretarea-edit/{id}(id=${pc.id})}" th:method="get"> |
||||
<input type="submit" value="--|>"/> |
||||
</form> |
||||
<form th:action="@{/program-cretarea/delete/{id}(id=${pc.id})}" th:method="get"> |
||||
<input type="submit" value="X"/> |
||||
</form> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</table> |
||||
</div> |
||||
</main> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue