Merge remote-tracking branch 'refs/remotes/origin/main' into Create-Lesson
# Conflicts: # db/init/init.sql
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package com.magistr.app.controller;
|
||||
|
||||
import com.magistr.app.dto.ClassroomRequest;
|
||||
import com.magistr.app.dto.ClassroomResponse;
|
||||
import com.magistr.app.model.Classroom;
|
||||
import com.magistr.app.model.Equipment;
|
||||
import com.magistr.app.repository.ClassroomRepository;
|
||||
import com.magistr.app.repository.EquipmentRepository;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/classrooms")
|
||||
public class ClassroomController {
|
||||
|
||||
private final ClassroomRepository classroomRepository;
|
||||
private final EquipmentRepository equipmentRepository;
|
||||
|
||||
public ClassroomController(ClassroomRepository classroomRepository, EquipmentRepository equipmentRepository) {
|
||||
this.classroomRepository = classroomRepository;
|
||||
this.equipmentRepository = equipmentRepository;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<ClassroomResponse> getAllClassrooms() {
|
||||
return classroomRepository.findAll().stream()
|
||||
.map(this::mapToResponse)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> createClassroom(@RequestBody ClassroomRequest request) {
|
||||
if (request.getName() == null || request.getName().isBlank()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Название аудитории обязательно"));
|
||||
}
|
||||
if (request.getCapacity() == null || request.getCapacity() <= 0) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Вместимость должна быть больше нуля"));
|
||||
}
|
||||
if (classroomRepository.findByName(request.getName().trim()).isPresent()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Аудитория с таким названием уже существует"));
|
||||
}
|
||||
|
||||
Classroom classroom = new Classroom();
|
||||
classroom.setName(request.getName().trim());
|
||||
classroom.setCapacity(request.getCapacity());
|
||||
classroom.setIsAvailable(request.getIsAvailable() != null ? request.getIsAvailable() : true);
|
||||
|
||||
if (request.getEquipmentIds() != null && !request.getEquipmentIds().isEmpty()) {
|
||||
List<Equipment> equipments = equipmentRepository.findAllById(request.getEquipmentIds());
|
||||
classroom.setEquipments(new java.util.HashSet<>(equipments));
|
||||
}
|
||||
|
||||
classroomRepository.save(classroom);
|
||||
return ResponseEntity.ok(mapToResponse(classroom));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<?> updateClassroom(@PathVariable Long id, @RequestBody ClassroomRequest request) {
|
||||
Optional<Classroom> opt = classroomRepository.findById(id);
|
||||
if (opt.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
Classroom classroom = opt.get();
|
||||
|
||||
if (request.getName() != null && !request.getName().isBlank()
|
||||
&& !classroom.getName().equals(request.getName().trim())) {
|
||||
if (classroomRepository.findByName(request.getName().trim()).isPresent()) {
|
||||
return ResponseEntity.badRequest()
|
||||
.body(Map.of("message", "Аудитория с таким названием уже существует"));
|
||||
}
|
||||
classroom.setName(request.getName().trim());
|
||||
}
|
||||
|
||||
if (request.getCapacity() != null && request.getCapacity() > 0) {
|
||||
classroom.setCapacity(request.getCapacity());
|
||||
}
|
||||
|
||||
if (request.getIsAvailable() != null) {
|
||||
classroom.setIsAvailable(request.getIsAvailable());
|
||||
}
|
||||
|
||||
if (request.getEquipmentIds() != null) {
|
||||
List<Equipment> equipments = equipmentRepository.findAllById(request.getEquipmentIds());
|
||||
classroom.setEquipments(new java.util.HashSet<>(equipments));
|
||||
}
|
||||
|
||||
classroomRepository.save(classroom);
|
||||
return ResponseEntity.ok(mapToResponse(classroom));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<?> deleteClassroom(@PathVariable Long id) {
|
||||
if (!classroomRepository.existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
classroomRepository.deleteById(id);
|
||||
return ResponseEntity.ok(Map.of("message", "Аудитория удалена"));
|
||||
}
|
||||
|
||||
private ClassroomResponse mapToResponse(Classroom c) {
|
||||
return new ClassroomResponse(c.getId(), c.getName(), c.getCapacity(), c.getIsAvailable(),
|
||||
new java.util.ArrayList<>(c.getEquipments()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.magistr.app.controller;
|
||||
|
||||
import com.magistr.app.model.Equipment;
|
||||
import com.magistr.app.repository.EquipmentRepository;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/equipments")
|
||||
public class EquipmentController {
|
||||
|
||||
private final EquipmentRepository equipmentRepository;
|
||||
|
||||
public EquipmentController(EquipmentRepository equipmentRepository) {
|
||||
this.equipmentRepository = equipmentRepository;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<Equipment> getAllEquipments() {
|
||||
return equipmentRepository.findAll();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> createEquipment(@RequestBody Map<String, String> request) {
|
||||
String name = request.get("name");
|
||||
if (name == null || name.isBlank()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Название обязательно"));
|
||||
}
|
||||
if (equipmentRepository.findByName(name.trim()).isPresent()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Оборудование с таким названием уже существует"));
|
||||
}
|
||||
|
||||
Equipment equipment = new Equipment();
|
||||
equipment.setName(name.trim());
|
||||
equipmentRepository.save(equipment);
|
||||
|
||||
return ResponseEntity.ok(equipment);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<?> deleteEquipment(@PathVariable Long id) {
|
||||
if (!equipmentRepository.existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
equipmentRepository.deleteById(id);
|
||||
return ResponseEntity.ok(Map.of("message", "Оборудование удалено"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.magistr.app.controller;
|
||||
|
||||
import com.magistr.app.model.Subject;
|
||||
import com.magistr.app.repository.SubjectRepository;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/subjects")
|
||||
public class SubjectController {
|
||||
|
||||
private final SubjectRepository subjectRepository;
|
||||
|
||||
public SubjectController(SubjectRepository subjectRepository) {
|
||||
this.subjectRepository = subjectRepository;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<Subject> getAllSubjects() {
|
||||
return subjectRepository.findAll();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> createSubject(@RequestBody Map<String, String> request) {
|
||||
String name = request.get("name");
|
||||
if (name == null || name.isBlank()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Название обязательно"));
|
||||
}
|
||||
if (subjectRepository.findByName(name.trim()).isPresent()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Дисциплина с таким названием уже существует"));
|
||||
}
|
||||
|
||||
Subject subject = new Subject();
|
||||
subject.setName(name.trim());
|
||||
subjectRepository.save(subject);
|
||||
|
||||
return ResponseEntity.ok(subject);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<?> deleteSubject(@PathVariable Long id) {
|
||||
if (!subjectRepository.existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
subjectRepository.deleteById(id);
|
||||
return ResponseEntity.ok(Map.of("message", "Дисциплина удалена"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.magistr.app.controller;
|
||||
|
||||
import com.magistr.app.dto.TeacherSubjectResponse;
|
||||
import com.magistr.app.model.TeacherSubject;
|
||||
import com.magistr.app.model.TeacherSubjectId;
|
||||
import com.magistr.app.repository.SubjectRepository;
|
||||
import com.magistr.app.repository.TeacherSubjectRepository;
|
||||
import com.magistr.app.repository.UserRepository;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/teacher-subjects")
|
||||
public class TeacherSubjectController {
|
||||
|
||||
private final TeacherSubjectRepository teacherSubjectRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final SubjectRepository subjectRepository;
|
||||
|
||||
public TeacherSubjectController(TeacherSubjectRepository teacherSubjectRepository,
|
||||
UserRepository userRepository,
|
||||
SubjectRepository subjectRepository) {
|
||||
this.teacherSubjectRepository = teacherSubjectRepository;
|
||||
this.userRepository = userRepository;
|
||||
this.subjectRepository = subjectRepository;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<TeacherSubjectResponse> getAll() {
|
||||
return teacherSubjectRepository.findAll().stream()
|
||||
.map(ts -> new TeacherSubjectResponse(
|
||||
ts.getUserId(),
|
||||
ts.getUser().getUsername(),
|
||||
ts.getSubjectId(),
|
||||
ts.getSubject().getName()
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> create(@RequestBody Map<String, Long> request) {
|
||||
Long userId = request.get("userId");
|
||||
Long subjectId = request.get("subjectId");
|
||||
|
||||
if (userId == null || subjectId == null) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "userId и subjectId обязательны"));
|
||||
}
|
||||
if (!userRepository.existsById(userId)) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Преподаватель не найден"));
|
||||
}
|
||||
if (!subjectRepository.existsById(subjectId)) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Дисциплина не найдена"));
|
||||
}
|
||||
|
||||
TeacherSubjectId id = new TeacherSubjectId(userId, subjectId);
|
||||
if (teacherSubjectRepository.existsById(id)) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "Привязка уже существует"));
|
||||
}
|
||||
|
||||
TeacherSubject ts = new TeacherSubject(userId, subjectId);
|
||||
teacherSubjectRepository.save(ts);
|
||||
|
||||
return ResponseEntity.ok(Map.of("message", "Привязка создана"));
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public ResponseEntity<?> delete(@RequestBody Map<String, Long> request) {
|
||||
Long userId = request.get("userId");
|
||||
Long subjectId = request.get("subjectId");
|
||||
|
||||
if (userId == null || subjectId == null) {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", "userId и subjectId обязательны"));
|
||||
}
|
||||
|
||||
TeacherSubjectId id = new TeacherSubjectId(userId, subjectId);
|
||||
if (!teacherSubjectRepository.existsById(id)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
teacherSubjectRepository.deleteById(id);
|
||||
return ResponseEntity.ok(Map.of("message", "Привязка удалена"));
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,13 @@ public class UserController {
|
||||
.toList();
|
||||
}
|
||||
|
||||
@GetMapping("/teachers")
|
||||
public List<UserResponse> getTeachers() {
|
||||
return userRepository.findByRole(Role.TEACHER).stream()
|
||||
.map(u -> new UserResponse(u.getId(), u.getUsername(), u.getRole().name()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> createUser(@RequestBody CreateUserRequest request) {
|
||||
if (request.getUsername() == null || request.getUsername().isBlank()) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.magistr.app.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClassroomRequest {
|
||||
private String name;
|
||||
private Integer capacity;
|
||||
private Boolean isAvailable;
|
||||
private List<Long> equipmentIds;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(Integer capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Boolean getIsAvailable() {
|
||||
return isAvailable;
|
||||
}
|
||||
|
||||
public void setIsAvailable(Boolean isAvailable) {
|
||||
this.isAvailable = isAvailable;
|
||||
}
|
||||
|
||||
public List<Long> getEquipmentIds() {
|
||||
return equipmentIds;
|
||||
}
|
||||
|
||||
public void setEquipmentIds(List<Long> equipmentIds) {
|
||||
this.equipmentIds = equipmentIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.magistr.app.dto;
|
||||
|
||||
import com.magistr.app.model.Equipment;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassroomResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Integer capacity;
|
||||
private Boolean isAvailable;
|
||||
private List<Equipment> equipments;
|
||||
|
||||
public ClassroomResponse() {
|
||||
}
|
||||
|
||||
public ClassroomResponse(Long id, String name, Integer capacity, Boolean isAvailable, List<Equipment> equipments) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.capacity = capacity;
|
||||
this.isAvailable = isAvailable;
|
||||
this.equipments = equipments;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(Integer capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Boolean getIsAvailable() {
|
||||
return isAvailable;
|
||||
}
|
||||
|
||||
public void setIsAvailable(Boolean isAvailable) {
|
||||
this.isAvailable = isAvailable;
|
||||
}
|
||||
|
||||
public List<Equipment> getEquipments() {
|
||||
return equipments;
|
||||
}
|
||||
|
||||
public void setEquipments(List<Equipment> equipments) {
|
||||
this.equipments = equipments;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.magistr.app.dto;
|
||||
|
||||
public class TeacherSubjectResponse {
|
||||
|
||||
private Long userId;
|
||||
private String username;
|
||||
private Long subjectId;
|
||||
private String subjectName;
|
||||
|
||||
public TeacherSubjectResponse(Long userId, String username, Long subjectId, String subjectName) {
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.subjectId = subjectId;
|
||||
this.subjectName = subjectName;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public Long getSubjectId() {
|
||||
return subjectId;
|
||||
}
|
||||
|
||||
public String getSubjectName() {
|
||||
return subjectName;
|
||||
}
|
||||
}
|
||||
70
backend/src/main/java/com/magistr/app/model/Classroom.java
Normal file
70
backend/src/main/java/com/magistr/app/model/Classroom.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.magistr.app.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "classrooms")
|
||||
public class Classroom {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true, nullable = false, length = 50)
|
||||
private String name;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer capacity;
|
||||
|
||||
@Column(name = "is_available", nullable = false)
|
||||
private Boolean isAvailable = true;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "classroom_equipments", joinColumns = @JoinColumn(name = "classroom_id"), inverseJoinColumns = @JoinColumn(name = "equipment_id"))
|
||||
private Set<Equipment> equipments = new HashSet<>();
|
||||
|
||||
public Classroom() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(Integer capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Boolean getIsAvailable() {
|
||||
return isAvailable;
|
||||
}
|
||||
|
||||
public void setIsAvailable(Boolean isAvailable) {
|
||||
this.isAvailable = isAvailable;
|
||||
}
|
||||
|
||||
public Set<Equipment> getEquipments() {
|
||||
return equipments;
|
||||
}
|
||||
|
||||
public void setEquipments(Set<Equipment> equipments) {
|
||||
this.equipments = equipments;
|
||||
}
|
||||
}
|
||||
39
backend/src/main/java/com/magistr/app/model/Equipment.java
Normal file
39
backend/src/main/java/com/magistr/app/model/Equipment.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.magistr.app.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "equipments")
|
||||
public class Equipment {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true, nullable = false, length = 50)
|
||||
private String name;
|
||||
|
||||
public Equipment() {
|
||||
}
|
||||
|
||||
public Equipment(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
39
backend/src/main/java/com/magistr/app/model/Subject.java
Normal file
39
backend/src/main/java/com/magistr/app/model/Subject.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.magistr.app.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "subjects")
|
||||
public class Subject {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true, nullable = false, length = 200)
|
||||
private String name;
|
||||
|
||||
public Subject() {
|
||||
}
|
||||
|
||||
public Subject(Long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.magistr.app.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "teacher_subjects")
|
||||
@IdClass(TeacherSubjectId.class)
|
||||
public class TeacherSubject {
|
||||
|
||||
@Id
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@Id
|
||||
@Column(name = "subject_id")
|
||||
private Long subjectId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "user_id", insertable = false, updatable = false)
|
||||
private User user;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "subject_id", insertable = false, updatable = false)
|
||||
private Subject subject;
|
||||
|
||||
public TeacherSubject() {
|
||||
}
|
||||
|
||||
public TeacherSubject(Long userId, Long subjectId) {
|
||||
this.userId = userId;
|
||||
this.subjectId = subjectId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getSubjectId() {
|
||||
return subjectId;
|
||||
}
|
||||
|
||||
public void setSubjectId(Long subjectId) {
|
||||
this.subjectId = subjectId;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Subject getSubject() {
|
||||
return subject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.magistr.app.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TeacherSubjectId implements Serializable {
|
||||
|
||||
private Long userId;
|
||||
private Long subjectId;
|
||||
|
||||
public TeacherSubjectId() {
|
||||
}
|
||||
|
||||
public TeacherSubjectId(Long userId, Long subjectId) {
|
||||
this.userId = userId;
|
||||
this.subjectId = subjectId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getSubjectId() {
|
||||
return subjectId;
|
||||
}
|
||||
|
||||
public void setSubjectId(Long subjectId) {
|
||||
this.subjectId = subjectId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof TeacherSubjectId that)) return false;
|
||||
return Objects.equals(userId, that.userId) && Objects.equals(subjectId, that.subjectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(userId, subjectId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.magistr.app.repository;
|
||||
|
||||
import com.magistr.app.model.Classroom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ClassroomRepository extends JpaRepository<Classroom, Long> {
|
||||
Optional<Classroom> findByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.magistr.app.repository;
|
||||
|
||||
import com.magistr.app.model.Equipment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface EquipmentRepository extends JpaRepository<Equipment, Long> {
|
||||
Optional<Equipment> findByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.magistr.app.repository;
|
||||
|
||||
import com.magistr.app.model.Subject;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface SubjectRepository extends JpaRepository<Subject, Long> {
|
||||
Optional<Subject> findByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.magistr.app.repository;
|
||||
|
||||
import com.magistr.app.model.TeacherSubject;
|
||||
import com.magistr.app.model.TeacherSubjectId;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TeacherSubjectRepository extends JpaRepository<TeacherSubject, TeacherSubjectId> {
|
||||
List<TeacherSubject> findByUserId(Long userId);
|
||||
List<TeacherSubject> findBySubjectId(Long subjectId);
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.magistr.app.repository;
|
||||
|
||||
import com.magistr.app.model.Role;
|
||||
import com.magistr.app.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
List<User> findByRole(Role role);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user