Browse Source

student api done

master
esoe 6 months ago
parent
commit
7c66660811
  1. 4
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/ProgramController.java
  2. 72
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StudentController.java
  3. 44
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Student.java
  4. 12
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/StudentFace.java

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

@ -31,7 +31,7 @@ public class ProgramController { @@ -31,7 +31,7 @@ public class ProgramController {
@GetMapping("/program/{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",
@ -63,6 +63,4 @@ public class ProgramController { @@ -63,6 +63,4 @@ public class ProgramController {
repo.delete(p);
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK);
}
}

72
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StudentController.java

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
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.Student;
import ru.molokoin.resourceserviceapi.repositories.StudentFace;
@RestController
@RequestMapping(path = "/", consumes = {"*/*"})
public class StudentController {
@Autowired
private StudentFace repo;
@GetMapping("/student/list")
public ResponseEntity<List<Student>> getStudents(){
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
}
@GetMapping("/student/{id}")
public ResponseEntity<?> getStudentByID(@PathVariable Integer id){
return new ResponseEntity<>(repo.findStudentById(id), HttpStatus.OK);
}
@PostMapping(path = "/student/create",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> saveStudent(@RequestBody Student student) {
repo.save(student);
return new ResponseEntity<>(student, HttpStatus.CREATED);
}
@PutMapping(path = "/student/update/{id}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateStudent(@PathVariable Integer id, @RequestBody Student student) {
Student s = repo.findStudentById(id);
s.setFirst_name(student.getFirst_name());
s.setSecond_name(student.getSecond_name());
s.setLast_name(student.getLast_name());
s.setProfession(student.getProfession());
s.setCategory(student.getCategory());
s.setDirection(student.getDirection());
s.setSnils(student.getSnils());
s.setBerth(student.getBerth());
s.setSitizenship(student.getSitizenship());
s.setSex(student.getSex());
s.setOrganization(student.getOrganization());
repo.save(s);
return new ResponseEntity<>(repo.findStudentById(id), HttpStatus.CREATED);
}
@DeleteMapping("/student/delete/{id}")
public ResponseEntity<String> deleteStudent(@PathVariable Long id){
Student s = repo.findStudentById(id);
System.out.println(s.toString());
repo.delete(s);
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK);
}
}

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

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
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 Student {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String first_name;//Имя
private String second_name;//Отчество
private String last_name;//Фамилия
private String profession;//Профессия
private String category;//Категория (ИТР или рабочий)
private String direction;//Структурное подразделение
private String snils;//СНИЛС
private Date berth;//Дата рождения
private String sitizenship;//Гражданство
private String sex;//Пол (м/ж)
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@OnDelete(action = OnDeleteAction.SET_NULL)
private Organization organization;//Организация - работодатель
}

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

@ -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.Student;
public interface StudentFace extends ListCrudRepository<Student, Long>{
List<Student> findAll();
Student findStudentById(long id);
}
Loading…
Cancel
Save