Добавлены контроллеры и DTO
This commit is contained in:
parent
83e27918ee
commit
591f84718a
@ -0,0 +1,21 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.DTO;
|
||||
|
||||
import ru.IP_LabWorks.IP.University.Model.Group;
|
||||
|
||||
public class GroupDTO {
|
||||
private final long id;
|
||||
private final String name;
|
||||
|
||||
public GroupDTO(Group group){
|
||||
this.id = group.getId();
|
||||
this.name = group.getName();
|
||||
}
|
||||
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.DTO;
|
||||
|
||||
import ru.IP_LabWorks.IP.University.Model.Student;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class StudentDTO {
|
||||
private final long id;
|
||||
private final String name;
|
||||
private final LocalDate birthDate;
|
||||
|
||||
public StudentDTO(Student student) {
|
||||
this.id = student.getId();
|
||||
this.name = student.getName();
|
||||
this.birthDate = student.getBirthDate();
|
||||
}
|
||||
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate(){
|
||||
return birthDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.DTO;
|
||||
|
||||
import ru.IP_LabWorks.IP.University.Model.Subject;
|
||||
|
||||
public class SubjectDTO {
|
||||
private final long id;
|
||||
private final String name;
|
||||
|
||||
public SubjectDTO(Subject subject){
|
||||
this.id = subject.getId();
|
||||
this.name = subject.getName();
|
||||
}
|
||||
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.REST;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.IP_LabWorks.IP.University.Contoller.DTO.GroupDTO;
|
||||
import ru.IP_LabWorks.IP.University.Service.GroupService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/group")
|
||||
public class GroupController {
|
||||
private final GroupService groupService;
|
||||
|
||||
public GroupController(GroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public GroupDTO getGroup(@PathVariable Long id){
|
||||
return new GroupDTO(groupService.findGroup(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<GroupDTO> getGroups(){
|
||||
return groupService.findAllGroups().stream()
|
||||
.map(GroupDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public GroupDTO createGroup(@RequestParam("name") String name){
|
||||
return new GroupDTO(groupService.addGroup(name));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public GroupDTO updateGroup(@PathVariable Long id,
|
||||
@RequestParam("name") String name){
|
||||
return new GroupDTO(groupService.updateGroup(id, name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public GroupDTO deleteGroup(@PathVariable Long id){
|
||||
return new GroupDTO(groupService.deleteGroup(id));
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.REST;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.IP_LabWorks.IP.University.Contoller.DTO.StudentDTO;
|
||||
import ru.IP_LabWorks.IP.University.Service.StudentService;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/student")
|
||||
public class StudentController {
|
||||
private final StudentService studentService;
|
||||
|
||||
public StudentController(StudentService studentService) {
|
||||
this.studentService = studentService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public StudentDTO getStudent(@PathVariable Long id){
|
||||
return new StudentDTO(studentService.findStudent(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<StudentDTO> getStudents(){
|
||||
return studentService.findAllStudents().stream()
|
||||
.map(StudentDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public StudentDTO createStudent(@RequestParam("name") String name,
|
||||
@RequestParam("birthDate")LocalDate birthDate){
|
||||
return new StudentDTO(studentService.addStudent(name, birthDate));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public StudentDTO updateStudent(@PathVariable Long id,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("birthDate") LocalDate birthDate){
|
||||
return new StudentDTO(studentService.updateStudent(id, name, birthDate));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public StudentDTO deleteStudent(@PathVariable Long id){
|
||||
return new StudentDTO(studentService.deleteStudent(id));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.REST;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.IP_LabWorks.IP.University.Contoller.DTO.GroupDTO;
|
||||
import ru.IP_LabWorks.IP.University.Contoller.DTO.SubjectDTO;
|
||||
import ru.IP_LabWorks.IP.University.Service.GroupService;
|
||||
import ru.IP_LabWorks.IP.University.Service.SubjectService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/subject")
|
||||
public class SubjectController {
|
||||
private final SubjectService subjectService;
|
||||
|
||||
public SubjectController(SubjectService subjectService) {
|
||||
this.subjectService = subjectService;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public SubjectDTO getSubject(@PathVariable Long id){
|
||||
return new SubjectDTO(subjectService.findSubject(id));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<SubjectDTO> getSubject(){
|
||||
return subjectService.findAllSubjects().stream()
|
||||
.map(SubjectDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public SubjectDTO createSubject(@RequestParam("name") String name){
|
||||
return new SubjectDTO(subjectService.addSubject(name));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public SubjectDTO updateSubject(@PathVariable Long id,
|
||||
@RequestParam("name") String name){
|
||||
return new SubjectDTO(subjectService.updateSubject(id, name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public SubjectDTO deleteSubject(@PathVariable Long id){
|
||||
return new SubjectDTO(subjectService.deleteSubject(id));
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/student")
|
||||
public class StudentController {
|
||||
}
|
Loading…
Reference in New Issue
Block a user