esoe
6 months ago
11 changed files with 329 additions and 5 deletions
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
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.Building; |
||||
import ru.molokoin.clientserviceteachers.entities.Teacher; |
||||
|
||||
@Controller |
||||
@RequestMapping(path = "/") |
||||
public class BuildingController { |
||||
@Autowired |
||||
private WebClient client; |
||||
|
||||
@GetMapping("/buildings") |
||||
public String buildingList(Model model) throws JsonMappingException, JsonProcessingException{ |
||||
List<Building> buildings = client.method(HttpMethod.GET) |
||||
.uri("/building/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Building>>(){}) |
||||
.block(); |
||||
|
||||
model.addAttribute("building_list", buildings); |
||||
model.addAttribute("b", new Building()); |
||||
System.out.println("BUILDINGS:" + buildings.toString()); |
||||
return "buildings"; |
||||
} |
||||
|
||||
@GetMapping("/building-edit/{id}") |
||||
public String buildingById(Model model, @PathVariable Long id) { |
||||
Building b = client.get() |
||||
.uri("/building/" + id) |
||||
.retrieve() |
||||
.bodyToMono(Building.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("building", b); |
||||
return "building-edit"; |
||||
} |
||||
|
||||
@PostMapping( |
||||
path = "/building/add", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String addBuilding(@ModelAttribute("b") @Validated Building building) throws JsonMappingException, JsonProcessingException{ |
||||
client.post() |
||||
.uri("/building/create") |
||||
.body(Mono.just(building), Building.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/buildings"; |
||||
} |
||||
|
||||
@GetMapping( |
||||
path = "/building/add" |
||||
) |
||||
public String addBuildingFrame(Model model){ |
||||
Building building = new Building(); |
||||
model.addAttribute("newBuilding", building); |
||||
return "building-add"; |
||||
} |
||||
|
||||
@GetMapping(path = "/building/delete/{id}") |
||||
public String deleteBuilding(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ |
||||
client.delete() |
||||
.uri("/building/delete/" + id) |
||||
.retrieve() |
||||
.bodyToMono(String.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/buildings"; |
||||
} |
||||
|
||||
@PostMapping( |
||||
path = "/building/update/{id}", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String updateTeacher(@PathVariable Long id |
||||
, @ModelAttribute("b") @Validated Building building) throws JsonMappingException, JsonProcessingException{ |
||||
System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); |
||||
System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); |
||||
System.out.println(">>>>>>>>>>>>>>" + building.toString()); |
||||
client.post() |
||||
.uri("/building/update/" + building.getId()) |
||||
.body(Mono.just(building), Building.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/buildings"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
package ru.molokoin.clientserviceteachers.entities; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* Сущность объекта строительства |
||||
*/ |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Data |
||||
public class Building implements Serializable{ |
||||
private long id; |
||||
private String name_short;//Сокращенное наименование
|
||||
private String name_full;//Полное наименование
|
||||
private String code_short;//Краткий код
|
||||
private String code_full;//Полный код
|
||||
|
||||
// подготовить конструкторы на все варианты внесения информации о преподавателях
|
||||
public Building(String name_short, String name_full, String code_short, String code_full){ |
||||
this.name_short = name_short; |
||||
this.name_full = name_full; |
||||
this.code_short = code_short; |
||||
this.code_full = code_full; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Building</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 : building |
||||
</header> |
||||
<main> |
||||
<h2>Добавление нового объекта строительства:</h2> |
||||
<form th:action="@{/building/add}" method="post" th:object="${newBuilding}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${newBuilding.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Наименование полное: </label> |
||||
<input type="text" th:field="${newBuilding.name_full}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Наименование сокращенно: </label> |
||||
<input type="text" th:field="${newBuilding.name_short}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Кодовое обозначение полное: </label> |
||||
<input type="text" th:field="${newBuilding.code_full}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Кодовое обозначение сокращенно: </label> |
||||
<input type="text" th:field="${newBuilding.code_short}" placeholder="" /> |
||||
</div> |
||||
|
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/buildings}" th:method="get"> |
||||
<input type="submit" value="ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
</main> |
||||
</body> |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Buildings</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 : building |
||||
</header> |
||||
<main> |
||||
<h2>Редактирование сведений об объекте строительства:</h2> |
||||
<form th:action="@{/building/add}" method="post" th:object="${b}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${building.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Наименование полное: </label> |
||||
<input type="text" th:field="${building.name_full}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Наименование сокращенно: </label> |
||||
<input type="text" th:field="${building.name_short}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Кодовое обозначение полное: </label> |
||||
<input type="text" th:field="${building.code_full}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Кодовое обозначение сокращенно: </label> |
||||
<input type="text" th:field="${building.code_short}" placeholder="" /> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/buildings}" th:method="get"> |
||||
<input type="submit" value="ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
</main> |
||||
</body> |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>Buildings</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>BUILDINGS</h1> |
||||
menu : auth : buildings |
||||
<br> |
||||
</header> |
||||
<main> |
||||
<div class="main-wraper"> |
||||
<!-- Вывод сведений о приложении из *.md файла (client-service-teachers\src\main\resources\static\teachers.md) --> |
||||
<!-- <zero-md th:src="@{/teachers.md}"></zero-md> |
||||
<br> --> |
||||
|
||||
<h2>Перечень объектов строительства:</h2> |
||||
<form th:action="@{/buildings}" method="get" th:object="${b}"></form> |
||||
<table> |
||||
<thead> |
||||
<tr> |
||||
<th>id</th> |
||||
<th>name_short</th> |
||||
<th>name_full</th> |
||||
<th>code_short</th> |
||||
<th>code_full</th> |
||||
<th> |
||||
<form th:action="@{/building/add}" th:method="get"> |
||||
<input type="submit" value="ADD --|>"/> |
||||
</form> |
||||
</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr th:each="b: ${building_list}"> |
||||
<td> |
||||
<input type="text" id="id" name="id" th:value="${b.id}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="name_short" name="name_short" th:value="${b.name_short}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="name_full" name="name_full" th:value="${b.name_full}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="code_short" name="code_short" th:value="${b.code_short}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="code_full" name="code_full" th:value="${b.code_full}" readonly /> |
||||
</td> |
||||
<td> |
||||
<form th:action="@{building-edit/{id}(id=${b.id})}" th:method="get"> |
||||
<input type="submit" value="--|>"/> |
||||
</form> |
||||
<form th:action="@{/building/delete/{id}(id=${b.id})}" th:method="get"> |
||||
<input type="submit" value="X"/> |
||||
</form> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</table> |
||||
</div> |
||||
</main> |
||||
</body> |
||||
</html> |
Before Width: | Height: | Size: 205 KiB |
Before Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 205 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
Loading…
Reference in new issue