Добавил новые поля в создание занятия и получение общего списка
This commit is contained in:
@@ -5,6 +5,7 @@ import com.magistr.app.dto.LessonResponse;
|
|||||||
import com.magistr.app.model.*;
|
import com.magistr.app.model.*;
|
||||||
import com.magistr.app.repository.*;
|
import com.magistr.app.repository.*;
|
||||||
import com.magistr.app.utils.DayAndWeekValidator;
|
import com.magistr.app.utils.DayAndWeekValidator;
|
||||||
|
import com.magistr.app.utils.TypeAndFormatLessonValidator;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -25,13 +26,15 @@ public class LessonsController {
|
|||||||
private final GroupRepository groupRepository;
|
private final GroupRepository groupRepository;
|
||||||
private final SubjectRepository subjectRepository;
|
private final SubjectRepository subjectRepository;
|
||||||
private final EducationFormRepository educationFormRepository;
|
private final EducationFormRepository educationFormRepository;
|
||||||
|
private final ClassroomRepository classroomRepository;
|
||||||
|
|
||||||
public LessonsController(LessonRepository lessonRepository, UserRepository teacherRepository, GroupRepository groupRepository, SubjectRepository subjectRepository, EducationFormRepository educationForm) {
|
public LessonsController(LessonRepository lessonRepository, UserRepository teacherRepository, GroupRepository groupRepository, SubjectRepository subjectRepository, EducationFormRepository educationForm, ClassroomRepository classroomRepository) {
|
||||||
this.lessonRepository = lessonRepository;
|
this.lessonRepository = lessonRepository;
|
||||||
this.teacherRepository = teacherRepository;
|
this.teacherRepository = teacherRepository;
|
||||||
this.groupRepository = groupRepository;
|
this.groupRepository = groupRepository;
|
||||||
this.subjectRepository = subjectRepository;
|
this.subjectRepository = subjectRepository;
|
||||||
this.educationFormRepository = educationForm;
|
this.educationFormRepository = educationForm;
|
||||||
|
this.classroomRepository = classroomRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@@ -54,13 +57,42 @@ public class LessonsController {
|
|||||||
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Проверка lessonTypeId
|
//Проверка subjectId
|
||||||
if (request.getSubjectId() == null || request.getSubjectId() == 0) {
|
if (request.getSubjectId() == null || request.getSubjectId() == 0) {
|
||||||
String errorMessage = "ID предмета обязателен";
|
String errorMessage = "ID предмета обязателен";
|
||||||
logger.info("Ошибка валидации: {}", errorMessage);
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Проверка lessonFormat
|
||||||
|
if (request.getLessonFormat() == null || request.getLessonFormat().isBlank()) {
|
||||||
|
String errorMessage = "Выбор формата занятия обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
} else if(!TypeAndFormatLessonValidator.isValidFormat(request.getLessonFormat())){
|
||||||
|
String errorMessage = "Некорректный формат занятий. " + TypeAndFormatLessonValidator.getValidFormatsMessage();
|
||||||
|
logger.info("Ошибка валидации формата: '{}' - {}", request.getLessonFormat(), errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Проверка typeLesson
|
||||||
|
if (request.getTypeLesson() == null || request.getTypeLesson().isBlank()) {
|
||||||
|
String errorMessage = "Выбор типа занятия обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
} else if(!TypeAndFormatLessonValidator.isValidType(request.getTypeLesson())){
|
||||||
|
String errorMessage = "Некорректный тип занятия. " + TypeAndFormatLessonValidator.getValidTypesMessage();
|
||||||
|
logger.info("Ошибка валидации типа: '{}' - {}", request.getTypeLesson(), errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Проверка classroomId
|
||||||
|
if (request.getClassroomId() == null || request.getClassroomId() == 0) {
|
||||||
|
String errorMessage = "ID аудитории обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
//Проверка day
|
//Проверка day
|
||||||
if (request.getDay() == null || request.getDay().isBlank()) {
|
if (request.getDay() == null || request.getDay().isBlank()) {
|
||||||
String errorMessage = "Выбор дня обязателен";
|
String errorMessage = "Выбор дня обязателен";
|
||||||
@@ -96,6 +128,9 @@ public class LessonsController {
|
|||||||
lesson.setTeacherId(request.getTeacherId());
|
lesson.setTeacherId(request.getTeacherId());
|
||||||
lesson.setSubjectId(request.getSubjectId());
|
lesson.setSubjectId(request.getSubjectId());
|
||||||
lesson.setGroupId(request.getGroupId());
|
lesson.setGroupId(request.getGroupId());
|
||||||
|
lesson.setLessonFormat(request.getLessonFormat());
|
||||||
|
lesson.setTypeLesson(request.getTypeLesson());
|
||||||
|
lesson.setClassroomId(request.getClassroomId());
|
||||||
lesson.setDay(request.getDay());
|
lesson.setDay(request.getDay());
|
||||||
lesson.setWeek(request.getWeek());
|
lesson.setWeek(request.getWeek());
|
||||||
lesson.setTime(request.getTime());
|
lesson.setTime(request.getTime());
|
||||||
@@ -107,6 +142,9 @@ public class LessonsController {
|
|||||||
response.put("teacherId", savedLesson.getTeacherId());
|
response.put("teacherId", savedLesson.getTeacherId());
|
||||||
response.put("groupId", savedLesson.getGroupId());
|
response.put("groupId", savedLesson.getGroupId());
|
||||||
response.put("subjectId", savedLesson.getSubjectId());
|
response.put("subjectId", savedLesson.getSubjectId());
|
||||||
|
response.put("formatLesson", savedLesson.getLessonFormat());
|
||||||
|
response.put("typeLesson", savedLesson.getTypeLesson());
|
||||||
|
response.put("classroomId", savedLesson.getClassroomId());
|
||||||
response.put("day", savedLesson.getDay());
|
response.put("day", savedLesson.getDay());
|
||||||
response.put("week", savedLesson.getWeek());
|
response.put("week", savedLesson.getWeek());
|
||||||
response.put("time", savedLesson.getTime());
|
response.put("time", savedLesson.getTime());
|
||||||
@@ -152,12 +190,19 @@ public class LessonsController {
|
|||||||
.map(Subject::getName)
|
.map(Subject::getName)
|
||||||
.orElse("Неизвестно");
|
.orElse("Неизвестно");
|
||||||
|
|
||||||
|
String classroomName = classroomRepository.findById(lesson.getClassroomId())
|
||||||
|
.map(Classroom::getName)
|
||||||
|
.orElse("Неизвестно");
|
||||||
|
|
||||||
return new LessonResponse(
|
return new LessonResponse(
|
||||||
lesson.getId(),
|
lesson.getId(),
|
||||||
teacherName,
|
teacherName,
|
||||||
groupName,
|
groupName,
|
||||||
|
classroomName,
|
||||||
educationFormName,
|
educationFormName,
|
||||||
subjectName,
|
subjectName,
|
||||||
|
lesson.getTypeLesson(),
|
||||||
|
lesson.getLessonFormat(),
|
||||||
lesson.getDay(),
|
lesson.getDay(),
|
||||||
lesson.getWeek(),
|
lesson.getWeek(),
|
||||||
lesson.getTime()
|
lesson.getTime()
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ public class CreateLessonRequest {
|
|||||||
private Long teacherId;
|
private Long teacherId;
|
||||||
private Long groupId;
|
private Long groupId;
|
||||||
private Long subjectId;
|
private Long subjectId;
|
||||||
|
private String lessonFormat;
|
||||||
|
private String typeLesson;
|
||||||
|
private Long classroomId;
|
||||||
private String day;
|
private String day;
|
||||||
private String week;
|
private String week;
|
||||||
private String time;
|
private String time;
|
||||||
@@ -36,6 +39,30 @@ public class CreateLessonRequest {
|
|||||||
this.subjectId = subjectId;
|
this.subjectId = subjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLessonFormat() {
|
||||||
|
return lessonFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonFormat(String lessonFormat) {
|
||||||
|
this.lessonFormat = lessonFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTypeLesson() {
|
||||||
|
return typeLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeLesson(String typeLesson) {
|
||||||
|
this.typeLesson = typeLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getClassroomId() {
|
||||||
|
return classroomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassroomId(Long classroomId) {
|
||||||
|
this.classroomId = classroomId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDay() {
|
public String getDay() {
|
||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ public class LessonResponse {
|
|||||||
private String educationFormName;
|
private String educationFormName;
|
||||||
private Long subjectId;
|
private Long subjectId;
|
||||||
private String subjectName;
|
private String subjectName;
|
||||||
|
private String lessonFormat;
|
||||||
|
private String typeLesson;
|
||||||
|
private Long classroomId;
|
||||||
|
private String classroomName;
|
||||||
private String day;
|
private String day;
|
||||||
private String week;
|
private String week;
|
||||||
private String time;
|
private String time;
|
||||||
@@ -31,12 +35,15 @@ public class LessonResponse {
|
|||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LessonResponse(Long id, String teacherName, String groupName, String educationFormName, String subjectName, String day, String week, String time) {
|
public LessonResponse(Long id, String teacherName, String groupName, String classroomName, String educationFormName, String subjectName, String typeLesson, String lessonFormat, String day, String week, String time) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.teacherName = teacherName;
|
this.teacherName = teacherName;
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
|
this.classroomName = classroomName;
|
||||||
this.educationFormName = educationFormName;
|
this.educationFormName = educationFormName;
|
||||||
this.subjectName = subjectName;
|
this.subjectName = subjectName;
|
||||||
|
this.typeLesson = typeLesson;
|
||||||
|
this.lessonFormat = lessonFormat;
|
||||||
this.day = day;
|
this.day = day;
|
||||||
this.week = week;
|
this.week = week;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
@@ -82,6 +89,38 @@ public class LessonResponse {
|
|||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTypeLesson() {
|
||||||
|
return typeLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeLesson(String typeLesson) {
|
||||||
|
this.typeLesson = typeLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonFormat() {
|
||||||
|
return lessonFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonFormat(String lessonFormat) {
|
||||||
|
this.lessonFormat = lessonFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getClassroomId() {
|
||||||
|
return classroomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassroomId(Long classroomId) {
|
||||||
|
this.classroomId = classroomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassroomName() {
|
||||||
|
return classroomName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassroomName(String classroomName) {
|
||||||
|
this.classroomName = classroomName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getEducationFormName() {
|
public String getEducationFormName() {
|
||||||
return educationFormName;
|
return educationFormName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,15 @@ public class Lesson {
|
|||||||
@Column(name = "subject_id", nullable = false)
|
@Column(name = "subject_id", nullable = false)
|
||||||
private Long subjectId;
|
private Long subjectId;
|
||||||
|
|
||||||
|
@Column(name = "lesson_format", nullable = false, length = 255)
|
||||||
|
private String lessonFormat;
|
||||||
|
|
||||||
|
@Column(name = "type_lesson", nullable = false, length = 255)
|
||||||
|
private String typeLesson;
|
||||||
|
|
||||||
|
@Column(name = "classroom_id", nullable = false)
|
||||||
|
private Long classroomId;
|
||||||
|
|
||||||
@Column(name = "day", nullable = false, length = 255)
|
@Column(name = "day", nullable = false, length = 255)
|
||||||
private String day;
|
private String day;
|
||||||
|
|
||||||
@@ -63,6 +72,30 @@ public class Lesson {
|
|||||||
this.subjectId = subjectId;
|
this.subjectId = subjectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLessonFormat() {
|
||||||
|
return lessonFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonFormat(String lessonFormat) {
|
||||||
|
this.lessonFormat = lessonFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTypeLesson() {
|
||||||
|
return typeLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTypeLesson(String typeLesson) {
|
||||||
|
this.typeLesson = typeLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getClassroomId() {
|
||||||
|
return classroomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassroomId(Long classroomId) {
|
||||||
|
this.classroomId = classroomId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDay() {
|
public String getDay() {
|
||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.magistr.app.utils;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class TypeAndFormatLessonValidator {
|
||||||
|
|
||||||
|
private static final Set<String> VALID_TYPES = Set.of(
|
||||||
|
"Лекция", "Лабораторная работа", "Практическая"
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Set<String> VALID_FORMATS = Set.of(
|
||||||
|
"Онлайн", "Очно"
|
||||||
|
);
|
||||||
|
|
||||||
|
public static boolean isValidType(String type) {
|
||||||
|
return type != null && VALID_TYPES.contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isValidFormat(String format) {
|
||||||
|
return format != null && VALID_FORMATS.contains(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValidTypesMessage() {
|
||||||
|
return "Допустимые типы: " + String.join(", ", VALID_TYPES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValidFormatsMessage() {
|
||||||
|
return "Допустимые форматы: " + String.join(", ", VALID_FORMATS);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -186,6 +186,9 @@ CREATE TABLE IF NOT EXISTS lessons (
|
|||||||
teacher_id BIGINT NOT NULL REFERENCES users(id),
|
teacher_id BIGINT NOT NULL REFERENCES users(id),
|
||||||
group_id BIGINT NOT NULL REFERENCES student_groups(id),
|
group_id BIGINT NOT NULL REFERENCES student_groups(id),
|
||||||
subject_id BIGINT NOT NULL REFERENCES subjects(id),
|
subject_id BIGINT NOT NULL REFERENCES subjects(id),
|
||||||
|
lesson_format VARCHAR(255) NOT NULL,
|
||||||
|
type_lesson VARCHAR(255) NOT NULL,
|
||||||
|
classroom_id BIGINT NOT NULL REFERENCES classrooms(id),
|
||||||
day VARCHAR(255) NOT NULL,
|
day VARCHAR(255) NOT NULL,
|
||||||
week VARCHAR(255) NOT NULL,
|
week VARCHAR(255) NOT NULL,
|
||||||
time VARCHAR(255) NOT NULL
|
time VARCHAR(255) NOT NULL
|
||||||
|
|||||||
Reference in New Issue
Block a user