Browse Source

course api done

master
esoe 6 months ago
parent
commit
af8a69b83f
  1. 2
      resource-service-api/src/main/docs/erd/erd-course.puml
  2. 69
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/CourseController.java
  3. 6
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java
  4. 47
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Course.java
  5. 2
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Program.java
  6. 12
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java

2
resource-service-api/src/main/docs/erd/erd-course.puml

@ -22,7 +22,7 @@ table(courses){
column(report_period): VARCHAR[80] >>"Отчетный период" column(report_period): VARCHAR[80] >>"Отчетный период"
foreign_key(teacher_id): VARCHAR[80] >>"Идентификатор преподавателя" foreign_key(teacher_id): VARCHAR[80] >>"Идентификатор преподавателя"
foreign_key(programm_id): INTEGER >>"Идентификатор программы обучения" foreign_key(programm_id): INTEGER >>"Идентификатор программы обучения"
foreign_key(building_object_id): INTEGER >>"Идентификатор объекта строительства" foreign_key(building_id): INTEGER >>"Идентификатор объекта строительства"
} }
table(building_objects){ table(building_objects){

69
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/CourseController.java

@ -0,0 +1,69 @@
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.Course;
import ru.molokoin.resourceserviceapi.repositories.CourseRepositoryFace;
@RestController
@RequestMapping(path = "/", consumes = {"*/*"})
public class CourseController {
@Autowired
private CourseRepositoryFace repo;
@GetMapping("/course/list")
public ResponseEntity<List<Course>> getCourses(){
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
}
@GetMapping("/course/{id}")
public ResponseEntity<?> getCourseByID(@PathVariable Integer id){
return new ResponseEntity<>(repo.findCourseById(id), HttpStatus.OK);
}
@PostMapping(path = "/course/create",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> saveCourse(@RequestBody Course course) {
repo.save(course);
return new ResponseEntity<>(course, HttpStatus.CREATED);
}
@PutMapping(path = "/course/update/{id}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateCourse(@PathVariable Integer id, @RequestBody Course course) {
Course c = repo.findCourseById(id);
c.setPlace(course.getPlace());
c.setStart_date(course.getStart_date());
c.setProtocol_date(course.getProtocol_date());
c.setProtocol_number(course.getProtocol_number());
c.setReport_period(course.getReport_period());
c.setTeacher(course.getTeacher());
c.setProgram(course.getProgram());
c.setBuilding(course.getBuilding());
repo.save(c);
return new ResponseEntity<>(repo.findCourseById(id), HttpStatus.CREATED);
}
@DeleteMapping("/course/delete/{id}")
public ResponseEntity<String> deleteCourse(@PathVariable Long id){
Course c = repo.findCourseById(id);
System.out.println(c.toString());
repo.delete(c);
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK);
}
}

6
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java

@ -30,14 +30,14 @@ public class ProgramController {
} }
@GetMapping("/program/{id}") @GetMapping("/program/{id}")
public ResponseEntity<?> getTeacherByID(@PathVariable Integer id){ public ResponseEntity<?> getProgramByID(@PathVariable Integer id){
return new ResponseEntity<>(repo.findProgramById(id), HttpStatus.OK); return new ResponseEntity<>(repo.findProgramById(id), HttpStatus.OK);
} }
@PostMapping(path = "/program/create", @PostMapping(path = "/program/create",
consumes = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> saveTeacher(@RequestBody Program program) { public ResponseEntity<?> saveProgram(@RequestBody Program program) {
repo.save(program); repo.save(program);
return new ResponseEntity<>(program, HttpStatus.CREATED); return new ResponseEntity<>(program, HttpStatus.CREATED);
} }
@ -57,7 +57,7 @@ public class ProgramController {
} }
@DeleteMapping("/program/delete/{id}") @DeleteMapping("/program/delete/{id}")
public ResponseEntity<String> deleteCretarea(@PathVariable Long id){ public ResponseEntity<String> deleteProgram(@PathVariable Long id){
Program p = repo.findProgramById(id); Program p = repo.findProgramById(id);
System.out.println(p.toString()); System.out.println(p.toString());
repo.delete(p); repo.delete(p);

47
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Course.java

@ -0,0 +1,47 @@
package ru.molokoin.resourceserviceapi.entities;
import java.util.Date;
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 Course {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;//уникальный идентификатор курса
private String place;//место проведения занятий
private Date start_date;//дата начала курса
private Date protocol_date;//дата протокола
private String protocol_number;//номер протоколаssss
private String report_period;//отчетный период (наименование месяца)
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@OnDelete(action = OnDeleteAction.SET_NULL)
private Teacher teacher;//сведения о преподаватле
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@OnDelete(action = OnDeleteAction.SET_NULL)
private Program program;//сведения о программе обучения
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@OnDelete(action = OnDeleteAction.SET_NULL)
private Building building;//сведения об объекте строительства
}

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

@ -3,7 +3,6 @@ package ru.molokoin.resourceserviceapi.entities;
import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction; import org.hibernate.annotations.OnDeleteAction;
import jakarta.annotation.Nullable;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -29,6 +28,5 @@ public class Program {
@ManyToOne(fetch = FetchType.EAGER, optional = false) @ManyToOne(fetch = FetchType.EAGER, optional = false)
@OnDelete(action = OnDeleteAction.SET_NULL) @OnDelete(action = OnDeleteAction.SET_NULL)
// @Nullable
private ProgramCretarea cretarea; private ProgramCretarea cretarea;
} }

12
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java

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