Browse Source

course done

organization api done
master
esoe 6 months ago
parent
commit
82bc4ee014
  1. 201
      client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/CourseController.java
  2. 16
      client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java
  3. 45
      client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Course.java
  4. 1
      client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java
  5. 4
      client-service-teachers/src/main/resources/application.yaml
  6. 70
      client-service-teachers/src/main/resources/templates/course-add.html
  7. 0
      client-service-teachers/src/main/resources/templates/course-edit.html
  8. 85
      client-service-teachers/src/main/resources/templates/courses.html
  9. 89
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/OrganizationController.java
  10. 44
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Organization.java
  11. 2
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Teacher.java
  12. 15
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/OrganizationFace.java

201
client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/CourseController.java

@ -0,0 +1,201 @@
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.Course;
import ru.molokoin.clientserviceteachers.entities.Program;
import ru.molokoin.clientserviceteachers.entities.ProgramCretarea;
import ru.molokoin.clientserviceteachers.entities.Teacher;
@Controller
@RequestMapping(path = "/")
public class CourseController {
@Autowired
private WebClient client;
@GetMapping("/courses")
public String courseList(Model model) throws JsonMappingException, JsonProcessingException{
List<Course> courses = client.method(HttpMethod.GET)
.uri("/course/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Course>>(){})
.block();
model.addAttribute("courses", courses);
model.addAttribute("cs", new Course());
System.out.println("COURCES:" + courses.toString());
return "courses";
}
@GetMapping("/course-edit/{id}")
public String courseById(Model model, @PathVariable Long id) {
/**
* получение списка преподавателей (Class.Teacher) из ресурсов
* - для select поля формы
*/
List<Teacher> teachers = client.get()
.uri("/teacher/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Teacher>>(){})
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("teachers", teachers);
/**
* получение списка программ обучения (Class.Program) из ресурсов
* - для select поля формы
*/
List<Program> programs = client.get()
.uri("/program/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Program>>(){})
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("programs", programs);
/**
* получение списка объектов строительства (Class.Building) из ресурсов
* - для select поля формы
*/
List<Building> buildings = client.get()
.uri("/building/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Building>>(){})
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("buildings", buildings);
/**
* Получение сведений о курсе (Class.Course) из ресурсов
* - для отображения на редактирование в форме course-edit
*/
Course course = client.get()
.uri("/course/" + id)
.retrieve()
.bodyToMono(Course.class)
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("course", course);
return "course-edit";
}
/**
* Отправка данных заполненной формы курса на сервер
* @param model
* @param course
* @return
* @throws JsonMappingException
* @throws JsonProcessingException
*/
@PostMapping(
path = "/course/add",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = {
MediaType.APPLICATION_JSON_VALUE
})
public String addCourse(Model model, @ModelAttribute("course") @Validated Course course) throws JsonMappingException, JsonProcessingException{
client.post()
.uri("/course/create")
.body(Mono.just(course), Course.class)
.retrieve()
.toBodilessEntity()
.timeout(Duration.ofSeconds(1))
.block();
return "redirect:/courses";
}
@GetMapping(path = "/course/add")
public String addCourseFrame(Model model){
/**
* получение списка преподавателей (Class.Teacher) из ресурсов
* - для select поля формы
*/
List<Teacher> teachers = client.get()
.uri("/teacher/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Teacher>>(){})
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("teachers", teachers);
/**
* получение списка программ обучения (Class.Program) из ресурсов
* - для select поля формы
*/
List<Program> programs = client.get()
.uri("/program/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Program>>(){})
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("programs", programs);
/**
* получение списка объектов строительства (Class.Building) из ресурсов
* - для select поля формы
*/
List<Building> buildings = client.get()
.uri("/building/list")
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Building>>(){})
.timeout(Duration.ofSeconds(1))
.block();
model.addAttribute("buildings", buildings);
Course course = new Course();
model.addAttribute("newCourse", course);
return "course-add";
}
@GetMapping(path = "/course/delete/{id}")
public String deleteCourse(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{
client.delete()
.uri("/course/delete/" + id)
.retrieve()
.bodyToMono(String.class)
.timeout(Duration.ofSeconds(1))
.block();
return "redirect:/courses";
}
@PostMapping(
path = "/course/update/{id}",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = {
MediaType.APPLICATION_JSON_VALUE
})
public String updateCourse(@PathVariable Long id
, @ModelAttribute("cs") @Validated Course course) throws JsonMappingException, JsonProcessingException{
client.post()
.uri("/course/update/" + course.getId())
.body(Mono.just(course), Course.class)
.retrieve()
.toBodilessEntity()
.timeout(Duration.ofSeconds(1))
.block();
return "redirect:/courses";
}
}

16
client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java

@ -32,7 +32,7 @@ public class ProgramController {
private WebClient client; private WebClient client;
@GetMapping("/programs") @GetMapping("/programs")
public String teacherList(Model model) throws JsonMappingException, JsonProcessingException{ public String programList(Model model) throws JsonMappingException, JsonProcessingException{
List<Program> programs = client.method(HttpMethod.GET) List<Program> programs = client.method(HttpMethod.GET)
.uri("/program/list") .uri("/program/list")
.retrieve() .retrieve()
@ -46,9 +46,10 @@ public class ProgramController {
} }
@GetMapping("/program-edit/{id}") @GetMapping("/program-edit/{id}")
public String teacherById(Model model, @PathVariable Long id) { public String programById(Model model, @PathVariable Long id) {
/** /**
* получение критериев из ресурсов * получение списка критериев из ресурсов
* - для select поля формы
*/ */
List<ProgramCretarea> pcl = client.get() List<ProgramCretarea> pcl = client.get()
.uri("/cretarea/list") .uri("/cretarea/list")
@ -102,7 +103,7 @@ public class ProgramController {
} }
@GetMapping(path = "/program/add") @GetMapping(path = "/program/add")
public String addTeacherFrame(Model model){ public String addProgramFrame(Model model){
/** /**
* получение критериев из ресурсов * получение критериев из ресурсов
*/ */
@ -120,7 +121,7 @@ public class ProgramController {
} }
@GetMapping(path = "/program/delete/{id}") @GetMapping(path = "/program/delete/{id}")
public String deleteTeacher(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ public String deleteProgram(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{
client.delete() client.delete()
.uri("/program/delete/" + id) .uri("/program/delete/" + id)
.retrieve() .retrieve()
@ -136,7 +137,7 @@ public class ProgramController {
produces = { produces = {
MediaType.APPLICATION_JSON_VALUE MediaType.APPLICATION_JSON_VALUE
}) })
public String updateTeacher(@PathVariable Long id public String updateProgram(@PathVariable Long id
, @ModelAttribute("p") @Validated Program program) throws JsonMappingException, JsonProcessingException{ , @ModelAttribute("p") @Validated Program program) throws JsonMappingException, JsonProcessingException{
client.post() client.post()
.uri("/teacher/update/" + program.getId()) .uri("/teacher/update/" + program.getId())
@ -147,7 +148,4 @@ public class ProgramController {
.block(); .block();
return "redirect:/programs"; return "redirect:/programs";
} }
} }

45
client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Course.java

@ -0,0 +1,45 @@
package ru.molokoin.clientserviceteachers.entities;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Course {
private long id;//уникальный идентификатор курса
private String place;//место проведения занятий
private Date start_date;//дата начала курса
private Date protocol_date;//дата протокола
private String protocol_number;//номер протоколаssss
private String report_period;//отчетный период (наименование месяца)
private Teacher teacher;//сведения о преподаватле
private Program program;//сведения о программе обучения
private Building building;//сведения об объекте строительства
/**
* Конструктор без id
* @param place
* @param start_date
* @param protocol_date
* @param protocol_number
* @param report_period
* @param teacher
* @param program
* @param building
*/
public Course(String place, Date start_date, Date protocol_date, String protocol_number, String report_period,
Teacher teacher, Program program, Building building) {
this.place = place;
this.start_date = start_date;
this.protocol_date = protocol_date;
this.protocol_number = protocol_number;
this.report_period = report_period;
this.teacher = teacher;
this.program = program;
this.building = building;
}
}

1
client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java

@ -1,6 +1,5 @@
package ru.molokoin.clientserviceteachers.entities; package ru.molokoin.clientserviceteachers.entities;
import jakarta.annotation.Nullable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

4
client-service-teachers/src/main/resources/application.yaml

@ -13,5 +13,9 @@ spring:
hiddenmethod: hiddenmethod:
filter: filter:
enabled: true enabled: true
format:
date: yyyy-MM-dd
date-time: yyyy-MM-dd HH:mm:ss
time: HH:mm:ss

70
client-service-teachers/src/main/resources/templates/course-add.html

@ -0,0 +1,70 @@
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>Course-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 : course
</header>
<main>
<h2>Добавление нового курса:</h2>
<form th:action="@{/course/add}" method="post" th:object="${newCourse}">
<div>
<label>id: </label>
<input type="text" th:field="${newCourse.id}" placeholder="" readonly />
</div>
<div>
<label>Место занятий: </label>
<input type="text" th:field="${newCourse.place}" placeholder="" />
</div>
<div>
<label>Дата начала занятий: </label>
<input type="date" th:field="${newCourse.start_date}" placeholder="" />
</div>
<div>
<label>Дата протокола: </label>
<input type="date" th:field="${newCourse.protocol_date}" placeholder="" />
</div>
<div>
<label>Номер протокола: </label>
<input type="text" th:field="${newCourse.protocol_number}" placeholder="" />
</div>
<div>
<label>Отчетный период: </label>
<input type="text" th:field="${newCourse.report_period}" placeholder="" />
</div>
<div>
<label>Преподаватель: </label>
<select th:field="${newCourse.teacher.id}">
<option value="0" disabled >выберите преподавателя</option>
<option th:each="option : ${teachers}" th:value="${option.id}" th:text="${option.second_name}"></option>
</select>
</div>
<div>
<label>Программа: </label>
<select th:field="${newCourse.program.id}">
<option value="0" disabled >выберите программу</option>
<option th:each="option : ${programs}" th:value="${option.id}" th:text="${option.name}"></option>
</select>
</div>
<div>
<label>Объект строительства: </label>
<select th:field="${newCourse.building.id}">
<option value="0" disabled >выберите объект строительства</option>
<option th:each="option : ${buildings}" th:value="${option.id}" th:text="${option.name_short}"></option>
</select>
</div>
<br>
<input type="submit" value="СОХРАНИТЬ И ВЕРНУТЬСЯ"/>
</form>
<br>
<form th:action="@{/courses}" th:method="get">
<input type="submit" value="ВЕРНУТЬСЯ"/>
</form>
</main>
</body>

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

85
client-service-teachers/src/main/resources/templates/courses.html

@ -0,0 +1,85 @@
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>Courses</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>COURSES</h1>
menu : auth : courses
<br>
</header>
<main>
<div class="main-wraper">
<h2>Перечень курсов:</h2>
<form th:action="@{/courses}" method="get" th:object="${cs}"></form>
<table>
<thead>
<tr>
<th>id</th>
<th>place</th>
<th>start_date</th>
<th>protocol_date</th>
<th>protocol_number</th>
<th>report_period</th>
<th>teacher</th>
<th>program</th>
<th>building</th>
<th>
<!-- Переход на страницу добавления нового курса -->
<form th:action="@{/course/add}" th:method="get">
<input type="submit" value="ADD --|>"/>
</form>
</th>
</tr>
</thead>
<tbody>
<tr th:each="c: ${courses}">
<td>
<input type="text" id="id" name="id" th:value="${c.id}" readonly />
</td>
<td>
<input type="text" id="place" name="place" th:value="${c.place}" readonly />
</td>
<td>
<input type="text" id="start_date" name="start_date" th:value="${c.start_date}" readonly />
</td>
<td>
<input type="text" id="protocol_date" name="protocol_date" th:value="${c.protocol_date}" readonly />
</td>
<td>
<input type="text" id="protocol_number" name="protocol_number" th:value="${c.protocol_number}" readonly />
</td>
<td>
<input type="text" id="report_period" name="report_period" th:value="${c.report_period}" readonly />
</td>
<td>
<input type="text" id="teacher" name="teacher" th:value="${c.teacher.second_name}" readonly />
</td>
<td>
<input type="text" id="program" name="program" th:value="${c.program.name}" readonly />
</td>
<td>
<input type="text" id="building" name="building" th:value="${c.building.name_short}" readonly />
</td>
<td>
<form th:action="@{course-edit/{id}(id=${c.id})}" th:method="get">
<input type="submit" value="--|>"/>
</form>
<form th:action="@{/course/delete/{id}(id=${c.id})}" th:method="get">
<input type="submit" value="X"/>
</form>
</td>
</tr>
</tbody>
</table>
</table>
</div>
</main>
</body>
</html>

89
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/OrganizationController.java

@ -0,0 +1,89 @@
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.molokoin.resourceserviceapi.entities.Organization;
import ru.molokoin.resourceserviceapi.repositories.OrganizationFace;
@RestController
@RequestMapping(path = "/", consumes = {"*/*"})
public class OrganizationController {
@Autowired
private OrganizationFace repo;
/**
* Получение списа организаций
* @return
*/
@GetMapping("/organization/list")
public ResponseEntity<List<Organization>> getOrganizations(){
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
}
/**
* Получение сведений об организации по id
* @param id
* @return
*/
@GetMapping("/organization/{id}")
public ResponseEntity<?> getOrganizationByID(@PathVariable Integer id){
return new ResponseEntity<>(repo.findOrganizationById(id), HttpStatus.OK);
}
/**
* Создание записи об организации
* @param organization
* @return
*/
@PostMapping(path = "/organization/create",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> saveOrganization(@RequestBody Organization organization) {
repo.save(organization);
return new ResponseEntity<>(organization, HttpStatus.CREATED);
}
/**
* Обновление вседений об организации
* @param id
* @param organization
* @return
*/
@PostMapping(path = "/organization/update/{id}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateOrganization(@PathVariable Integer id, @RequestBody Organization organization) {
Organization org = repo.findOrganizationById(id);
org.setOwnership(organization.getOwnership());
org.setName_short(organization.getName_short());
org.setName_full(organization.getName_full());
org.setType(organization.getType());
org.setInn(organization.getInn());
repo.save(org);
return new ResponseEntity<>(repo.findOrganizationById(id), HttpStatus.CREATED);
}
/**
* Удаление записи об организации
* @param id
* @return
*/
@DeleteMapping("/organization/delete/{id}")
public ResponseEntity<String> deleteOrganization(@PathVariable Long id){
Organization org = repo.findOrganizationById(id);
repo.delete(org);
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK);
}
}

44
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Organization.java

@ -0,0 +1,44 @@
package ru.molokoin.resourceserviceapi.entities;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Сущность для хранения сведений об организации - контрагенте
* - ПСК
*/
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Data
public class Organization {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String ownership;
private String name_short;//Сокращенное наименование
private String name_full;//Полное наименование
private String type;
private String inn;
/**
* подготовить конструкторы на все варианты внесения информации о преподавателях
* @param ownership
* @param name_short
* @param name_full
* @param type
* @param inn
*/
public Organization(String ownership, String name_short, String name_full, String type, String inn) {
this.ownership = ownership;
this.name_short = name_short;
this.name_full = name_full;
this.type = type;
this.inn = inn;
}
}

2
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Teacher.java

@ -1,7 +1,5 @@
package ru.molokoin.resourceserviceapi.entities; package ru.molokoin.resourceserviceapi.entities;
import org.hibernate.engine.jdbc.SerializableBlobProxy;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;

15
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/OrganizationFace.java

@ -0,0 +1,15 @@
package ru.molokoin.resourceserviceapi.repositories;
import java.util.List;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.stereotype.Repository;
import ru.molokoin.resourceserviceapi.entities.Organization;
@Repository
public interface OrganizationFace extends ListCrudRepository<Organization, Long>{
List<Organization> findAll();
Organization findOrganizationById(long id);
}
Loading…
Cancel
Save