Добавлен просмотр студентов через группы
This commit is contained in:
parent
6159f006a7
commit
66052b7078
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="container mt-4">
|
||||
<h1 class="text-center mb-4">Group Table</h1>
|
||||
<button class="btn btn-primary mr-2" @click="openModal(); group = new Group(); group.status = `create`">Добавить</button>
|
||||
<button class="btn btn-primary mr-2" @click="openModal('create')">Добавить</button>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -13,13 +13,21 @@
|
||||
<tr v-for="grp in groups" :key="grp.id">
|
||||
<td>{{ grp.name }}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="openModal(); group = grp; group.status = `edit`">Изменить</button>
|
||||
<button class="btn btn-danger" @click="deleteGroup(grp.id)">Удалить</button>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="openModal('edit', grp)">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" @click="deleteGroup(grp.id)">Удалить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="OpenModelForStudents();getStudentsFromGroup(grp.id)">Просмотр студентов</button>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Модальное окно для добавления и изменения-->
|
||||
<div class="modal" tabindex="-1" id="editModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
@ -36,10 +44,41 @@
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModal()">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary" v-if="group.status === `create`"
|
||||
@click="addGroup">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else
|
||||
@click="editGroup(group)">Сохранить</button>
|
||||
<button type="button" class="btn btn-primary" v-if="group.status === 'create'" @click="addGroup(group)">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else @click="editGroup(group)">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Модальное окно для просмотра студентов в группе-->
|
||||
<div class="modal" tabindex="-1" id="ModelForStudents">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Студенты</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Имя</th>
|
||||
<th>Дата рождения</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="stud in students" :key="stud.id">
|
||||
<td>{{ stud.name }}</td>
|
||||
<td>{{ stud.birthDate }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="ModelForStudents" @click="closeModelForStudents()">Закрыть</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -49,12 +88,8 @@
|
||||
import 'axios';
|
||||
import axios from "axios";
|
||||
import Group from "@/models/Group";
|
||||
import Student from "@/models/Student";
|
||||
export default {
|
||||
computed: {
|
||||
Group() {
|
||||
return Group
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getGroups();
|
||||
},
|
||||
@ -62,6 +97,9 @@ export default {
|
||||
const addModal = document.getElementById('editModal');
|
||||
addModal.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
const ModelForStudents = document.getElementById('ModelForStudents');
|
||||
addModal.addEventListener('shown.bs.modal', function () {
|
||||
})
|
||||
},
|
||||
|
||||
data() {
|
||||
@ -69,6 +107,7 @@ export default {
|
||||
groups: [],
|
||||
URL: "http://localhost:8080/",
|
||||
group: new Group(),
|
||||
students: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -82,9 +121,9 @@ export default {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
addGroup(){
|
||||
addGroup(group){
|
||||
console.log(this.group);
|
||||
axios.post(this.URL + "group", this.group)
|
||||
axios.post(this.URL + "group", group)
|
||||
.then(() => {
|
||||
this.getGroups();
|
||||
this.closeModal();
|
||||
@ -100,19 +139,46 @@ export default {
|
||||
})
|
||||
},
|
||||
editGroup(group){
|
||||
this.group = group;
|
||||
axios.put(this.URL + `group/${group.id}`, this.group)
|
||||
axios.put(this.URL + `group/${group.id}`, group)
|
||||
.then(() =>{
|
||||
const index = this.groups.findIndex((s) => s.id === group.id);
|
||||
if (index !== -1) {
|
||||
this.groups[index] = { ...group };
|
||||
}
|
||||
this.closeModal();
|
||||
this.getGroups();
|
||||
})
|
||||
this.closeModal();
|
||||
},
|
||||
openModal() {
|
||||
openModal(status, group = null) {
|
||||
if (status === "create") {
|
||||
this.group = new Group();
|
||||
this.group.status = "create";
|
||||
} else if (status === "edit" && group) {
|
||||
this.group = { ...group };
|
||||
this.group.status = "edit";
|
||||
}
|
||||
document.getElementById("editModal").style.display = "block";
|
||||
},
|
||||
closeModal() {
|
||||
document.getElementById("editModal").style.display = "none";
|
||||
},
|
||||
getStudentsFromGroup(groupId){
|
||||
axios.get(this.URL + `group/${groupId}/students`)
|
||||
.then(response => {
|
||||
this.students = response.data;
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
OpenModelForStudents() {
|
||||
document.getElementById("ModelForStudents").style.display = "block";
|
||||
},
|
||||
closeModelForStudents() {
|
||||
document.getElementById("ModelForStudents").style.display = "none";
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -17,8 +17,12 @@
|
||||
<td>{{ stud.birthDate }}</td>
|
||||
<td>{{ stud.groupName }}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="openModal('edit', stud)">Изменить</button>
|
||||
<button class="btn btn-danger" @click="deleteStudent(stud.id)">Удалить</button>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="openModal('edit', stud)">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" @click="deleteStudent(stud.id)">Удалить</button>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -29,7 +33,6 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Студент</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="container mt-4">
|
||||
<h1 class="text-center mb-4">Subject Table</h1>
|
||||
<button class="btn btn-primary mr-2" @click="openModal(); subject = new Subject(); subject.status = `create`">Добавить</button>
|
||||
<button class="btn btn-primary mr-2" @click="openModal('create')">Добавить</button>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -13,8 +13,12 @@
|
||||
<tr v-for="sbjct in subjects" :key="sbjct.id">
|
||||
<td>{{ sbjct.name }}</td>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="openModal(); subject = sbjct; subject.status = `edit`">Изменить</button>
|
||||
<button class="btn btn-danger" @click="deleteSubject(sbjct.id)">Удалить</button>
|
||||
<td>
|
||||
<button class="btn btn-primary mr-2" @click="openModal('edit', sbjct)">Изменить</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" @click="deleteSubject(sbjct.id)">Удалить</button>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@ -36,10 +40,8 @@
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="editModal" @click="closeModal()">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary" v-if="subject.status === `create`"
|
||||
@click="addSubject">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else
|
||||
@click="editSubject(subject)">Сохранить</button>
|
||||
<button type="button" class="btn btn-primary" v-if="subject.status === 'create'" @click="addSubject(subject)">Создать</button>
|
||||
<button type="button" class="btn btn-primary" v-else @click="editSubject(subject)">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -49,12 +51,8 @@
|
||||
import 'axios';
|
||||
import axios from "axios";
|
||||
import Subject from "@/models/Subject";
|
||||
import Group from "@/models/Group";
|
||||
export default {
|
||||
computed: {
|
||||
Subject() {
|
||||
return Subject
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getSubjects();
|
||||
},
|
||||
@ -82,9 +80,9 @@ export default {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
addSubject(){
|
||||
addSubject(subject){
|
||||
console.log(this.subjects);
|
||||
axios.post(this.URL + "subject", this.subject)
|
||||
axios.post(this.URL + "subject", subject)
|
||||
.then(() => {
|
||||
this.getSubjects();
|
||||
this.closeModal();
|
||||
@ -92,7 +90,6 @@ export default {
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
this.subject = new Subject();
|
||||
},
|
||||
deleteSubject(id){
|
||||
axios.delete(this.URL + `subject/${id}`)
|
||||
@ -101,14 +98,25 @@ export default {
|
||||
})
|
||||
},
|
||||
editSubject(subject){
|
||||
this.subject = subject;
|
||||
axios.put(this.URL + `subject/${subject.id}`, this.subject)
|
||||
axios.put(this.URL + `subject/${subject.id}`, subject)
|
||||
.then(() =>{
|
||||
const index = this.subjects.findIndex((s) => s.id === subject.id);
|
||||
if (index !== -1) {
|
||||
this.subjects[index] = { ...subject };
|
||||
}
|
||||
this.closeModal();
|
||||
this.getSubjects();
|
||||
})
|
||||
this.closeModal();
|
||||
},
|
||||
openModal() {
|
||||
openModal(status, subject = null) {
|
||||
if (status === "create") {
|
||||
this.subject = new Group();
|
||||
this.subject.status = "create";
|
||||
} else if (status === "edit" && subject) {
|
||||
this.subject = { ...subject };
|
||||
this.subject.status = "edit";
|
||||
}
|
||||
document.getElementById("editModal").style.display = "block";
|
||||
},
|
||||
closeModal() {
|
||||
|
@ -1,9 +1,11 @@
|
||||
package ru.IP_LabWorks.IP.University.Contoller.REST;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.IP_LabWorks.IP.University.Contoller.DTO.GroupDTO;
|
||||
import ru.IP_LabWorks.IP.University.Contoller.DTO.StudentDTO;
|
||||
import ru.IP_LabWorks.IP.University.Model.Student;
|
||||
import ru.IP_LabWorks.IP.University.Service.GroupService;
|
||||
|
||||
import java.util.List;
|
||||
@ -44,6 +46,12 @@ public class GroupController {
|
||||
return new GroupDTO(groupService.deleteGroup(id));
|
||||
}
|
||||
|
||||
@GetMapping("/{groupId}/students")
|
||||
public ResponseEntity<List<Student>> getStudentsFromGroup(@PathVariable Long groupId) {
|
||||
List<Student> students = groupService.getStudentFromGroup(groupId);
|
||||
return ResponseEntity.ok(students);
|
||||
}
|
||||
|
||||
// @PostMapping("/{id}/student")
|
||||
// public StudentDTO setStudentToGroup(@PathVariable Long id,
|
||||
// @RequestParam("studentId") Long studentId) {
|
||||
|
@ -64,6 +64,17 @@ public class GroupService {
|
||||
groupRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Student> getStudentFromGroup(Long groupId){
|
||||
Optional<Group> groupOptional = groupRepository.findById(groupId);
|
||||
if (groupOptional.isPresent()) {
|
||||
Group group = groupOptional.get();
|
||||
return group.getStudents();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Group not found with id: " + groupId);
|
||||
}
|
||||
}
|
||||
|
||||
/* @Transactional
|
||||
public Group addStudentToGroup(Long groupId, Long studentId) {
|
||||
Group group = findGroup(groupId);
|
||||
|
Loading…
Reference in New Issue
Block a user