Добавил еще немного

This commit is contained in:
ProstoDenya01
2026-02-25 22:56:44 +03:00
parent e44ac04cac
commit 94aa164930
6 changed files with 48 additions and 36 deletions

View File

@@ -28,7 +28,7 @@ public class TestController {
if (request.getGroupId() == null || request.getGroupId() == 0) { if (request.getGroupId() == null || request.getGroupId() == 0) {
return ResponseEntity.badRequest().body(Map.of("message", "ID группы обязателен")); return ResponseEntity.badRequest().body(Map.of("message", "ID группы обязателен"));
} }
if (request.getLessonId() == null || request.getLessonId() == 0) { if (request.getDisciplineId() == null || request.getDisciplineId() == 0) {
return ResponseEntity.badRequest().body(Map.of("message", "ID предмета обязателен")); return ResponseEntity.badRequest().body(Map.of("message", "ID предмета обязателен"));
} }
if (request.getDay() == null || request.getDay().isBlank()) { if (request.getDay() == null || request.getDay().isBlank()) {
@@ -43,7 +43,7 @@ public class TestController {
Lesson lesson = new Lesson(); Lesson lesson = new Lesson();
lesson.setTeacherId(request.getTeacherId()); lesson.setTeacherId(request.getTeacherId());
lesson.setLessonId(request.getLessonId()); lesson.setDisciplineId(request.getDisciplineId());
lesson.setGroupId(request.getGroupId()); lesson.setGroupId(request.getGroupId());
lesson.setDay(request.getDay()); lesson.setDay(request.getDay());
lesson.setWeek(request.getWeek()); lesson.setWeek(request.getWeek());
@@ -56,7 +56,7 @@ public class TestController {
@GetMapping @GetMapping
public List<LessonResponse> getAllLessons() { public List<LessonResponse> getAllLessons() {
return lessonRepository.findAll().stream() return lessonRepository.findAll().stream()
.map(l -> new LessonResponse(l.getId(), l.getTeacherId(), l.getLessonId(), l.getDay(), l.getWeek(), l.getTime())) .map(l -> new LessonResponse(l.getId(), l.getTeacherId(), l.getDisciplineId(), l.getDay(), l.getWeek(), l.getTime()))
.toList(); .toList();
} }

View File

@@ -4,7 +4,7 @@ public class CreateLessonRequest {
private Long teacherId; private Long teacherId;
private Long groupId; private Long groupId;
private Long lessonId; private Long disciplineId;
private String day; private String day;
private String week; private String week;
private String time; private String time;
@@ -28,12 +28,12 @@ public class CreateLessonRequest {
this.groupId = groupId; this.groupId = groupId;
} }
public Long getLessonId() { public Long getDisciplineId() {
return lessonId; return disciplineId;
} }
public void setLessonId(Long lessonId) { public void setDisciplineId(Long disciplineId) {
this.lessonId= lessonId; this.disciplineId= disciplineId;
} }
public String getDay() { public String getDay() {

View File

@@ -5,7 +5,7 @@ public class LessonResponse {
private Long id; private Long id;
private Long teacherId; private Long teacherId;
private Long groupId; private Long groupId;
private Long lessonId; private Long disciplineId;
private String day; private String day;
private String week; private String week;
private String time; private String time;
@@ -13,17 +13,17 @@ public class LessonResponse {
public LessonResponse() { public LessonResponse() {
} }
public LessonResponse(Long lessonId, String day, String week, String time) { public LessonResponse(Long disciplineId, String day, String week, String time) {
this.lessonId = lessonId; this.disciplineId = disciplineId;
this.day = day; this.day = day;
this.week = week; this.week = week;
this.time = time; this.time = time;
} }
public LessonResponse(Long id, Long teacherId, Long lessonId, String day, String week, String time) { public LessonResponse(Long id, Long teacherId, Long disciplineId, String day, String week, String time) {
this.id = id; this.id = id;
this.teacherId = teacherId; this.teacherId = teacherId;
this.lessonId = lessonId; this.disciplineId = disciplineId;
this.day = day; this.day = day;
this.week = week; this.week = week;
this.time = time; this.time = time;
@@ -53,12 +53,12 @@ public class LessonResponse {
this.groupId = groupId; this.groupId = groupId;
} }
public Long getLessonId() { public Long getDisciplineId() {
return lessonId; return disciplineId;
} }
public void setLessonId(Long lessonId) { public void setDisciplineId(Long disciplineId) {
this.lessonId= lessonId; this.disciplineId = disciplineId;
} }
public String getDay() { public String getDay() {

View File

@@ -10,22 +10,22 @@ public class Lesson {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@Column(nullable = false) @Column(name = "teacher_id", nullable = false)
private Long teacherId; private Long teacherId;
@Column(nullable = false) @Column(name = "group_id", nullable = false)
private Long groupId; private Long groupId;
@Column(nullable = false) @Column(name = "discipline_id", nullable = false)
private Long lessonId; private Long disciplineId;
@Column(nullable = false, length = 255) @Column(name = "day", nullable = false, length = 255)
private String day; private String day;
@Column(nullable = false, length = 255) @Column(name = "week", nullable = false, length = 255)
private String week; private String week;
@Column(nullable = false, length = 255) @Column(name = "time", nullable = false, length = 255)
private String time; private String time;
public Lesson() { public Lesson() {
@@ -55,12 +55,12 @@ public class Lesson {
this.groupId = groupId; this.groupId = groupId;
} }
public Long getLessonId() { public Long getDisciplineId() {
return lessonId; return disciplineId;
} }
public void setLessonId(Long lessonId) { public void setDisciplineId(Long disciplineId) {
this.lessonId = lessonId; this.disciplineId = disciplineId;
} }
public String getDay() { public String getDay() {

View File

@@ -7,5 +7,5 @@ import java.util.Optional;
public interface LessonRepository extends JpaRepository<Lesson, Long> { public interface LessonRepository extends JpaRepository<Lesson, Long> {
Optional<Lesson> findByLessonId(Long lessonId); Optional<Lesson> findByDisciplineId(Long disciplineId);
} }

View File

@@ -1,5 +1,8 @@
CREATE EXTENSION IF NOT EXISTS pgcrypto; CREATE EXTENSION IF NOT EXISTS pgcrypto;
-- =====================================================
-- 1. Таблица users
-- =====================================================
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL, username VARCHAR(50) UNIQUE NOT NULL,
@@ -7,39 +10,48 @@ CREATE TABLE IF NOT EXISTS users (
role VARCHAR(20) NOT NULL DEFAULT 'STUDENT' role VARCHAR(20) NOT NULL DEFAULT 'STUDENT'
); );
-- Админ по умолчанию: admin / admin (bcrypt через pgcrypto) -- Админ по умолчанию
INSERT INTO users (username, password, role) INSERT INTO users (username, password, role)
VALUES ('admin', crypt('admin', gen_salt('bf', 10)), 'ADMIN') VALUES ('admin', crypt('admin', gen_salt('bf', 10)), 'ADMIN')
ON CONFLICT (username) DO NOTHING; ON CONFLICT (username) DO NOTHING;
-- =====================================================
-- 2. Таблица education_forms
-- =====================================================
CREATE TABLE IF NOT EXISTS education_forms ( CREATE TABLE IF NOT EXISTS education_forms (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL name VARCHAR(100) UNIQUE NOT NULL
); );
INSERT INTO education_forms (name) VALUES ('Бакалавриат'), ('Магистратура'), ('Специалитет') INSERT INTO education_forms (name)
VALUES ('Бакалавриат'), ('Магистратура'), ('Специалитет')
ON CONFLICT (name) DO NOTHING; ON CONFLICT (name) DO NOTHING;
-- =====================================================
-- 3. Таблица student_groups
-- =====================================================
CREATE TABLE IF NOT EXISTS student_groups ( CREATE TABLE IF NOT EXISTS student_groups (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL, name VARCHAR(100) UNIQUE NOT NULL,
education_form_id BIGINT NOT NULL REFERENCES education_forms(id) education_form_id BIGINT NOT NULL REFERENCES education_forms(id)
); );
-- =====================================================
-- 4. Таблица lessons (ЭТА ЧАСТЬ БЫЛА ИСПОРЧЕНА)
-- =====================================================
CREATE TABLE IF NOT EXISTS lessons ( CREATE TABLE IF NOT EXISTS lessons (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
teacher_id BIGINT NOT NULL, teacher_id BIGINT NOT NULL,
group_id BIGINT NOT NULL, group_id BIGINT NOT NULL,
lesson_id BIGINT NOT NULL, discipline_id BIGINT NOT NULL,
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
); );
ALTER TABLE lessons -- Добавляем внешние ключи
ADD CONSTRAINT fk_lessons_teacher ALTER TABLE lessons ADD CONSTRAINT fk_lessons_teacher
FOREIGN KEY (teacher_id) REFERENCES users(id); FOREIGN KEY (teacher_id) REFERENCES users(id);
ALTER TABLE lessons ALTER TABLE lessons ADD CONSTRAINT fk_lessons_group
ADD CONSTRAINT fk_lessons_group
FOREIGN KEY (group_id) REFERENCES student_groups(id); FOREIGN KEY (group_id) REFERENCES student_groups(id);