Написал запрос на создание занятия
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
package com.magistr.app.controller;
|
||||||
|
|
||||||
|
import com.magistr.app.dto.CreateLessonRequest;
|
||||||
|
import com.magistr.app.dto.LessonResponse;
|
||||||
|
import com.magistr.app.model.Lesson;
|
||||||
|
import com.magistr.app.repository.LessonRepository;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/users/test")
|
||||||
|
public class TestController {
|
||||||
|
|
||||||
|
private final LessonRepository lessonRepository;
|
||||||
|
|
||||||
|
public TestController(LessonRepository lessonRepository) {
|
||||||
|
this.lessonRepository = lessonRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
public ResponseEntity<?> createLesson(@RequestBody CreateLessonRequest request) {
|
||||||
|
if (request.getTeacherId() == null || request.getTeacherId() == 0) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", "ID преподавателя обязателен"));
|
||||||
|
}
|
||||||
|
if (request.getGroupId() == null || request.getGroupId() == 0) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", "ID группы обязателен"));
|
||||||
|
}
|
||||||
|
if (request.getLessonId() == null || request.getLessonId() == 0) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", "ID предмета обязателен"));
|
||||||
|
}
|
||||||
|
if (request.getDay() == null || request.getDay().isBlank()) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", "Выбор дня обязателен"));
|
||||||
|
}
|
||||||
|
if (request.getWeek() == null || request.getWeek().isBlank()) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", "Выбор недели обязателен"));
|
||||||
|
}
|
||||||
|
if (request.getTime() == null || request.getTime().isBlank()) {
|
||||||
|
return ResponseEntity.badRequest().body(Map.of("message", "Время обязательно"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Lesson lesson = new Lesson();
|
||||||
|
lesson.setTeacherId(request.getTeacherId());
|
||||||
|
lesson.setLessonId(request.getLessonId());
|
||||||
|
lesson.setGroupId(request.getGroupId());
|
||||||
|
lesson.setDay(request.getDay());
|
||||||
|
lesson.setWeek(request.getWeek());
|
||||||
|
lesson.setTime(request.getTime());
|
||||||
|
lessonRepository.save(lesson);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(new LessonResponse(lesson.getId(), lesson.getDay(), lesson.getWeek(), lesson.getTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<LessonResponse> getAllLessons() {
|
||||||
|
return lessonRepository.findAll().stream()
|
||||||
|
.map(l -> new LessonResponse(l.getTeacherId(), l.getLessonId(), l.getDay(), l.getWeek(), l.getTime()))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.magistr.app.dto;
|
||||||
|
|
||||||
|
public class CreateLessonRequest {
|
||||||
|
|
||||||
|
private Long teacherId;
|
||||||
|
private Long groupId;
|
||||||
|
private Long lessonId;
|
||||||
|
private String day;
|
||||||
|
private String week;
|
||||||
|
private String time;
|
||||||
|
|
||||||
|
public CreateLessonRequest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTeacherId() {
|
||||||
|
return teacherId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeacherId(Long teacherId) {
|
||||||
|
this.teacherId = teacherId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupId(Long groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLessonId() {
|
||||||
|
return lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonId(Long lessonId) {
|
||||||
|
this.lessonId= lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDay(String day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeek() {
|
||||||
|
return week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeek(String week) {
|
||||||
|
this.week = week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(String time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.magistr.app.dto;
|
||||||
|
|
||||||
|
public class LessonResponse {
|
||||||
|
|
||||||
|
private Long teacherId;
|
||||||
|
private Long groupId;
|
||||||
|
private Long lessonId;
|
||||||
|
private String day;
|
||||||
|
private String week;
|
||||||
|
private String time;
|
||||||
|
|
||||||
|
public LessonResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public LessonResponse(Long lessonId, String day, String week, String time) {
|
||||||
|
this.lessonId = lessonId;
|
||||||
|
this.day = day;
|
||||||
|
this.week = week;
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LessonResponse(Long teacherId, Long lessonId, String day, String week, String time) {
|
||||||
|
this.teacherId = teacherId;
|
||||||
|
this.lessonId = lessonId;
|
||||||
|
this.day = day;
|
||||||
|
this.week = week;
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTeacherId() {
|
||||||
|
return teacherId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeacherId(Long teacherId) {
|
||||||
|
this.teacherId = teacherId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupId(Long groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLessonId() {
|
||||||
|
return lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonId(Long lessonId) {
|
||||||
|
this.lessonId= lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDay(String day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeek() {
|
||||||
|
return week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeek(String week) {
|
||||||
|
this.week = week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(String time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
89
backend/src/main/java/com/magistr/app/model/Lesson.java
Normal file
89
backend/src/main/java/com/magistr/app/model/Lesson.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package com.magistr.app.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "lessons")
|
||||||
|
public class Lesson {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Long teacherId;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Long groupId;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Long lessonId;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 255)
|
||||||
|
private String day;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 255)
|
||||||
|
private String week;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 255)
|
||||||
|
private String time;
|
||||||
|
|
||||||
|
public Lesson() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTeacherId() {
|
||||||
|
return teacherId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeacherId(Long teacherId) {
|
||||||
|
this.teacherId = teacherId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupId(Long groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLessonId() {
|
||||||
|
return lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonId(Long lessonId) {
|
||||||
|
this.lessonId = lessonId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDay(String day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeek() {
|
||||||
|
return week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeek(String week) {
|
||||||
|
this.week = week;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(String time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.magistr.app.repository;
|
||||||
|
|
||||||
|
import com.magistr.app.model.Lesson;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface LessonRepository extends JpaRepository<Lesson, Long> {
|
||||||
|
|
||||||
|
Optional<Lesson> findByLessonId(Long lessonId);
|
||||||
|
}
|
||||||
@@ -25,3 +25,21 @@ CREATE TABLE IF NOT EXISTS student_groups (
|
|||||||
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)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS lessons (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
teacher_id BIGINT NOT NULL,
|
||||||
|
group_id BIGINT NOT NULL,
|
||||||
|
lesson_id BIGINT NOT NULL,
|
||||||
|
day VARCHAR(255) NOT NULL,
|
||||||
|
week VARCHAR(255) NOT NULL,
|
||||||
|
time VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE lessons
|
||||||
|
ADD CONSTRAINT fk_lessons_teacher
|
||||||
|
FOREIGN KEY (teacher_id) REFERENCES users(id);
|
||||||
|
|
||||||
|
ALTER TABLE lessons
|
||||||
|
ADD CONSTRAINT fk_lessons_group
|
||||||
|
FOREIGN KEY (group_id) REFERENCES student_groups(id);
|
||||||
Reference in New Issue
Block a user