esoe
6 months ago
8 changed files with 543 additions and 0 deletions
@ -0,0 +1,196 @@
@@ -0,0 +1,196 @@
|
||||
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.Course; |
||||
import ru.molokoin.clientserviceteachers.entities.EducatonEntry; |
||||
import ru.molokoin.clientserviceteachers.entities.Program; |
||||
import ru.molokoin.clientserviceteachers.entities.ProgramCretarea; |
||||
import ru.molokoin.clientserviceteachers.entities.Student; |
||||
|
||||
@Controller |
||||
@RequestMapping(path = "/") |
||||
public class EducationEntryController { |
||||
@Autowired |
||||
private WebClient client; |
||||
|
||||
@GetMapping("/educations") |
||||
public String educationEntryList(Model model) throws JsonMappingException, JsonProcessingException{ |
||||
List<EducatonEntry> educations = client.method(HttpMethod.GET) |
||||
.uri("/education/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<EducatonEntry>>(){}) |
||||
.block(); |
||||
|
||||
model.addAttribute("educations", educations); |
||||
model.addAttribute("edu", new EducatonEntry()); |
||||
System.out.println("EDUCATIONS:" + educations.toString()); |
||||
return "educations"; |
||||
} |
||||
|
||||
@GetMapping("/education-edit/{id}") |
||||
public String educationEntryById(Model model, @PathVariable Long id) { |
||||
/** |
||||
* получение списка студентов из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Student> students = client.get() |
||||
.uri("/student/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Student>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("students", students); |
||||
|
||||
/** |
||||
* получение списка курсов из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Course> courses = client.get() |
||||
.uri("/course/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Course>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("courses", courses); |
||||
|
||||
/** |
||||
* Получение данных об обучении из ресурсов |
||||
* - для отображения в форме редактирования |
||||
*/ |
||||
EducatonEntry ee = client.get() |
||||
.uri("/education/" + id) |
||||
.retrieve() |
||||
.bodyToMono(EducatonEntry.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("education", ee); |
||||
return "education-edit"; |
||||
} |
||||
|
||||
@PostMapping( |
||||
path = "/education/add", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String addEducationEntry(Model model, @ModelAttribute("education") @Validated EducatonEntry ee) throws JsonMappingException, JsonProcessingException{ |
||||
/** |
||||
* получение списка студентов из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Student> students = client.get() |
||||
.uri("/student/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Student>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("students", students); |
||||
|
||||
/** |
||||
* получение списка курсов из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Course> courses = client.get() |
||||
.uri("/course/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Course>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("courses", courses); |
||||
|
||||
client.post() |
||||
.uri("/education/create") |
||||
.body(Mono.just(ee), EducatonEntry.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/educations"; |
||||
} |
||||
|
||||
@GetMapping(path = "/education/add") |
||||
public String addProgramFrame(Model model){ |
||||
/** |
||||
* получение списка студентов из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Student> students = client.get() |
||||
.uri("/student/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Student>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("students", students); |
||||
|
||||
/** |
||||
* получение списка курсов из ресурсов |
||||
* - для select поля формы |
||||
*/ |
||||
List<Course> courses = client.get() |
||||
.uri("/course/list") |
||||
.retrieve() |
||||
.bodyToMono(new ParameterizedTypeReference <List<Course>>(){}) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
model.addAttribute("courses", courses); |
||||
|
||||
/** |
||||
* Создание пустого объекта, для передачи в форму для заполнения |
||||
*/ |
||||
EducatonEntry education = new EducatonEntry(); |
||||
model.addAttribute("newEducation", education); |
||||
return "education-add"; |
||||
} |
||||
|
||||
@GetMapping(path = "/education/delete/{id}") |
||||
public String deleteProgram(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ |
||||
client.delete() |
||||
.uri("/education/delete/" + id) |
||||
.retrieve() |
||||
.bodyToMono(String.class) |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/educations"; |
||||
} |
||||
|
||||
@PostMapping( |
||||
path = "/education/update/{id}", |
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
||||
produces = { |
||||
MediaType.APPLICATION_JSON_VALUE |
||||
}) |
||||
public String updateProgram(@PathVariable Long id |
||||
, @ModelAttribute("edu") @Validated EducatonEntry education) throws JsonMappingException, JsonProcessingException{ |
||||
client.post() |
||||
.uri("/education/update/" + education.getId()) |
||||
.body(Mono.just(education), EducatonEntry.class) |
||||
.retrieve() |
||||
.toBodilessEntity() |
||||
.timeout(Duration.ofSeconds(1)) |
||||
.block(); |
||||
return "redirect:/educations"; |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
package ru.molokoin.clientserviceteachers.entities; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Data |
||||
public class EducatonEntry { |
||||
private long id; |
||||
private String sertificate_number;//номер удостоверения
|
||||
private String frdo_number;//ФРДО номер по реестру
|
||||
private String eisot_number;//ЕИСОТ номер по реестру
|
||||
private String ones;//единички (вспомогатльный столбец)
|
||||
private Course course;//сведения о курсе
|
||||
private Student student;//сведения о студенте
|
||||
|
||||
/** |
||||
* Конструктор без id |
||||
* @param sertificate_number |
||||
* @param frdo_number |
||||
* @param eisot_number |
||||
* @param ones |
||||
* @param course |
||||
* @param student |
||||
*/ |
||||
public EducatonEntry(String sertificate_number, String frdo_number, String eisot_number, String ones, |
||||
Course course, Student student) { |
||||
this.sertificate_number = sertificate_number; |
||||
this.frdo_number = frdo_number; |
||||
this.eisot_number = eisot_number; |
||||
this.ones = ones; |
||||
this.course = course; |
||||
this.student = student; |
||||
} |
||||
|
||||
} |
@ -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>Education-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 : Education |
||||
</header> |
||||
<main> |
||||
<h2>Добавление обучения:</h2> |
||||
<form th:action="@{/education/add}" method="post" th:object="${newEducation}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${newEducation.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Номер удостоверения: </label> |
||||
<input type="text" th:field="${newEducation.sertificate_number}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>ФРДО номер по реестру: </label> |
||||
<input type="text" th:field="${newEducation.frdo_number}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>ЕИСОТ номер по реестру: </label> |
||||
<input type="text" th:field="${newEducation.eisot_number}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Единички (вспомогатльный столбец): </label> |
||||
<input type="text" th:field="${newEducation.ones}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Сведения о курсе: </label> |
||||
<select th:field="${newEducation.course.id}"> |
||||
<option value="0" disabled >выберите курс</option> |
||||
<option th:each="option : ${courses}" th:value="${option.id}" th:text="${option.id}"></option> |
||||
</select> |
||||
</div> |
||||
<div> |
||||
<label>Сведения о студенте: </label> |
||||
<select th:field="${newEducation.student.id}"> |
||||
<option value="0" disabled >выберите курс</option> |
||||
<option th:each="option : ${students}" th:value="${option.id}" th:text="${option.id}"></option> |
||||
</select> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/educations}" 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>Education-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 : Education |
||||
</header> |
||||
<main> |
||||
<h2>Редактирование сведений об обучении:</h2> |
||||
<form th:action="@{/education/add}" method="post" th:object="${education}"> |
||||
<div> |
||||
<label>id: </label> |
||||
<input type="text" th:field="${education.id}" placeholder="" readonly /> |
||||
</div> |
||||
<div> |
||||
<label>Номер удостоверения: </label> |
||||
<input type="text" th:field="${education.sertificate_number}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>ФРДО номер по реестру: </label> |
||||
<input type="text" th:field="${education.frdo_number}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>ЕИСОТ номер по реестру: </label> |
||||
<input type="text" th:field="${education.eisot_number}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Единички (вспомогатльный столбец): </label> |
||||
<input type="text" th:field="${education.ones}" placeholder="" /> |
||||
</div> |
||||
<div> |
||||
<label>Сведения о курсе: </label> |
||||
<select th:field="${education.course.id}"> |
||||
<option value="0" disabled >выберите курс</option> |
||||
<option th:each="option : ${courses}" th:value="${option.id}" th:text="${option.name_short}"></option> |
||||
</select> |
||||
</div> |
||||
<div> |
||||
<label>Сведения о студенте: </label> |
||||
<select th:field="${education.student.id}"> |
||||
<option value="0" disabled >выберите курс</option> |
||||
<option th:each="option : ${students}" th:value="${option.id}" th:text="${option.first_name}"></option> |
||||
</select> |
||||
</div> |
||||
<br> |
||||
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/> |
||||
</form> |
||||
<br> |
||||
<form th:action="@{/educations}" 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>Educations</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>EDUCATIONS</h1> |
||||
menu : auth : Educations |
||||
<br> |
||||
</header> |
||||
<main> |
||||
<div class="main-wraper"> |
||||
<h2>Перечень обучений:</h2> |
||||
<form th:action="@{/educations}" method="get" th:object="${edu}"></form> |
||||
<table> |
||||
<thead> |
||||
<tr> |
||||
<th>id</th> |
||||
<th>sertificate_number</th> |
||||
<th>frdo_number</th> |
||||
<th>eisot_number</th> |
||||
<th>ones</th> |
||||
<th>course</th> |
||||
<th>student</th> |
||||
<th> |
||||
<form th:action="@{/education/add}" th:method="get"> |
||||
<input type="submit" value="ADD --|>"/> |
||||
</form> |
||||
</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr th:each="edu: ${educations}"> |
||||
<td> |
||||
<input type="text" id="id" name="id" th:value="${edu.id}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="sertificate_number" name="sertificate_number" th:value="${edu.sertificate_number}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="frdo_number" name="frdo_number" th:value="${edu.frdo_number}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="eisot_number" name="eisot_number" th:value="${edu.eisot_number}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="ones" name="ones" th:value="${edu.ones}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="course" name="course" th:value="${edu.course.id}" readonly /> |
||||
</td> |
||||
<td> |
||||
<input type="text" id="student" name="student" th:value="${edu.student.id}" readonly /> |
||||
</td> |
||||
<td> |
||||
<form th:action="@{education-edit/{id}(id=${edu.id})}" th:method="get"> |
||||
<input type="submit" value="--|>"/> |
||||
</form> |
||||
<form th:action="@{/education/delete/{id}(id=${edu.id})}" th:method="get"> |
||||
<input type="submit" value="X"/> |
||||
</form> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
</table> |
||||
</div> |
||||
</main> |
||||
</body> |
||||
</html> |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.PutMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.EducationEntry; |
||||
import ru.molokoin.resourceserviceapi.repositories.EducationEntryFace; |
||||
|
||||
@RestController |
||||
@RequestMapping(path = "/", consumes = {"*/*"}) |
||||
public class EducationEntryController { |
||||
@Autowired |
||||
private EducationEntryFace repo; |
||||
|
||||
@GetMapping("/education/list") |
||||
public ResponseEntity<List<EducationEntry>> getEducationEntries(){ |
||||
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); |
||||
} |
||||
|
||||
@GetMapping("/education/{id}") |
||||
public ResponseEntity<?> getEducationEntryByID(@PathVariable Integer id){ |
||||
return new ResponseEntity<>(repo.findEducationEntryById(id), HttpStatus.OK); |
||||
} |
||||
|
||||
@PostMapping(path = "/education/create", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> saveEducationEntry(@RequestBody EducationEntry educationEntry) { |
||||
repo.save(educationEntry); |
||||
return new ResponseEntity<>(educationEntry, HttpStatus.CREATED); |
||||
} |
||||
|
||||
@PutMapping(path = "/education/update/{id}", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> updateProgram(@PathVariable Integer id, @RequestBody EducationEntry educationEntry) { |
||||
EducationEntry ee = repo.findEducationEntryById(id); |
||||
ee.setSertificate_number(educationEntry.getSertificate_number()); |
||||
ee.setFrdo_number(educationEntry.getFrdo_number()); |
||||
ee.setEisot_number(educationEntry.getEisot_number()); |
||||
ee.setOnes(educationEntry.getOnes()); |
||||
ee.setCourse(educationEntry.getCourse()); |
||||
ee.setStudent(educationEntry.getStudent()); |
||||
repo.save(ee); |
||||
return new ResponseEntity<>(repo.findEducationEntryById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
@DeleteMapping("/education/delete/{id}") |
||||
public ResponseEntity<String> deleteProgram(@PathVariable Long id){ |
||||
EducationEntry ee = repo.findEducationEntryById(id); |
||||
System.out.println(ee.toString()); |
||||
repo.delete(ee); |
||||
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
package ru.molokoin.resourceserviceapi.entities; |
||||
|
||||
import org.hibernate.annotations.OnDelete; |
||||
import org.hibernate.annotations.OnDeleteAction; |
||||
|
||||
import jakarta.persistence.Entity; |
||||
import jakarta.persistence.FetchType; |
||||
import jakarta.persistence.GeneratedValue; |
||||
import jakarta.persistence.GenerationType; |
||||
import jakarta.persistence.Id; |
||||
import jakarta.persistence.ManyToOne; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Entity |
||||
@Data |
||||
public class EducationEntry { |
||||
@Id |
||||
@GeneratedValue(strategy=GenerationType.AUTO) |
||||
private long id; |
||||
private String sertificate_number;//Номер удостоверения
|
||||
private String frdo_number;//ФРДО номер по реестру
|
||||
private String eisot_number;//ЕИСОТ номер по реестру
|
||||
private String ones;//Единички (вспомогатльный столбец)
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false) |
||||
@OnDelete(action = OnDeleteAction.SET_NULL) |
||||
private Course course;//Сведения о курсе
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER, optional = false) |
||||
@OnDelete(action = OnDeleteAction.SET_NULL) |
||||
private Student student;//Сведения о студенте
|
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
package ru.molokoin.resourceserviceapi.repositories; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.data.repository.ListCrudRepository; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.EducationEntry; |
||||
|
||||
public interface EducationEntryFace extends ListCrudRepository<EducationEntry, Long>{ |
||||
List<EducationEntry> findAll(); |
||||
EducationEntry findEducationEntryById(long id); |
||||
} |
Loading…
Reference in new issue