Lab 4
This commit is contained in:
parent
9730c77ed5
commit
2105cff6f9
@ -14,8 +14,8 @@ function Router(props) {
|
||||
const routes = [
|
||||
{ index: true, element: <DrivingSchools /> },
|
||||
{ path: '/', element: <DrivingSchools />, label: 'Сеть Автошкол' },
|
||||
{ path: '/students', element: <Students />, label: 'Студенты' },
|
||||
{ path: '/drivingSchools', element: <DrivingSchools />, label: 'Автошколы' },
|
||||
{ path: '/students', element: <Students />, label: 'Студенты' },
|
||||
{ path: '/categories', element: <Categories />, label: 'Категории' },
|
||||
{ path: '/drivingSchool/:id', element: <OneDrivingSchool />},
|
||||
];
|
||||
|
@ -225,9 +225,9 @@ export default function OneDrivingSchool(props) {
|
||||
</Link>
|
||||
<h1>Название: {drivingSchool.name}</h1>
|
||||
<h2>Количество студентов: {drivingSchool.countStudents}</h2>
|
||||
<Button name="Зачисление" onClick={showModalFormHire} variant="success">Зачислить студента</Button>
|
||||
<Button name='Отчисление' onClick={showModalFormDismiss} variant="danger">Отчислить студента</Button>
|
||||
<Button name='Выбор категории' onClick={showModalFormChooseCategory} variant="info">Выбор категории</Button>
|
||||
<Button name="Зачисление" onClick={showModalFormHire} variant="btn btn-outline-success">Зачислить студента</Button>
|
||||
<Button name='Отчисление' onClick={showModalFormDismiss} variant="btn btn-outline-danger">Отчислить студента</Button>
|
||||
<Button name='Выбор категории' onClick={showModalFormChooseCategory} variant="btn btn-outline-primary">Выбор категории</Button>
|
||||
<div >
|
||||
<table className={`table table-hover`}>
|
||||
<thead>
|
||||
|
@ -5,7 +5,7 @@ import Navbar from 'react-bootstrap/Navbar';
|
||||
|
||||
export default function Header(props) {
|
||||
return (
|
||||
<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark">
|
||||
<Navbar collapseOnSelect expand="lg" bg="primary" variant="primary">
|
||||
<Container className='lg justify-content-center'>
|
||||
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
|
||||
<Navbar.Collapse id="responsive-navbar-nav">
|
||||
|
@ -12,7 +12,7 @@ export default function ItemTable(props) {
|
||||
props.headers.map((header) => <td key={`${header.name}_${props.item.id}`}>{props.item[header.name]}</td>)
|
||||
}
|
||||
{props.isOnlyView || <td key={`controls_${props.item.id}`}>
|
||||
<Button variant="info" onClick={edit}>Редактировать</Button>
|
||||
<Button variant="danger" onClick={remove}>Удалить</Button></td>}
|
||||
<Button variant="btn btn-outline-primary" onClick={edit}>Редактировать</Button>
|
||||
<Button variant="btn btn-outline-danger" onClick={remove}>Удалить</Button></td>}
|
||||
</tr>
|
||||
}
|
@ -60,9 +60,9 @@ public class DrivingSchoolController {
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/dismiss")
|
||||
public StudentDto dismiss(@PathVariable Long id, @RequestParam Long studentId) {
|
||||
public void dismiss(@PathVariable Long id, @RequestParam Long studentId) {
|
||||
Student e = studentService.findStudent(studentId);
|
||||
return new StudentDto(drivingSchoolService.deleteStudent(id, e));
|
||||
drivingSchoolService.deleteStudent(id, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class DrivingSchool {
|
||||
private Long Id;
|
||||
@Column(unique = true)
|
||||
private String name;
|
||||
@OneToMany(mappedBy = "drivingSchool", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@OneToMany(mappedBy = "drivingSchool", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
|
||||
private Set<Student> students = new HashSet<>();
|
||||
|
||||
public DrivingSchool(String name, Set<Student> students) {
|
||||
@ -41,7 +41,6 @@ public class DrivingSchool {
|
||||
public void deleteStudent(Student student) {
|
||||
students.remove(student);
|
||||
student.deleteDrivingSchool();
|
||||
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ru.ulstu.is.cbapp.service;
|
||||
|
||||
import ru.ulstu.is.cbapp.dao.DrivingSchoolRepository;
|
||||
import ru.ulstu.is.cbapp.dao.StudentRepository;
|
||||
import ru.ulstu.is.cbapp.models.DrivingSchool;
|
||||
import ru.ulstu.is.cbapp.models.Student;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
@ -13,11 +12,13 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DrivingSchoolService {
|
||||
|
||||
private DrivingSchoolRepository drivingSchoolRepository;
|
||||
private StudentRepository studentRepository;
|
||||
public DrivingSchoolService(DrivingSchoolRepository drivingSchoolRepository, StudentRepository studentRepository) {
|
||||
private StudentService studentService;
|
||||
|
||||
public DrivingSchoolService(DrivingSchoolRepository drivingSchoolRepository, StudentService studentService) {
|
||||
this.drivingSchoolRepository = drivingSchoolRepository;
|
||||
this.studentRepository = studentRepository;
|
||||
this.studentService = studentService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@ -76,9 +77,8 @@ public class DrivingSchoolService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Student deleteStudent(Long id, Student student) {
|
||||
public void deleteStudent(Long id, Student student) {
|
||||
DrivingSchool currentDrivingSchool = findDrivingSchool(id);
|
||||
currentDrivingSchool.deleteStudent(student);
|
||||
return studentRepository.save(student);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StudentService {
|
||||
|
||||
private StudentRepository studentRepository;
|
||||
|
||||
public StudentService(StudentRepository studentRepository) {
|
||||
this.studentRepository = studentRepository;
|
||||
}
|
||||
@ -105,4 +107,10 @@ public class StudentService {
|
||||
List<Student> students = studentRepository.findByCategories_Id(p.getId());
|
||||
return students;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Student saveStudent(Student s) {
|
||||
studentRepository.save(s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user