This commit is contained in:
AnnZhimol 2023-04-17 14:30:42 +04:00
parent 9730c77ed5
commit 2105cff6f9
8 changed files with 24 additions and 17 deletions

View File

@ -14,8 +14,8 @@ function Router(props) {
const routes = [ const routes = [
{ index: true, element: <DrivingSchools /> }, { index: true, element: <DrivingSchools /> },
{ path: '/', element: <DrivingSchools />, label: 'Сеть Автошкол' }, { path: '/', element: <DrivingSchools />, label: 'Сеть Автошкол' },
{ path: '/students', element: <Students />, label: 'Студенты' },
{ path: '/drivingSchools', element: <DrivingSchools />, label: 'Автошколы' }, { path: '/drivingSchools', element: <DrivingSchools />, label: 'Автошколы' },
{ path: '/students', element: <Students />, label: 'Студенты' },
{ path: '/categories', element: <Categories />, label: 'Категории' }, { path: '/categories', element: <Categories />, label: 'Категории' },
{ path: '/drivingSchool/:id', element: <OneDrivingSchool />}, { path: '/drivingSchool/:id', element: <OneDrivingSchool />},
]; ];

View File

@ -225,9 +225,9 @@ export default function OneDrivingSchool(props) {
</Link> </Link>
<h1>Название: {drivingSchool.name}</h1> <h1>Название: {drivingSchool.name}</h1>
<h2>Количество студентов: {drivingSchool.countStudents}</h2> <h2>Количество студентов: {drivingSchool.countStudents}</h2>
<Button name="Зачисление" onClick={showModalFormHire} variant="success">Зачислить студента</Button> <Button name="Зачисление" onClick={showModalFormHire} variant="btn btn-outline-success">Зачислить студента</Button>
<Button name='Отчисление' onClick={showModalFormDismiss} variant="danger">Отчислить студента</Button> <Button name='Отчисление' onClick={showModalFormDismiss} variant="btn btn-outline-danger">Отчислить студента</Button>
<Button name='Выбор категории' onClick={showModalFormChooseCategory} variant="info">Выбор категории</Button> <Button name='Выбор категории' onClick={showModalFormChooseCategory} variant="btn btn-outline-primary">Выбор категории</Button>
<div > <div >
<table className={`table table-hover`}> <table className={`table table-hover`}>
<thead> <thead>

View File

@ -5,7 +5,7 @@ import Navbar from 'react-bootstrap/Navbar';
export default function Header(props) { export default function Header(props) {
return ( return (
<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark"> <Navbar collapseOnSelect expand="lg" bg="primary" variant="primary">
<Container className='lg justify-content-center'> <Container className='lg justify-content-center'>
<Navbar.Toggle aria-controls="responsive-navbar-nav" /> <Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav"> <Navbar.Collapse id="responsive-navbar-nav">

View File

@ -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.headers.map((header) => <td key={`${header.name}_${props.item.id}`}>{props.item[header.name]}</td>)
} }
{props.isOnlyView || <td key={`controls_${props.item.id}`}> {props.isOnlyView || <td key={`controls_${props.item.id}`}>
<Button variant="info" onClick={edit}>Редактировать</Button> <Button variant="btn btn-outline-primary" onClick={edit}>Редактировать</Button>
<Button variant="danger" onClick={remove}>Удалить</Button></td>} <Button variant="btn btn-outline-danger" onClick={remove}>Удалить</Button></td>}
</tr> </tr>
} }

View File

@ -60,9 +60,9 @@ public class DrivingSchoolController {
} }
@PutMapping("/{id}/dismiss") @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); Student e = studentService.findStudent(studentId);
return new StudentDto(drivingSchoolService.deleteStudent(id, e)); drivingSchoolService.deleteStudent(id, e);
} }
} }

View File

@ -10,7 +10,7 @@ public class DrivingSchool {
private Long Id; private Long Id;
@Column(unique = true) @Column(unique = true)
private String name; 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<>(); private Set<Student> students = new HashSet<>();
public DrivingSchool(String name, Set<Student> students) { public DrivingSchool(String name, Set<Student> students) {
@ -41,7 +41,6 @@ public class DrivingSchool {
public void deleteStudent(Student student) { public void deleteStudent(Student student) {
students.remove(student); students.remove(student);
student.deleteDrivingSchool(); student.deleteDrivingSchool();
} }
public Long getId() { public Long getId() {

View File

@ -1,7 +1,6 @@
package ru.ulstu.is.cbapp.service; package ru.ulstu.is.cbapp.service;
import ru.ulstu.is.cbapp.dao.DrivingSchoolRepository; 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.DrivingSchool;
import ru.ulstu.is.cbapp.models.Student; import ru.ulstu.is.cbapp.models.Student;
import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.EntityNotFoundException;
@ -13,11 +12,13 @@ import java.util.List;
@Service @Service
public class DrivingSchoolService { public class DrivingSchoolService {
private DrivingSchoolRepository drivingSchoolRepository; private DrivingSchoolRepository drivingSchoolRepository;
private StudentRepository studentRepository; private StudentService studentService;
public DrivingSchoolService(DrivingSchoolRepository drivingSchoolRepository, StudentRepository studentRepository) {
public DrivingSchoolService(DrivingSchoolRepository drivingSchoolRepository, StudentService studentService) {
this.drivingSchoolRepository = drivingSchoolRepository; this.drivingSchoolRepository = drivingSchoolRepository;
this.studentRepository = studentRepository; this.studentService = studentService;
} }
@Transactional @Transactional
@ -76,9 +77,8 @@ public class DrivingSchoolService {
} }
@Transactional @Transactional
public Student deleteStudent(Long id, Student student) { public void deleteStudent(Long id, Student student) {
DrivingSchool currentDrivingSchool = findDrivingSchool(id); DrivingSchool currentDrivingSchool = findDrivingSchool(id);
currentDrivingSchool.deleteStudent(student); currentDrivingSchool.deleteStudent(student);
return studentRepository.save(student);
} }
} }

View File

@ -13,7 +13,9 @@ import java.util.List;
@Service @Service
public class StudentService { public class StudentService {
private StudentRepository studentRepository; private StudentRepository studentRepository;
public StudentService(StudentRepository studentRepository) { public StudentService(StudentRepository studentRepository) {
this.studentRepository = studentRepository; this.studentRepository = studentRepository;
} }
@ -105,4 +107,10 @@ public class StudentService {
List<Student> students = studentRepository.findByCategories_Id(p.getId()); List<Student> students = studentRepository.findByCategories_Id(p.getId());
return students; return students;
} }
@Transactional
public Student saveStudent(Student s) {
studentRepository.save(s);
return s;
}
} }