Поправил создание кафедрального файла
This commit is contained in:
@@ -4,6 +4,7 @@ import com.magistr.app.dto.CreateScheduleDataRequest;
|
|||||||
import com.magistr.app.dto.ScheduleResponse;
|
import com.magistr.app.dto.ScheduleResponse;
|
||||||
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.SemesterTypeValidator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -147,8 +148,91 @@ public class ScheduleDataController {
|
|||||||
// Доделать проверки получаемых полей!!!
|
// Доделать проверки получаемых полей!!!
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<?> createScheduleData(@RequestBody CreateScheduleDataRequest request) {
|
public ResponseEntity<?> createScheduleData(@RequestBody CreateScheduleDataRequest request) {
|
||||||
logger.info("Получен запрос на создание записи данных для расписаний");
|
logger.info("Получен запрос на создание записи данных для расписаний: departmentId={}, semester={}, groupId={}, subjectsId={}, lessonTypeId={}, numberOfHours={}, division={}, teacherId={}, semesterType={}, period={}",
|
||||||
|
request.getDepartmentId(), request.getSemester(), request.getGroupId(), request.getSubjectsId(), request.getLessonTypeId(), request.getNumberOfHours(), request.getDivision(), request.getTeacherId(), request.getSemesterType(), request.getPeriod());
|
||||||
try {
|
try {
|
||||||
|
if (request.getDepartmentId() == null || request.getDepartmentId() == 0) {
|
||||||
|
String errorMessage = "ID кафедры обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
} else if(!scheduleDataRepository.existsById(request.getDepartmentId())) {
|
||||||
|
String errorMessage = "Кафедра не найдена";
|
||||||
|
logger.info("Кафедра не найдена");
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getSemester() == null || request.getSemester() == 0) {
|
||||||
|
String errorMessage = "Семестр обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
} else if(request.getSemester() > 12) {
|
||||||
|
String errorMessage = "Семестр должен быть меньше или равен 12";
|
||||||
|
logger.info("Семестр должен быть меньше или равен 12");
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getGroupId() == null || request.getGroupId() == 0) {
|
||||||
|
String errorMessage = "ID группы обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getSubjectsId() == null || request.getSubjectsId() == 0) {
|
||||||
|
String errorMessage = "ID дисциплины обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getLessonTypeId() == null || request.getLessonTypeId() == 0) {
|
||||||
|
String errorMessage = "ID типа занятия обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getNumberOfHours() == null) {
|
||||||
|
request.setNumberOfHours(0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getTeacherId() == null || request.getTeacherId() == 0) {
|
||||||
|
String errorMessage = "ID преподавателя обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getSemesterType() == null) {
|
||||||
|
String errorMessage = "Семестр обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
} else if (!SemesterTypeValidator.isValidTypeSemester(request.getSemesterType().toString())) {
|
||||||
|
String errorMessage = "Некорректный формат семестра. Допустимые форматы: " + SemesterTypeValidator.getValidTypes();
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getPeriod() == null || request.getPeriod().isBlank()) {
|
||||||
|
String errorMessage = "Период обязателен";
|
||||||
|
logger.info("Ошибка валидации: {}", errorMessage);
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean existsRecord = scheduleDataRepository.existsByDepartmentIdAndSemesterAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
|
||||||
|
request.getDepartmentId(),
|
||||||
|
request.getSemester(),
|
||||||
|
request.getGroupId(),
|
||||||
|
request.getSubjectsId(),
|
||||||
|
request.getLessonTypeId(),
|
||||||
|
request.getNumberOfHours(),
|
||||||
|
request.getDivision(),
|
||||||
|
request.getTeacherId(),
|
||||||
|
request.getSemesterType(),
|
||||||
|
request.getPeriod()
|
||||||
|
);
|
||||||
|
|
||||||
|
if(existsRecord) {
|
||||||
|
return ResponseEntity.status(HttpStatus.CONFLICT)
|
||||||
|
.body(Map.of("message", "Такая запись уже существует"));
|
||||||
|
}
|
||||||
|
|
||||||
ScheduleData scheduleData = new ScheduleData();
|
ScheduleData scheduleData = new ScheduleData();
|
||||||
scheduleData.setDepartmentId(request.getDepartmentId());
|
scheduleData.setDepartmentId(request.getDepartmentId());
|
||||||
scheduleData.setSemester(request.getSemester());
|
scheduleData.setSemester(request.getSemester());
|
||||||
@@ -179,6 +263,9 @@ public class ScheduleDataController {
|
|||||||
logger.info("Запись успешно создана с ID: {}", savedSchedule.getId());
|
logger.info("Запись успешно создана с ID: {}", savedSchedule.getId());
|
||||||
|
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
|
} catch (org.springframework.dao.DataIntegrityViolationException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.CONFLICT)
|
||||||
|
.body(Map.of("message", "Такая запись уже существует"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Ошибка при создании записи: {}", e.getMessage(), e);
|
logger.error("Ошибка при создании записи: {}", e.getMessage(), e);
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class CreateScheduleDataRequest {
|
|||||||
private Long subjectsId;
|
private Long subjectsId;
|
||||||
private Long lessonTypeId;
|
private Long lessonTypeId;
|
||||||
private Long numberOfHours;
|
private Long numberOfHours;
|
||||||
private Boolean isDivision;
|
private Boolean division;
|
||||||
private Long teacherId;
|
private Long teacherId;
|
||||||
private SemesterType semesterType;
|
private SemesterType semesterType;
|
||||||
private String period;
|
private String period;
|
||||||
@@ -72,11 +72,11 @@ public class CreateScheduleDataRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDivision() {
|
public Boolean getDivision() {
|
||||||
return isDivision;
|
return division;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDivision(Boolean division) {
|
public void setDivision(Boolean division) {
|
||||||
isDivision = division;
|
this.division = division;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTeacherId() {
|
public Long getTeacherId() {
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ public class ScheduleResponse {
|
|||||||
private Long lessonTypeId;
|
private Long lessonTypeId;
|
||||||
private String lessonType;
|
private String lessonType;
|
||||||
private Long numberOfHours;
|
private Long numberOfHours;
|
||||||
private Boolean isDivision;
|
private Boolean division;
|
||||||
private Long teacherId;
|
private Long teacherId;
|
||||||
private String teacherName;
|
private String teacherName;
|
||||||
private String teacherJobTitle;
|
private String teacherJobTitle;
|
||||||
private SemesterType semesterType;
|
private SemesterType semesterType;
|
||||||
private String period;
|
private String period;
|
||||||
|
|
||||||
public ScheduleResponse(Long id, Long departmentId, Long semester, Long groupId, Long subjectsId, Long lessonTypeId, String lessonType, Long numberOfHours, Boolean isDivision, Long teacherId, SemesterType semesterType, String period) {
|
public ScheduleResponse(Long id, Long departmentId, Long semester, Long groupId, Long subjectsId, Long lessonTypeId, String lessonType, Long numberOfHours, Boolean division, Long teacherId, SemesterType semesterType, String period) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.departmentId = departmentId;
|
this.departmentId = departmentId;
|
||||||
this.semester = semester;
|
this.semester = semester;
|
||||||
@@ -32,13 +32,13 @@ public class ScheduleResponse {
|
|||||||
this.subjectsId = subjectsId;
|
this.subjectsId = subjectsId;
|
||||||
this.lessonTypeId = lessonTypeId;
|
this.lessonTypeId = lessonTypeId;
|
||||||
this.numberOfHours = numberOfHours;
|
this.numberOfHours = numberOfHours;
|
||||||
this.isDivision = isDivision;
|
this.division = division;
|
||||||
this.teacherId = teacherId;
|
this.teacherId = teacherId;
|
||||||
this.semesterType = semesterType;
|
this.semesterType = semesterType;
|
||||||
this.period = period;
|
this.period = period;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScheduleResponse(Long id, Long departmentId, String specialityCode, Long semester, String groupName, Integer groupCourse, String subjectName, String lessonType, Long numberOfHours, Boolean isDivision, String teacherName, String teacherJobTitle, SemesterType semesterType, String period) {
|
public ScheduleResponse(Long id, Long departmentId, String specialityCode, Long semester, String groupName, Integer groupCourse, String subjectName, String lessonType, Long numberOfHours, Boolean division, String teacherName, String teacherJobTitle, SemesterType semesterType, String period) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.departmentId = departmentId;
|
this.departmentId = departmentId;
|
||||||
this.specialityCode = specialityCode;
|
this.specialityCode = specialityCode;
|
||||||
@@ -48,7 +48,7 @@ public class ScheduleResponse {
|
|||||||
this.subjectName = subjectName;
|
this.subjectName = subjectName;
|
||||||
this.lessonType = lessonType;
|
this.lessonType = lessonType;
|
||||||
this.numberOfHours = numberOfHours;
|
this.numberOfHours = numberOfHours;
|
||||||
this.isDivision = isDivision;
|
this.division = division;
|
||||||
this.teacherName = teacherName;
|
this.teacherName = teacherName;
|
||||||
this.teacherJobTitle = teacherJobTitle;
|
this.teacherJobTitle = teacherJobTitle;
|
||||||
this.semesterType = semesterType;
|
this.semesterType = semesterType;
|
||||||
@@ -104,7 +104,7 @@ public class ScheduleResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDivision() {
|
public Boolean getDivision() {
|
||||||
return isDivision;
|
return division;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTeacherId() {
|
public Long getTeacherId() {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class ScheduleData {
|
|||||||
private Long numberOfHours;
|
private Long numberOfHours;
|
||||||
|
|
||||||
@Column(name="is_division", nullable = false)
|
@Column(name="is_division", nullable = false)
|
||||||
private Boolean isDivision;
|
private Boolean division;
|
||||||
|
|
||||||
@Column(name="teacher_id", nullable = false)
|
@Column(name="teacher_id", nullable = false)
|
||||||
private Long teacherId;
|
private Long teacherId;
|
||||||
@@ -43,7 +43,7 @@ public class ScheduleData {
|
|||||||
|
|
||||||
public ScheduleData() {}
|
public ScheduleData() {}
|
||||||
|
|
||||||
public ScheduleData(Long id, Long departmentId, Long semester, Long groupId, Long subjectsId, Long lessonTypeId, Long numberOfHours, Boolean isDivision, Long teacherId, SemesterType semesterType, String period) {
|
public ScheduleData(Long id, Long departmentId, Long semester, Long groupId, Long subjectsId, Long lessonTypeId, Long numberOfHours, Boolean division, Long teacherId, SemesterType semesterType, String period) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.departmentId = departmentId;
|
this.departmentId = departmentId;
|
||||||
this.semester = semester;
|
this.semester = semester;
|
||||||
@@ -51,7 +51,7 @@ public class ScheduleData {
|
|||||||
this.subjectsId = subjectsId;
|
this.subjectsId = subjectsId;
|
||||||
this.lessonTypeId = lessonTypeId;
|
this.lessonTypeId = lessonTypeId;
|
||||||
this.numberOfHours = numberOfHours;
|
this.numberOfHours = numberOfHours;
|
||||||
this.isDivision = isDivision;
|
this.division = division;
|
||||||
this.teacherId = teacherId;
|
this.teacherId = teacherId;
|
||||||
this.semesterType = semesterType;
|
this.semesterType = semesterType;
|
||||||
this.period = period;
|
this.period = period;
|
||||||
@@ -114,11 +114,11 @@ public class ScheduleData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDivision() {
|
public Boolean getDivision() {
|
||||||
return isDivision;
|
return division;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDivision(Boolean division) {
|
public void setDivision(Boolean division) {
|
||||||
isDivision = division;
|
this.division = division;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTeacherId() {
|
public Long getTeacherId() {
|
||||||
|
|||||||
@@ -9,4 +9,17 @@ import java.util.List;
|
|||||||
public interface ScheduleDataRepository extends JpaRepository<ScheduleData, Long> {
|
public interface ScheduleDataRepository extends JpaRepository<ScheduleData, Long> {
|
||||||
|
|
||||||
List<ScheduleData> findByDepartmentIdAndSemesterTypeAndPeriod(Long departmentId, SemesterType semesterType, String period);
|
List<ScheduleData> findByDepartmentIdAndSemesterTypeAndPeriod(Long departmentId, SemesterType semesterType, String period);
|
||||||
|
|
||||||
|
boolean existsByDepartmentIdAndSemesterAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
|
||||||
|
Long departmentId,
|
||||||
|
Long semester,
|
||||||
|
Long groupId,
|
||||||
|
Long subjectsId,
|
||||||
|
Long lessonTypeId,
|
||||||
|
Long numberOfHours,
|
||||||
|
Boolean division,
|
||||||
|
Long teacherId,
|
||||||
|
SemesterType semesterType,
|
||||||
|
String period
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.magistr.app.utils;
|
||||||
|
|
||||||
|
import com.magistr.app.model.SemesterType;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class SemesterTypeValidator {
|
||||||
|
|
||||||
|
public static boolean isValidTypeSemester(String semesterType) {
|
||||||
|
if (semesterType == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
SemesterType.valueOf(semesterType);
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValidTypes() {
|
||||||
|
return String.join(", ", Arrays.stream(SemesterType.values())
|
||||||
|
.map(Enum::name)
|
||||||
|
.toArray(String[]::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -230,7 +230,7 @@ export async function initDepartment() {
|
|||||||
const lessonTypeName = LESSON_TYPE_LABELS[s.lessonTypeId] || 'Неизвестно';
|
const lessonTypeName = LESSON_TYPE_LABELS[s.lessonTypeId] || 'Неизвестно';
|
||||||
const semLabel = SEMESTER_LABELS[s.semesterType] || s.semesterType;
|
const semLabel = SEMESTER_LABELS[s.semesterType] || s.semesterType;
|
||||||
const periodDisplay = s.period.replace('-', '/');
|
const periodDisplay = s.period.replace('-', '/');
|
||||||
const divText = s.isDivision ? '✓' : '';
|
const divText = s.division ? '✓' : '';
|
||||||
const hasError = !!s._errorMsg;
|
const hasError = !!s._errorMsg;
|
||||||
const rowStyle = hasError ? ' style="background: rgba(239, 68, 68, 0.08);"' : '';
|
const rowStyle = hasError ? ' style="background: rgba(239, 68, 68, 0.08);"' : '';
|
||||||
let row = `
|
let row = `
|
||||||
@@ -288,7 +288,7 @@ export async function initDepartment() {
|
|||||||
const subjectId = csSubjectSelect.value;
|
const subjectId = csSubjectSelect.value;
|
||||||
const lessonTypeId = document.getElementById('cs-lesson-type').value;
|
const lessonTypeId = document.getElementById('cs-lesson-type').value;
|
||||||
const hours = document.getElementById('cs-hours').value;
|
const hours = document.getElementById('cs-hours').value;
|
||||||
const isDivision = document.getElementById('cs-division').checked;
|
const division = document.getElementById('cs-division').checked;
|
||||||
const teacherId = csTeacherSelect.value;
|
const teacherId = csTeacherSelect.value;
|
||||||
|
|
||||||
if (!period || !semesterType || !semester || !groupId || !subjectId || !lessonTypeId || !hours || !teacherId) {
|
if (!period || !semesterType || !semester || !groupId || !subjectId || !lessonTypeId || !hours || !teacherId) {
|
||||||
@@ -303,7 +303,7 @@ export async function initDepartment() {
|
|||||||
subjectsId: Number(subjectId),
|
subjectsId: Number(subjectId),
|
||||||
lessonTypeId: Number(lessonTypeId),
|
lessonTypeId: Number(lessonTypeId),
|
||||||
numberOfHours: Number(hours),
|
numberOfHours: Number(hours),
|
||||||
isDivision: isDivision,
|
division: division,
|
||||||
teacherId: Number(teacherId),
|
teacherId: Number(teacherId),
|
||||||
semesterType: semesterType,
|
semesterType: semesterType,
|
||||||
period: period
|
period: period
|
||||||
@@ -318,7 +318,7 @@ export async function initDepartment() {
|
|||||||
s.subjectsId === newRecord.subjectsId &&
|
s.subjectsId === newRecord.subjectsId &&
|
||||||
s.lessonTypeId === newRecord.lessonTypeId &&
|
s.lessonTypeId === newRecord.lessonTypeId &&
|
||||||
s.numberOfHours === newRecord.numberOfHours &&
|
s.numberOfHours === newRecord.numberOfHours &&
|
||||||
s.isDivision === newRecord.isDivision &&
|
s.division === newRecord.division &&
|
||||||
s.teacherId === newRecord.teacherId
|
s.teacherId === newRecord.teacherId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<input type="text" id="new-jobtitle" placeholder="Студент / Доцент" required>
|
<input type="text" id="new-jobtitle" placeholder="Студент / Доцент" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="new-department">Кафедра</label>
|
<label for="new-department">ID Кафедры</label>
|
||||||
<input type="number" id="new-department" placeholder="ID" required>
|
<input type="number" id="new-department" placeholder="ID" required>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn-primary">Создать</button>
|
<button type="submit" class="btn-primary">Создать</button>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
<th>Имя пользователя</th>
|
<th>Имя пользователя</th>
|
||||||
<th>ФИО</th>
|
<th>ФИО</th>
|
||||||
<th>Должность</th>
|
<th>Должность</th>
|
||||||
<th>ID кафедры</th>
|
<th>Кафедра</th>
|
||||||
<th>Роль</th>
|
<th>Роль</th>
|
||||||
<th colspan="2">Действия</th>
|
<th colspan="2">Действия</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user