esoe
6 months ago
6 changed files with 132 additions and 6 deletions
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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;//сведения об объекте строительства
|
||||||
|
} |
@ -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…
Reference in new issue