diff --git a/schedule/pom.xml b/schedule/pom.xml
index 7dce915..1f6a763 100644
--- a/schedule/pom.xml
+++ b/schedule/pom.xml
@@ -98,6 +98,12 @@
springdoc-openapi-starter-webmvc-ui
2.7.0
+
+
+ org.apache.pdfbox
+ pdfbox
+ 2.0.29
+
diff --git a/schedule/src/main/java/edu/unive/schedule/controller/ScheduleController.java b/schedule/src/main/java/edu/unive/schedule/controller/ScheduleController.java
index ec1ebe6..fb15fb2 100644
--- a/schedule/src/main/java/edu/unive/schedule/controller/ScheduleController.java
+++ b/schedule/src/main/java/edu/unive/schedule/controller/ScheduleController.java
@@ -1,16 +1,23 @@
package edu.unive.schedule.controller;
import edu.unive.schedule.domain.Schedule;
+import edu.unive.schedule.service.PdfGenerationService;
import edu.unive.schedule.service.ScheduleService;
import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import java.io.IOException;
+
@RestController
@RequiredArgsConstructor
public class ScheduleController implements ScheduleApi {
private final ScheduleService scheduleService;
+ private final PdfGenerationService pdfGenerationService;
@Override
public ResponseEntity createSchedule(Schedule scheduleDTO) {
@@ -30,4 +37,15 @@ public class ScheduleController implements ScheduleApi {
scheduleService.deleteSchedule(id);
return ResponseEntity.ok().build();
}
+
+ @GetMapping("/download/{groupId}")
+ public ResponseEntity downloadSchedulePdf(@PathVariable Long groupId) throws IOException {
+ byte[] pdfBytes = pdfGenerationService.generatePdf(groupId);
+
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_PDF);
+ headers.setContentDispositionFormData("attachment", "schedule.pdf");
+
+ return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK);
+ }
}
diff --git a/schedule/src/main/java/edu/unive/schedule/domain/Schedule.java b/schedule/src/main/java/edu/unive/schedule/domain/Schedule.java
index 13ff3c9..cc41245 100644
--- a/schedule/src/main/java/edu/unive/schedule/domain/Schedule.java
+++ b/schedule/src/main/java/edu/unive/schedule/domain/Schedule.java
@@ -1,13 +1,19 @@
package edu.unive.schedule.domain;
+import edu.unive.schedule.domain.entity.DayOfWeek;
import lombok.Data;
+import java.util.List;
+
@Data
public class Schedule {
private Long id;
private int pairNumber;
+ private Integer weekNumber;
+ private DayOfWeek dayOfWeek;
private Long classroomId;
private Long courseId; // ID курса из внешнего микросервиса
private Long teacherId; // ID преподавателя из внешнего микросервиса
+ private List groupIds;
}
diff --git a/schedule/src/main/java/edu/unive/schedule/domain/entity/DayOfWeek.java b/schedule/src/main/java/edu/unive/schedule/domain/entity/DayOfWeek.java
new file mode 100644
index 0000000..92753be
--- /dev/null
+++ b/schedule/src/main/java/edu/unive/schedule/domain/entity/DayOfWeek.java
@@ -0,0 +1,11 @@
+package edu.unive.schedule.domain.entity;
+
+public enum DayOfWeek {
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY,
+ SUNDAY
+}
diff --git a/schedule/src/main/java/edu/unive/schedule/domain/entity/ScheduleEntity.java b/schedule/src/main/java/edu/unive/schedule/domain/entity/ScheduleEntity.java
index cb93bff..61ba8c0 100644
--- a/schedule/src/main/java/edu/unive/schedule/domain/entity/ScheduleEntity.java
+++ b/schedule/src/main/java/edu/unive/schedule/domain/entity/ScheduleEntity.java
@@ -3,7 +3,7 @@ package edu.unive.schedule.domain.entity;
import jakarta.persistence.*;
import lombok.Data;
-import java.time.LocalDateTime;
+import java.util.List;
@Data
@Entity
@@ -13,13 +13,24 @@ public class ScheduleEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, unique = true)
private Long id;
- @Column(name = "pair_number", nullable = false)
- private int pairNumber;
+ @Column(name = "pair_number")
+ private Integer pairNumber; // Номер пары (1 - 8)
+ @Column(name = "week_number")
+ private Integer weekNumber; // Номер недели (1 или 2)
+ @Column(name = "day_of_week")
+ private DayOfWeek dayOfWeek; // День недели
+
+ @ElementCollection
+ @CollectionTable(name = "schedule_group_ids", joinColumns = @JoinColumn(name = "schedule_id"))
+ @Column(name = "group_id")
+ private List groupIds;
@ManyToOne
@JoinColumn(name = "classroom_id")
private ClassroomEntity classroom;
+ @Column(name = "course_id")
private Long courseId; // ID курса из внешнего микросервиса
+ @Column(name = "teacher_id")
private Long teacherId; // ID преподавателя из внешнего микросервиса
}
diff --git a/schedule/src/main/java/edu/unive/schedule/repository/ScheduleRepository.java b/schedule/src/main/java/edu/unive/schedule/repository/ScheduleRepository.java
index a358429..4424ed5 100644
--- a/schedule/src/main/java/edu/unive/schedule/repository/ScheduleRepository.java
+++ b/schedule/src/main/java/edu/unive/schedule/repository/ScheduleRepository.java
@@ -3,7 +3,10 @@ package edu.unive.schedule.repository;
import edu.unive.schedule.domain.entity.ScheduleEntity;
import org.springframework.data.jpa.repository.JpaRepository;
+import java.util.List;
+
public interface ScheduleRepository extends JpaRepository {
+ List findByGroupIdsContaining(Long groupId);
}
diff --git a/schedule/src/main/java/edu/unive/schedule/service/PdfGenerationService.java b/schedule/src/main/java/edu/unive/schedule/service/PdfGenerationService.java
new file mode 100644
index 0000000..57ec345
--- /dev/null
+++ b/schedule/src/main/java/edu/unive/schedule/service/PdfGenerationService.java
@@ -0,0 +1,74 @@
+package edu.unive.schedule.service;
+
+import edu.unive.schedule.domain.entity.ScheduleEntity;
+import edu.unive.schedule.repository.ScheduleRepository;
+import lombok.RequiredArgsConstructor;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import org.springframework.stereotype.Service;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+@Service
+@RequiredArgsConstructor
+public class PdfGenerationService {
+
+ private final ScheduleRepository scheduleRepository;
+
+ //private final GroupServiceClient groupServiceClient;
+
+ //private final TeacherServiceClient teacherServiceClient;
+
+ public byte[] generatePdf(Long groupId) throws IOException {
+ List schedules = scheduleRepository.findByGroupIdsContaining(groupId);
+
+ try (PDDocument document = new PDDocument()) {
+ PDPage page = new PDPage();
+ document.addPage(page);
+
+ try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) {
+ contentStream.setFont(PDType1Font.HELVETICA_BOLD, 12);
+ contentStream.beginText();
+ contentStream.newLineAtOffset(100, 700);
+ contentStream.showText("Group Schedule");
+ contentStream.endText();
+
+ int yOffset = 650;
+ for (ScheduleEntity schedule : schedules) {
+ // Получаем название группы из внешнего микросервиса
+ //String groupNames = schedule.getGroupIds().stream()
+ // .map(groupServiceClient::getGroupById)
+ // .map(Group::getName)
+ // .collect(Collectors.joining(", "));
+
+ // Получаем данные о преподавателе из внешнего микросервиса
+ //Teacher teacher = teacherServiceClient.getTeacherById(schedule.getTeacherId());
+
+ String text = String.format("Week %d, %s, Pair %d: %s - %s (Classroom: %s, Teacher: %s, Groups: %s)",
+ schedule.getWeekNumber(),
+ schedule.getDayOfWeek(),
+ schedule.getPairNumber(),
+ schedule.getCourseId(),
+ schedule.getClassroom().getName());
+ //teacher.getName(),
+ //groupNames);
+
+ contentStream.beginText();
+ contentStream.newLineAtOffset(100, yOffset);
+ contentStream.showText(text);
+ contentStream.endText();
+
+ yOffset -= 20;
+ }
+ }
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ document.save(byteArrayOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
+ }
+}
diff --git a/schedule/src/main/java/edu/unive/schedule/service/ScheduleServiceImpl.java b/schedule/src/main/java/edu/unive/schedule/service/ScheduleServiceImpl.java
index 0723a88..329ebcb 100644
--- a/schedule/src/main/java/edu/unive/schedule/service/ScheduleServiceImpl.java
+++ b/schedule/src/main/java/edu/unive/schedule/service/ScheduleServiceImpl.java
@@ -8,6 +8,8 @@ import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
+import java.util.List;
+
@Service
@RequiredArgsConstructor
public class ScheduleServiceImpl implements ScheduleService {
@@ -35,4 +37,6 @@ public class ScheduleServiceImpl implements ScheduleService {
public void deleteSchedule(Long id) {
scheduleRepository.deleteById(id);
}
+
+ //TODO генерация расписания
}
diff --git a/schedule/src/main/resources/db/migration/V1__Init.sql b/schedule/src/main/resources/db/migration/V1__Init.sql
index 4d37083..6112f0a 100644
--- a/schedule/src/main/resources/db/migration/V1__Init.sql
+++ b/schedule/src/main/resources/db/migration/V1__Init.sql
@@ -9,8 +9,17 @@ CREATE TABLE schedule (
id BIGSERIAL
CONSTRAINT schedule_pk PRIMARY KEY,
pair_number INT,
+ week_number INT,
+ day_of_week VARCHAR(20),
classroom_id BIGINT,
course_id BIGINT,
teacher_id BIGINT,
FOREIGN KEY (classroom_id) REFERENCES classroom(id)
+);
+
+CREATE TABLE schedule_group_ids (
+ schedule_id BIGINT NOT NULL,
+ group_id BIGINT NOT NULL,
+ PRIMARY KEY (schedule_id, group_id),
+ FOREIGN KEY (schedule_id) REFERENCES schedule(id)
);
\ No newline at end of file
diff --git a/university/pom.xml b/university/pom.xml
index 3dcef8f..1be2925 100644
--- a/university/pom.xml
+++ b/university/pom.xml
@@ -31,6 +31,10 @@
2024.0.0
+
+ org.springframework.boot
+ spring-boot-starter-web
+
org.flywaydb
flyway-core
@@ -68,6 +72,32 @@
spring-kafka-test
test
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.mapstruct
+ mapstruct
+ 1.5.5.Final
+
+
+ org.mapstruct
+ mapstruct-processor
+ 1.5.5.Final
+ provided
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+ org.springdoc
+ springdoc-openapi-starter-webmvc-ui
+ 2.7.0
+
@@ -92,6 +122,11 @@
org.projectlombok
lombok
+
+ org.mapstruct
+ mapstruct-processor
+ 1.5.5.Final
+
diff --git a/university/src/main/java/edu/unive/university/UniversityApplication.java b/university/src/main/java/edu/unive/university/UniversityApplication.java
index d65c822..bcf0691 100644
--- a/university/src/main/java/edu/unive/university/UniversityApplication.java
+++ b/university/src/main/java/edu/unive/university/UniversityApplication.java
@@ -2,8 +2,10 @@ package edu.unive.university;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.PropertySource;
@SpringBootApplication
+@PropertySource("classpath:application.yml")
public class UniversityApplication {
public static void main(String[] args) {
@@ -11,3 +13,4 @@ public class UniversityApplication {
}
}
+
diff --git a/university/src/main/java/edu/unive/university/controller/DepartmentApi.java b/university/src/main/java/edu/unive/university/controller/DepartmentApi.java
new file mode 100644
index 0000000..5f8532c
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/DepartmentApi.java
@@ -0,0 +1,25 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Department;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RequestMapping("api/departments")
+public interface DepartmentApi {
+ @PostMapping
+ ResponseEntity createDepartment(@RequestBody Department department);
+
+ @GetMapping("/{id}")
+ ResponseEntity getDepartmentById(@PathVariable Long id);
+
+ @GetMapping
+ List getAllDepartments();
+
+ @PutMapping("/{id}")
+ ResponseEntity updateDepartment(@PathVariable Long id, @RequestBody Department department);
+
+ @DeleteMapping("/{id}")
+ ResponseEntity deleteDepartment(@PathVariable Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/controller/DepartmentController.java b/university/src/main/java/edu/unive/university/controller/DepartmentController.java
new file mode 100644
index 0000000..628cb04
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/DepartmentController.java
@@ -0,0 +1,44 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Department;
+import edu.unive.university.service.DepartmentService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RequiredArgsConstructor
+@RestController
+public class DepartmentController implements DepartmentApi {
+ private final DepartmentService departmentService;
+
+ @Override
+ public ResponseEntity createDepartment(Department department) {
+ departmentService.createDepartment(department);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity getDepartmentById(Long id) {
+ var dto = departmentService.getDepartmentById(id);
+ return ResponseEntity.ok(dto);
+ }
+
+ @Override
+ public List getAllDepartments() {
+ return departmentService.getAllDepartments();
+ }
+
+ @Override
+ public ResponseEntity updateDepartment(Long id, Department department) {
+ departmentService.updateDepartment(id, department);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity deleteDepartment(Long id) {
+ departmentService.deleteDepartment(id);
+ return ResponseEntity.ok().build();
+ }
+}
\ No newline at end of file
diff --git a/university/src/main/java/edu/unive/university/controller/DirectionApi.java b/university/src/main/java/edu/unive/university/controller/DirectionApi.java
new file mode 100644
index 0000000..2da87f2
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/DirectionApi.java
@@ -0,0 +1,25 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Direction;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RequestMapping("api/directions")
+public interface DirectionApi {
+ @PostMapping
+ ResponseEntity createDirection(@RequestBody Direction direction);
+
+ @GetMapping("/{id}")
+ ResponseEntity getDirectionById(@PathVariable Long id);
+
+ @GetMapping
+ List getAllDirections();
+
+ @PutMapping("/{id}")
+ ResponseEntity updateDirection(@PathVariable Long id, @RequestBody Direction direction);
+
+ @DeleteMapping("/{id}")
+ ResponseEntity deleteDirection(@PathVariable Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/controller/DirectionController.java b/university/src/main/java/edu/unive/university/controller/DirectionController.java
new file mode 100644
index 0000000..6b3ea26
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/DirectionController.java
@@ -0,0 +1,44 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Direction;
+import edu.unive.university.service.DirectionService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+public class DirectionController implements DirectionApi {
+ private final DirectionService directionService;
+
+ @Override
+ public ResponseEntity createDirection(Direction direction) {
+ directionService.createDirection(direction);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity getDirectionById(Long id) {
+ var dto = directionService.getDirectionById(id);
+ return ResponseEntity.ok(dto);
+ }
+
+ @Override
+ public List getAllDirections() {
+ return directionService.getAllDirections();
+ }
+
+ @Override
+ public ResponseEntity updateDirection(Long id, Direction direction) {
+ directionService.updateDirection(id, direction);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity deleteDirection(Long id) {
+ directionService.deleteDirection(id);
+ return ResponseEntity.ok().build();
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/controller/FacultyApi.java b/university/src/main/java/edu/unive/university/controller/FacultyApi.java
new file mode 100644
index 0000000..dcb4a56
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/FacultyApi.java
@@ -0,0 +1,25 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Faculty;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RequestMapping("api/faculties")
+public interface FacultyApi {
+ @PostMapping
+ ResponseEntity createFaculty(@RequestBody Faculty faculty);
+
+ @GetMapping("/{id}")
+ ResponseEntity getFacultyById(@PathVariable Long id);
+
+ @GetMapping
+ List getAllFaculties();
+
+ @PutMapping("/{id}")
+ ResponseEntity updateFaculty(@PathVariable Long id, @RequestBody Faculty faculty);
+
+ @DeleteMapping("/{id}")
+ ResponseEntity deleteFaculty(@PathVariable Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/controller/FacultyController.java b/university/src/main/java/edu/unive/university/controller/FacultyController.java
new file mode 100644
index 0000000..857b9b3
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/FacultyController.java
@@ -0,0 +1,44 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Faculty;
+import edu.unive.university.service.FacultyService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+public class FacultyController implements FacultyApi {
+ private final FacultyService facultyService;
+
+ @Override
+ public ResponseEntity createFaculty(Faculty faculty) {
+ facultyService.createFaculty(faculty);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity getFacultyById(Long id) {
+ var dto = facultyService.getFacultyById(id);
+ return ResponseEntity.ok().body(dto);
+ }
+
+ @Override
+ public List getAllFaculties() {
+ return facultyService.getAllFaculties();
+ }
+
+ @Override
+ public ResponseEntity updateFaculty(Long id, Faculty faculty) {
+ facultyService.updateFaculty(id, faculty);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity deleteFaculty(Long id) {
+ facultyService.deleteFaculty(id);
+ return ResponseEntity.ok().build();
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/controller/GroupApi.java b/university/src/main/java/edu/unive/university/controller/GroupApi.java
new file mode 100644
index 0000000..59bac4f
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/GroupApi.java
@@ -0,0 +1,25 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Group;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RequestMapping("api/groups")
+public interface GroupApi {
+ @PostMapping
+ ResponseEntity createGroup(@RequestBody Group group);
+
+ @GetMapping("/{id}")
+ ResponseEntity getGroupById(@PathVariable Long id);
+
+ @GetMapping
+ List getAllGroups();
+
+ @PutMapping("/{id}")
+ ResponseEntity updateGroup(@PathVariable Long id, @RequestBody Group group);
+
+ @DeleteMapping("/{id}")
+ ResponseEntity deleteGroup(@PathVariable Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/controller/GroupController.java b/university/src/main/java/edu/unive/university/controller/GroupController.java
new file mode 100644
index 0000000..42e1b94
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/GroupController.java
@@ -0,0 +1,45 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Group;
+import edu.unive.university.service.GroupService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+public class GroupController implements GroupApi {
+
+ private final GroupService groupService;
+
+ @Override
+ public ResponseEntity createGroup(Group group) {
+ groupService.createGroup(group);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity getGroupById( Long id) {
+ var dto = groupService.getGroupById(id);
+ return ResponseEntity.ok().body(dto);
+ }
+
+ @Override
+ public List getAllGroups() {
+ return groupService.getAllGroups();
+ }
+
+ @Override
+ public ResponseEntity updateGroup( Long id, Group group) {
+ groupService.updateGroup(id, group);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity deleteGroup( Long id) {
+ groupService.deleteGroup(id);
+ return ResponseEntity.ok().build();
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/controller/TeacherApi.java b/university/src/main/java/edu/unive/university/controller/TeacherApi.java
new file mode 100644
index 0000000..ec0bbd7
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/TeacherApi.java
@@ -0,0 +1,25 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Teacher;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RequestMapping("api/teachers")
+public interface TeacherApi {
+ @PostMapping
+ ResponseEntity createTeacher(@RequestBody Teacher teacher);
+
+ @GetMapping("/{id}")
+ ResponseEntity getTeacherById(@PathVariable Long id);
+
+ @GetMapping
+ List getAllTeachers();
+
+ @PutMapping("/{id}")
+ ResponseEntity updateTeacher(@PathVariable Long id, @RequestBody Teacher teacher);
+
+ @DeleteMapping("/{id}")
+ ResponseEntity deleteTeacher(@PathVariable Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/controller/TeacherController.java b/university/src/main/java/edu/unive/university/controller/TeacherController.java
new file mode 100644
index 0000000..ed69eb3
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/controller/TeacherController.java
@@ -0,0 +1,44 @@
+package edu.unive.university.controller;
+
+import edu.unive.university.domain.Teacher;
+import edu.unive.university.service.TeacherService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequiredArgsConstructor
+public class TeacherController implements TeacherApi {
+ private final TeacherService teacherService;
+
+ @Override
+ public ResponseEntity createTeacher(@RequestBody Teacher teacher) {
+ teacherService.createTeacher(teacher);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity getTeacherById(@PathVariable Long id) {
+ var dto = teacherService.getTeacherById(id);
+ return ResponseEntity.ok(dto);
+ }
+
+ @Override
+ public List getAllTeachers() {
+ return teacherService.getAllTeachers();
+ }
+
+ @Override
+ public ResponseEntity updateTeacher(@PathVariable Long id, @RequestBody Teacher teacher) {
+ teacherService.updateTeacher(id, teacher);
+ return ResponseEntity.ok().build();
+ }
+
+ @Override
+ public ResponseEntity deleteTeacher(@PathVariable Long id) {
+ teacherService.deleteTeacher(id);
+ return ResponseEntity.ok().build();
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/domain/Department.java b/university/src/main/java/edu/unive/university/domain/Department.java
new file mode 100644
index 0000000..4694a1b
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/Department.java
@@ -0,0 +1,10 @@
+package edu.unive.university.domain;
+
+import lombok.Data;
+
+@Data
+public class Department {
+ private Long id;
+ private String name;
+ private Long facultyId;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/Direction.java b/university/src/main/java/edu/unive/university/domain/Direction.java
new file mode 100644
index 0000000..94b022a
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/Direction.java
@@ -0,0 +1,10 @@
+package edu.unive.university.domain;
+
+import lombok.Data;
+
+@Data
+public class Direction {
+ private Long id;
+ private String name;
+ private Long departmentId;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/Faculty.java b/university/src/main/java/edu/unive/university/domain/Faculty.java
new file mode 100644
index 0000000..6649702
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/Faculty.java
@@ -0,0 +1,10 @@
+package edu.unive.university.domain;
+
+import lombok.Data;
+
+@Data
+public class Faculty {
+ private Long id;
+ private String name;
+}
+
diff --git a/university/src/main/java/edu/unive/university/domain/Group.java b/university/src/main/java/edu/unive/university/domain/Group.java
new file mode 100644
index 0000000..a02d815
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/Group.java
@@ -0,0 +1,10 @@
+package edu.unive.university.domain;
+
+import lombok.Data;
+
+@Data
+public class Group {
+ private Long id;
+ private String name;
+ private Long directionId;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/Teacher.java b/university/src/main/java/edu/unive/university/domain/Teacher.java
new file mode 100644
index 0000000..4ad6664
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/Teacher.java
@@ -0,0 +1,11 @@
+package edu.unive.university.domain;
+
+import lombok.Data;
+
+@Data
+public class Teacher {
+ private Long id;
+ private String firstName;
+ private String lastName;
+ private Long departmentId;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/entity/DepartmentEntity.java b/university/src/main/java/edu/unive/university/domain/entity/DepartmentEntity.java
new file mode 100644
index 0000000..543d63e
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/entity/DepartmentEntity.java
@@ -0,0 +1,23 @@
+package edu.unive.university.domain.entity;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+import java.util.Set;
+
+@Data
+@Entity
+@Table(name = "department")
+public class DepartmentEntity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String name;
+
+ @ManyToOne
+ @JoinColumn(name = "faculty_id")
+ private FacultyEntity faculty;
+
+ @OneToMany(mappedBy = "department", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ private Set teachers;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/entity/DirectionEntity.java b/university/src/main/java/edu/unive/university/domain/entity/DirectionEntity.java
new file mode 100644
index 0000000..6cb0212
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/entity/DirectionEntity.java
@@ -0,0 +1,24 @@
+package edu.unive.university.domain.entity;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+import java.util.Set;
+
+@Entity
+@Data
+@Table(name = "direction")
+public class DirectionEntity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String name;
+
+ @ManyToOne
+ @JoinColumn(name = "department_id")
+ private DepartmentEntity department;
+
+ @OneToMany(mappedBy = "direction", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ private Set groups;
+
+}
diff --git a/university/src/main/java/edu/unive/university/domain/entity/FacultyEntity.java b/university/src/main/java/edu/unive/university/domain/entity/FacultyEntity.java
new file mode 100644
index 0000000..ac1d6b7
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/entity/FacultyEntity.java
@@ -0,0 +1,19 @@
+package edu.unive.university.domain.entity;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+import java.util.Set;
+
+@Data
+@Entity
+@Table(name = "faculty")
+public class FacultyEntity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String name;
+
+ @OneToMany(mappedBy = "faculty", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ private Set departments;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/entity/GroupEntity.java b/university/src/main/java/edu/unive/university/domain/entity/GroupEntity.java
new file mode 100644
index 0000000..abd89ae
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/entity/GroupEntity.java
@@ -0,0 +1,18 @@
+package edu.unive.university.domain.entity;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+@Entity
+@Data
+@Table(name = "st_group")
+public class GroupEntity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String name;
+
+ @ManyToOne
+ @JoinColumn(name = "direction_id")
+ private DirectionEntity direction;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/entity/TeacherEntity.java b/university/src/main/java/edu/unive/university/domain/entity/TeacherEntity.java
new file mode 100644
index 0000000..bdad4fd
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/entity/TeacherEntity.java
@@ -0,0 +1,19 @@
+package edu.unive.university.domain.entity;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+@Entity
+@Data
+@Table(name = "teacher")
+public class TeacherEntity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+ private String firstName;
+ private String lastName;
+
+ @ManyToOne
+ @JoinColumn(name = "department_id")
+ private DepartmentEntity department;
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/DepartmentEntityMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/DepartmentEntityMapper.java
new file mode 100644
index 0000000..e4d9962
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/DepartmentEntityMapper.java
@@ -0,0 +1,13 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.*;
+import edu.unive.university.domain.entity.*;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface DepartmentEntityMapper {
+ @Mapping(source = "facultyId", target = "faculty.id")
+ DepartmentEntity toEntity(Department dto);
+}
+
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/DepartmentMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/DepartmentMapper.java
new file mode 100644
index 0000000..b2de2f6
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/DepartmentMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Department;
+import edu.unive.university.domain.entity.DepartmentEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface DepartmentMapper {
+ @Mapping(source = "faculty.id", target = "facultyId")
+ Department toDTO(DepartmentEntity entity);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/DirectionEntityMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/DirectionEntityMapper.java
new file mode 100644
index 0000000..5e3eacd
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/DirectionEntityMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Direction;
+import edu.unive.university.domain.entity.DirectionEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface DirectionEntityMapper {
+ @Mapping(source = "departmentId", target = "department.id")
+ DirectionEntity toEntity(Direction dto);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/DirectionMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/DirectionMapper.java
new file mode 100644
index 0000000..766a9f3
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/DirectionMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Direction;
+import edu.unive.university.domain.entity.DirectionEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface DirectionMapper {
+ @Mapping(source = "department.id", target = "departmentId")
+ Direction toDTO(DirectionEntity entity);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/FacultyEntityMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/FacultyEntityMapper.java
new file mode 100644
index 0000000..9a150dc
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/FacultyEntityMapper.java
@@ -0,0 +1,10 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Faculty;
+import edu.unive.university.domain.entity.FacultyEntity;
+import org.mapstruct.Mapper;
+
+@Mapper(componentModel = "spring")
+public interface FacultyEntityMapper {
+ FacultyEntity toEntity(Faculty dto);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/FacultyMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/FacultyMapper.java
new file mode 100644
index 0000000..f583022
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/FacultyMapper.java
@@ -0,0 +1,10 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Faculty;
+import edu.unive.university.domain.entity.FacultyEntity;
+import org.mapstruct.Mapper;
+
+@Mapper(componentModel = "spring")
+public interface FacultyMapper {
+ Faculty toDTO(FacultyEntity entity);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/GroupEntityMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/GroupEntityMapper.java
new file mode 100644
index 0000000..7aeb006
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/GroupEntityMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Group;
+import edu.unive.university.domain.entity.GroupEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface GroupEntityMapper {
+ @Mapping(source = "directionId", target = "direction.id")
+ GroupEntity toEntity(Group dto);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/GroupMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/GroupMapper.java
new file mode 100644
index 0000000..cabe3e3
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/GroupMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Group;
+import edu.unive.university.domain.entity.GroupEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface GroupMapper {
+ @Mapping(source = "direction.id", target = "directionId")
+ Group toDTO(GroupEntity entity);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/TeacherEntityMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/TeacherEntityMapper.java
new file mode 100644
index 0000000..e8846f6
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/TeacherEntityMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Teacher;
+import edu.unive.university.domain.entity.TeacherEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface TeacherEntityMapper {
+ @Mapping(source = "departmentId", target = "department.id")
+ TeacherEntity toEntity(Teacher dto);
+}
diff --git a/university/src/main/java/edu/unive/university/domain/mapper/TeacherMapper.java b/university/src/main/java/edu/unive/university/domain/mapper/TeacherMapper.java
new file mode 100644
index 0000000..e0008c4
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/domain/mapper/TeacherMapper.java
@@ -0,0 +1,12 @@
+package edu.unive.university.domain.mapper;
+
+import edu.unive.university.domain.Teacher;
+import edu.unive.university.domain.entity.TeacherEntity;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper(componentModel = "spring")
+public interface TeacherMapper {
+ @Mapping(source = "department.id", target = "departmentId")
+ Teacher toDTO(TeacherEntity entity);
+}
diff --git a/university/src/main/java/edu/unive/university/repository/DepartmentRepository.java b/university/src/main/java/edu/unive/university/repository/DepartmentRepository.java
new file mode 100644
index 0000000..91fe5a8
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/repository/DepartmentRepository.java
@@ -0,0 +1,7 @@
+package edu.unive.university.repository;
+
+import edu.unive.university.domain.entity.DepartmentEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface DepartmentRepository extends JpaRepository {
+}
diff --git a/university/src/main/java/edu/unive/university/repository/DirectionRepository.java b/university/src/main/java/edu/unive/university/repository/DirectionRepository.java
new file mode 100644
index 0000000..a767354
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/repository/DirectionRepository.java
@@ -0,0 +1,7 @@
+package edu.unive.university.repository;
+
+import edu.unive.university.domain.entity.DirectionEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface DirectionRepository extends JpaRepository {
+}
diff --git a/university/src/main/java/edu/unive/university/repository/FacultyRepository.java b/university/src/main/java/edu/unive/university/repository/FacultyRepository.java
new file mode 100644
index 0000000..ce6357f
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/repository/FacultyRepository.java
@@ -0,0 +1,8 @@
+package edu.unive.university.repository;
+
+import edu.unive.university.domain.entity.*;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface FacultyRepository extends JpaRepository {
+}
+
diff --git a/university/src/main/java/edu/unive/university/repository/GroupRepository.java b/university/src/main/java/edu/unive/university/repository/GroupRepository.java
new file mode 100644
index 0000000..d19fca5
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/repository/GroupRepository.java
@@ -0,0 +1,7 @@
+package edu.unive.university.repository;
+
+import edu.unive.university.domain.entity.GroupEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface GroupRepository extends JpaRepository {
+}
diff --git a/university/src/main/java/edu/unive/university/repository/TeacherRepository.java b/university/src/main/java/edu/unive/university/repository/TeacherRepository.java
new file mode 100644
index 0000000..fd8f148
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/repository/TeacherRepository.java
@@ -0,0 +1,7 @@
+package edu.unive.university.repository;
+
+import edu.unive.university.domain.entity.TeacherEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface TeacherRepository extends JpaRepository {
+}
diff --git a/university/src/main/java/edu/unive/university/service/DepartmentService.java b/university/src/main/java/edu/unive/university/service/DepartmentService.java
new file mode 100644
index 0000000..d9876e3
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/DepartmentService.java
@@ -0,0 +1,17 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Department;
+
+import java.util.List;
+
+public interface DepartmentService {
+ void createDepartment(Department department);
+
+ Department getDepartmentById(Long id);
+
+ List getAllDepartments();
+
+ void updateDepartment(Long id, Department department);
+
+ void deleteDepartment(Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/service/DepartmentServiceImpl.java b/university/src/main/java/edu/unive/university/service/DepartmentServiceImpl.java
new file mode 100644
index 0000000..e307a38
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/DepartmentServiceImpl.java
@@ -0,0 +1,56 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Department;
+import edu.unive.university.domain.entity.DepartmentEntity;
+import edu.unive.university.domain.mapper.DepartmentEntityMapper;
+import edu.unive.university.domain.mapper.DepartmentMapper;
+import edu.unive.university.repository.DepartmentRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor
+public class DepartmentServiceImpl implements DepartmentService {
+ private final DepartmentRepository departmentRepository;
+
+ private final DepartmentMapper departmentMapper;
+ private final DepartmentEntityMapper departmentEntityMapper;
+
+ @Override
+ public void createDepartment(Department department) {
+ DepartmentEntity entity = departmentEntityMapper.toEntity(department);
+ entity.setId(null);
+ departmentRepository.save(entity);
+ }
+
+ @Override
+ public Department getDepartmentById(Long id) {
+ DepartmentEntity entity = departmentRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Department not found"));
+ return departmentMapper.toDTO(entity);
+ }
+
+ @Override
+ public List getAllDepartments() {
+ return departmentRepository.findAll().stream()
+ .map(departmentMapper::toDTO)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void updateDepartment(Long id, Department department) {
+ DepartmentEntity existingEntity = departmentRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Department not found"));
+ DepartmentEntity updatedEntity = departmentEntityMapper.toEntity(department);
+ updatedEntity.setId(existingEntity.getId()); // Сохраняем ID
+ DepartmentEntity savedEntity = departmentRepository.save(updatedEntity);
+ }
+
+ @Override
+ public void deleteDepartment(Long id) {
+ departmentRepository.deleteById(id);
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/service/DirectionService.java b/university/src/main/java/edu/unive/university/service/DirectionService.java
new file mode 100644
index 0000000..fa7485a
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/DirectionService.java
@@ -0,0 +1,17 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Direction;
+
+import java.util.List;
+
+public interface DirectionService {
+ void createDirection(Direction direction);
+
+ Direction getDirectionById(Long id);
+
+ List getAllDirections();
+
+ Direction updateDirection(Long id, Direction direction);
+
+ void deleteDirection(Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/service/DirectionServiceImpl.java b/university/src/main/java/edu/unive/university/service/DirectionServiceImpl.java
new file mode 100644
index 0000000..7308aca
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/DirectionServiceImpl.java
@@ -0,0 +1,57 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Direction;
+import edu.unive.university.domain.entity.DirectionEntity;
+import edu.unive.university.domain.mapper.DirectionEntityMapper;
+import edu.unive.university.domain.mapper.DirectionMapper;
+import edu.unive.university.repository.DirectionRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor
+public class DirectionServiceImpl implements DirectionService {
+ private final DirectionRepository directionRepository;
+
+ private final DirectionMapper directionMapper;
+ private final DirectionEntityMapper directionEntityMapper;
+
+ @Override
+ public void createDirection(Direction direction) {
+ DirectionEntity entity = directionEntityMapper.toEntity(direction);
+ entity.setId(null);
+ directionRepository.save(entity);
+ }
+
+ @Override
+ public Direction getDirectionById(Long id) {
+ DirectionEntity entity = directionRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Direction not found"));
+ return directionMapper.toDTO(entity);
+ }
+
+ @Override
+ public List getAllDirections() {
+ return directionRepository.findAll().stream()
+ .map(directionMapper::toDTO)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Direction updateDirection(Long id, Direction direction) {
+ DirectionEntity existingEntity = directionRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Direction not found"));
+ DirectionEntity updatedEntity = directionEntityMapper.toEntity(direction);
+ updatedEntity.setId(existingEntity.getId()); // Сохраняем ID
+ DirectionEntity savedEntity = directionRepository.save(updatedEntity);
+ return directionMapper.toDTO(savedEntity);
+ }
+
+ @Override
+ public void deleteDirection(Long id) {
+ directionRepository.deleteById(id);
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/service/FacultyService.java b/university/src/main/java/edu/unive/university/service/FacultyService.java
new file mode 100644
index 0000000..14d4598
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/FacultyService.java
@@ -0,0 +1,17 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Faculty;
+
+import java.util.List;
+
+public interface FacultyService {
+ void createFaculty(Faculty faculty);
+
+ Faculty getFacultyById(Long id);
+
+ List getAllFaculties();
+
+ void updateFaculty(Long id, Faculty faculty);
+
+ void deleteFaculty(Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/service/FacultyServiceImpl.java b/university/src/main/java/edu/unive/university/service/FacultyServiceImpl.java
new file mode 100644
index 0000000..e6b386c
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/FacultyServiceImpl.java
@@ -0,0 +1,57 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Faculty;
+import edu.unive.university.domain.entity.FacultyEntity;
+import edu.unive.university.domain.mapper.FacultyEntityMapper;
+import edu.unive.university.domain.mapper.FacultyMapper;
+import edu.unive.university.repository.FacultyRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor
+public class FacultyServiceImpl implements FacultyService {
+
+ private final FacultyRepository facultyRepository;
+
+ private final FacultyEntityMapper facultyEntityMapper;
+ private final FacultyMapper facultyMapper;
+
+ @Override
+ public void createFaculty(Faculty faculty) {
+ FacultyEntity entity = facultyEntityMapper.toEntity(faculty);
+ entity.setId(null);
+ facultyRepository.save(entity);
+ }
+
+ @Override
+ public Faculty getFacultyById(Long id) {
+ FacultyEntity entity = facultyRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Faculty not found"));
+ return facultyMapper.toDTO(entity);
+ }
+
+ @Override
+ public List getAllFaculties() {
+ return facultyRepository.findAll().stream()
+ .map(facultyMapper::toDTO)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void updateFaculty(Long id, Faculty faculty) {
+ FacultyEntity existingEntity = facultyRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Faculty not found"));
+ FacultyEntity updatedEntity = facultyEntityMapper.toEntity(faculty);
+ updatedEntity.setId(existingEntity.getId()); // Сохраняем ID
+ FacultyEntity savedEntity = facultyRepository.save(updatedEntity);
+ }
+
+ @Override
+ public void deleteFaculty(Long id) {
+ facultyRepository.deleteById(id);
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/service/GroupService.java b/university/src/main/java/edu/unive/university/service/GroupService.java
new file mode 100644
index 0000000..4ebddfa
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/GroupService.java
@@ -0,0 +1,17 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Group;
+
+import java.util.List;
+
+public interface GroupService {
+ void createGroup(Group group);
+
+ Group getGroupById(Long id);
+
+ List getAllGroups();
+
+ void updateGroup(Long id, Group group);
+
+ void deleteGroup(Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/service/GroupServiceImpl.java b/university/src/main/java/edu/unive/university/service/GroupServiceImpl.java
new file mode 100644
index 0000000..a89a389
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/GroupServiceImpl.java
@@ -0,0 +1,56 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Group;
+import edu.unive.university.domain.entity.GroupEntity;
+import edu.unive.university.domain.mapper.GroupEntityMapper;
+import edu.unive.university.domain.mapper.GroupMapper;
+import edu.unive.university.repository.GroupRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@RequiredArgsConstructor
+@Service
+public class GroupServiceImpl implements GroupService {
+ private final GroupRepository groupRepository;
+
+ private final GroupMapper groupMapper;
+ private final GroupEntityMapper groupEntityMapper;
+
+ @Override
+ public void createGroup(Group group) {
+ GroupEntity entity = groupEntityMapper.toEntity(group);
+ entity.setId(null);
+ groupRepository.save(entity);
+ }
+
+ @Override
+ public Group getGroupById(Long id) {
+ GroupEntity entity = groupRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Group not found"));
+ return groupMapper.toDTO(entity);
+ }
+
+ @Override
+ public List getAllGroups() {
+ return groupRepository.findAll().stream()
+ .map(groupMapper::toDTO)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void updateGroup(Long id, Group group) {
+ GroupEntity existingEntity = groupRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Group not found"));
+ GroupEntity updatedEntity = groupEntityMapper.toEntity(group);
+ updatedEntity.setId(existingEntity.getId()); // Сохраняем ID
+ GroupEntity savedEntity = groupRepository.save(updatedEntity);
+ }
+
+ @Override
+ public void deleteGroup(Long id) {
+ groupRepository.deleteById(id);
+ }
+}
diff --git a/university/src/main/java/edu/unive/university/service/TeacherService.java b/university/src/main/java/edu/unive/university/service/TeacherService.java
new file mode 100644
index 0000000..a9f96e0
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/TeacherService.java
@@ -0,0 +1,17 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Teacher;
+
+import java.util.List;
+
+public interface TeacherService {
+ void createTeacher(Teacher teacher);
+
+ Teacher getTeacherById(Long id);
+
+ List getAllTeachers();
+
+ Teacher updateTeacher(Long id, Teacher teacher);
+
+ void deleteTeacher(Long id);
+}
diff --git a/university/src/main/java/edu/unive/university/service/TeacherServiceImpl.java b/university/src/main/java/edu/unive/university/service/TeacherServiceImpl.java
new file mode 100644
index 0000000..9164ba7
--- /dev/null
+++ b/university/src/main/java/edu/unive/university/service/TeacherServiceImpl.java
@@ -0,0 +1,57 @@
+package edu.unive.university.service;
+
+import edu.unive.university.domain.Teacher;
+import edu.unive.university.domain.entity.TeacherEntity;
+import edu.unive.university.domain.mapper.TeacherEntityMapper;
+import edu.unive.university.domain.mapper.TeacherMapper;
+import edu.unive.university.repository.TeacherRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor
+public class TeacherServiceImpl implements TeacherService {
+ private final TeacherRepository teacherRepository;
+
+ private final TeacherMapper teacherMapper;
+ private final TeacherEntityMapper teacherEntityMapper;
+
+ @Override
+ public void createTeacher(Teacher teacher) {
+ TeacherEntity entity = teacherEntityMapper.toEntity(teacher);
+ entity.setId(null);
+ teacherRepository.save(entity);
+ }
+
+ @Override
+ public Teacher getTeacherById(Long id) {
+ TeacherEntity entity = teacherRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Teacher not found"));
+ return teacherMapper.toDTO(entity);
+ }
+
+ @Override
+ public List getAllTeachers() {
+ return teacherRepository.findAll().stream()
+ .map(teacherMapper::toDTO)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Teacher updateTeacher(Long id, Teacher teacher) {
+ TeacherEntity existingEntity = teacherRepository.findById(id)
+ .orElseThrow(() -> new RuntimeException("Teacher not found"));
+ TeacherEntity updatedEntity = teacherEntityMapper.toEntity(teacher);
+ updatedEntity.setId(existingEntity.getId()); // Сохраняем ID
+ TeacherEntity savedEntity = teacherRepository.save(updatedEntity);
+ return teacherMapper.toDTO(savedEntity);
+ }
+
+ @Override
+ public void deleteTeacher(Long id) {
+ teacherRepository.deleteById(id);
+ }
+}
diff --git a/university/src/main/resources/application.properties b/university/src/main/resources/application.properties
deleted file mode 100644
index 4972a67..0000000
--- a/university/src/main/resources/application.properties
+++ /dev/null
@@ -1 +0,0 @@
-spring.application.name=university
diff --git a/university/src/main/resources/application.yml b/university/src/main/resources/application.yml
new file mode 100644
index 0000000..58f5432
--- /dev/null
+++ b/university/src/main/resources/application.yml
@@ -0,0 +1,18 @@
+server:
+ port: 8281
+spring:
+ application.name: university
+ datasource:
+ url: jdbc:postgresql://localhost:5432/u_university
+ username: postgres
+ password: postgres
+ flyway:
+ enabled: true
+ locations: classpath:db/migration
+ baseline-on-migrate: true
+ jpa:
+ show-sql: true
+ properties:
+ hibernate:
+ format_sql: true
+ use_sql_comments: true
\ No newline at end of file
diff --git a/university/src/main/resources/db/migration/V1__init.sql b/university/src/main/resources/db/migration/V1__init.sql
new file mode 100644
index 0000000..1cbf103
--- /dev/null
+++ b/university/src/main/resources/db/migration/V1__init.sql
@@ -0,0 +1,39 @@
+CREATE TABLE faculty (
+ id BIGSERIAL
+ CONSTRAINT faculty_pk PRIMARY KEY,
+ name VARCHAR(255) NOT NULL
+);
+
+CREATE TABLE department (
+ id BIGSERIAL
+ CONSTRAINT department_pk PRIMARY KEY,
+ name VARCHAR(255) NOT NULL,
+ faculty_id BIGINT,
+ CONSTRAINT fk_faculty FOREIGN KEY (faculty_id) REFERENCES faculty(id)
+);
+
+CREATE TABLE teacher (
+ id BIGSERIAL
+ CONSTRAINT teacher_pk PRIMARY KEY,
+ first_name VARCHAR(255) NOT NULL,
+ last_name VARCHAR(255) NOT NULL,
+ department_id BIGINT,
+ CONSTRAINT fk_department FOREIGN KEY (department_id) REFERENCES department(id)
+);
+
+CREATE TABLE direction (
+ id BIGSERIAL
+ CONSTRAINT direction_pk PRIMARY KEY,
+ name VARCHAR(255) NOT NULL,
+ department_id BIGINT,
+ CONSTRAINT fk_department FOREIGN KEY (department_id) REFERENCES department(id)
+);
+
+CREATE TABLE st_group (
+ id BIGSERIAL
+ CONSTRAINT group_pk PRIMARY KEY,
+ name VARCHAR(255) NOT NULL,
+ direction_id BIGINT,
+ CONSTRAINT fk_direction FOREIGN KEY (direction_id) REFERENCES direction(id)
+);
+