Compare commits
6 Commits
e58961ab74
...
01a2b1b0ea
Author | SHA1 | Date | |
---|---|---|---|
01a2b1b0ea | |||
|
c1d1db14b0 | ||
|
f58b3c5cfa | ||
|
1cd45c49f0 | ||
|
867345d696 | ||
|
b6fcd0c52b |
@ -98,6 +98,12 @@
|
|||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.pdfbox</groupId>
|
||||||
|
<artifactId>pdfbox</artifactId>
|
||||||
|
<version>2.0.29</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
package edu.unive.schedule.controller;
|
package edu.unive.schedule.controller;
|
||||||
|
|
||||||
import edu.unive.schedule.domain.Schedule;
|
import edu.unive.schedule.domain.Schedule;
|
||||||
|
import edu.unive.schedule.service.PdfGenerationService;
|
||||||
import edu.unive.schedule.service.ScheduleService;
|
import edu.unive.schedule.service.ScheduleService;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ScheduleController implements ScheduleApi {
|
public class ScheduleController implements ScheduleApi {
|
||||||
|
|
||||||
private final ScheduleService scheduleService;
|
private final ScheduleService scheduleService;
|
||||||
|
private final PdfGenerationService pdfGenerationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Void> createSchedule(Schedule scheduleDTO) {
|
public ResponseEntity<Void> createSchedule(Schedule scheduleDTO) {
|
||||||
@ -30,4 +37,15 @@ public class ScheduleController implements ScheduleApi {
|
|||||||
scheduleService.deleteSchedule(id);
|
scheduleService.deleteSchedule(id);
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/download/{groupId}")
|
||||||
|
public ResponseEntity<byte[]> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
package edu.unive.schedule.domain;
|
package edu.unive.schedule.domain;
|
||||||
|
|
||||||
|
import edu.unive.schedule.domain.entity.DayOfWeek;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Schedule {
|
public class Schedule {
|
||||||
private Long id;
|
private Long id;
|
||||||
private int pairNumber;
|
private int pairNumber;
|
||||||
|
private Integer weekNumber;
|
||||||
|
private DayOfWeek dayOfWeek;
|
||||||
private Long classroomId;
|
private Long classroomId;
|
||||||
private Long courseId; // ID курса из внешнего микросервиса
|
private Long courseId; // ID курса из внешнего микросервиса
|
||||||
private Long teacherId; // ID преподавателя из внешнего микросервиса
|
private Long teacherId; // ID преподавателя из внешнего микросервиса
|
||||||
|
private List<Long> groupIds;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package edu.unive.schedule.domain.entity;
|
||||||
|
|
||||||
|
public enum DayOfWeek {
|
||||||
|
MONDAY,
|
||||||
|
TUESDAY,
|
||||||
|
WEDNESDAY,
|
||||||
|
THURSDAY,
|
||||||
|
FRIDAY,
|
||||||
|
SATURDAY,
|
||||||
|
SUNDAY
|
||||||
|
}
|
@ -3,7 +3,7 @@ package edu.unive.schedule.domain.entity;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@ -13,13 +13,24 @@ public class ScheduleEntity {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", nullable = false, unique = true)
|
@Column(name = "id", nullable = false, unique = true)
|
||||||
private Long id;
|
private Long id;
|
||||||
@Column(name = "pair_number", nullable = false)
|
@Column(name = "pair_number")
|
||||||
private int pairNumber;
|
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<Long> groupIds;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "classroom_id")
|
@JoinColumn(name = "classroom_id")
|
||||||
private ClassroomEntity classroom;
|
private ClassroomEntity classroom;
|
||||||
|
|
||||||
|
@Column(name = "course_id")
|
||||||
private Long courseId; // ID курса из внешнего микросервиса
|
private Long courseId; // ID курса из внешнего микросервиса
|
||||||
|
@Column(name = "teacher_id")
|
||||||
private Long teacherId; // ID преподавателя из внешнего микросервиса
|
private Long teacherId; // ID преподавателя из внешнего микросервиса
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ package edu.unive.schedule.repository;
|
|||||||
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public interface ScheduleRepository extends JpaRepository<ScheduleEntity, Long> {
|
public interface ScheduleRepository extends JpaRepository<ScheduleEntity, Long> {
|
||||||
|
List<ScheduleEntity> findByGroupIdsContaining(Long groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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<ScheduleEntity> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,8 @@ import jakarta.transaction.Transactional;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ScheduleServiceImpl implements ScheduleService {
|
public class ScheduleServiceImpl implements ScheduleService {
|
||||||
@ -35,4 +37,6 @@ public class ScheduleServiceImpl implements ScheduleService {
|
|||||||
public void deleteSchedule(Long id) {
|
public void deleteSchedule(Long id) {
|
||||||
scheduleRepository.deleteById(id);
|
scheduleRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO генерация расписания
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,17 @@ CREATE TABLE schedule (
|
|||||||
id BIGSERIAL
|
id BIGSERIAL
|
||||||
CONSTRAINT schedule_pk PRIMARY KEY,
|
CONSTRAINT schedule_pk PRIMARY KEY,
|
||||||
pair_number INT,
|
pair_number INT,
|
||||||
|
week_number INT,
|
||||||
|
day_of_week VARCHAR(20),
|
||||||
classroom_id BIGINT,
|
classroom_id BIGINT,
|
||||||
course_id BIGINT,
|
course_id BIGINT,
|
||||||
teacher_id BIGINT,
|
teacher_id BIGINT,
|
||||||
FOREIGN KEY (classroom_id) REFERENCES classroom(id)
|
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)
|
||||||
);
|
);
|
@ -31,6 +31,10 @@
|
|||||||
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.flywaydb</groupId>
|
<groupId>org.flywaydb</groupId>
|
||||||
<artifactId>flyway-core</artifactId>
|
<artifactId>flyway-core</artifactId>
|
||||||
@ -68,6 +72,32 @@
|
|||||||
<artifactId>spring-kafka-test</artifactId>
|
<artifactId>spring-kafka-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<version>1.5.5.Final</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>1.5.5.Final</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Swagger -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -92,6 +122,11 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</path>
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
|
<version>1.5.5.Final</version>
|
||||||
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -2,8 +2,10 @@ package edu.unive.university;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@PropertySource("classpath:application.yml")
|
||||||
public class UniversityApplication {
|
public class UniversityApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -11,3 +13,4 @@ public class UniversityApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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<Void> createDepartment(@RequestBody Department department);
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
ResponseEntity<Department> getDepartmentById(@PathVariable Long id);
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
List<Department> getAllDepartments();
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
ResponseEntity<Void> updateDepartment(@PathVariable Long id, @RequestBody Department department);
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
ResponseEntity<Void> deleteDepartment(@PathVariable Long id);
|
||||||
|
}
|
@ -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<Void> createDepartment(Department department) {
|
||||||
|
departmentService.createDepartment(department);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Department> getDepartmentById(Long id) {
|
||||||
|
var dto = departmentService.getDepartmentById(id);
|
||||||
|
return ResponseEntity.ok(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Department> getAllDepartments() {
|
||||||
|
return departmentService.getAllDepartments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> updateDepartment(Long id, Department department) {
|
||||||
|
departmentService.updateDepartment(id, department);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> deleteDepartment(Long id) {
|
||||||
|
departmentService.deleteDepartment(id);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
}
|
@ -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<Void> createDirection(@RequestBody Direction direction);
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
ResponseEntity<Direction> getDirectionById(@PathVariable Long id);
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
List<Direction> getAllDirections();
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
ResponseEntity<Void> updateDirection(@PathVariable Long id, @RequestBody Direction direction);
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
ResponseEntity<Void> deleteDirection(@PathVariable Long id);
|
||||||
|
}
|
@ -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<Void> createDirection(Direction direction) {
|
||||||
|
directionService.createDirection(direction);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Direction> getDirectionById(Long id) {
|
||||||
|
var dto = directionService.getDirectionById(id);
|
||||||
|
return ResponseEntity.ok(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Direction> getAllDirections() {
|
||||||
|
return directionService.getAllDirections();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> updateDirection(Long id, Direction direction) {
|
||||||
|
directionService.updateDirection(id, direction);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> deleteDirection(Long id) {
|
||||||
|
directionService.deleteDirection(id);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
}
|
@ -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<Void> createFaculty(@RequestBody Faculty faculty);
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
ResponseEntity<Faculty> getFacultyById(@PathVariable Long id);
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
List<Faculty> getAllFaculties();
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
ResponseEntity<Void> updateFaculty(@PathVariable Long id, @RequestBody Faculty faculty);
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
ResponseEntity<Void> deleteFaculty(@PathVariable Long id);
|
||||||
|
}
|
@ -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<Void> createFaculty(Faculty faculty) {
|
||||||
|
facultyService.createFaculty(faculty);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Faculty> getFacultyById(Long id) {
|
||||||
|
var dto = facultyService.getFacultyById(id);
|
||||||
|
return ResponseEntity.ok().body(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Faculty> getAllFaculties() {
|
||||||
|
return facultyService.getAllFaculties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> updateFaculty(Long id, Faculty faculty) {
|
||||||
|
facultyService.updateFaculty(id, faculty);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> deleteFaculty(Long id) {
|
||||||
|
facultyService.deleteFaculty(id);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
}
|
@ -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<Void> createGroup(@RequestBody Group group);
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
ResponseEntity<Group> getGroupById(@PathVariable Long id);
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
List<Group> getAllGroups();
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
ResponseEntity<Void> updateGroup(@PathVariable Long id, @RequestBody Group group);
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
ResponseEntity<Void> deleteGroup(@PathVariable Long id);
|
||||||
|
}
|
@ -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<Void> createGroup(Group group) {
|
||||||
|
groupService.createGroup(group);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Group> getGroupById( Long id) {
|
||||||
|
var dto = groupService.getGroupById(id);
|
||||||
|
return ResponseEntity.ok().body(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Group> getAllGroups() {
|
||||||
|
return groupService.getAllGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> updateGroup( Long id, Group group) {
|
||||||
|
groupService.updateGroup(id, group);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> deleteGroup( Long id) {
|
||||||
|
groupService.deleteGroup(id);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
}
|
@ -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<Void> createTeacher(@RequestBody Teacher teacher);
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
ResponseEntity<Teacher> getTeacherById(@PathVariable Long id);
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
List<Teacher> getAllTeachers();
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
ResponseEntity<Void> updateTeacher(@PathVariable Long id, @RequestBody Teacher teacher);
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
ResponseEntity<Void> deleteTeacher(@PathVariable Long id);
|
||||||
|
}
|
@ -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<Void> createTeacher(@RequestBody Teacher teacher) {
|
||||||
|
teacherService.createTeacher(teacher);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Teacher> getTeacherById(@PathVariable Long id) {
|
||||||
|
var dto = teacherService.getTeacherById(id);
|
||||||
|
return ResponseEntity.ok(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Teacher> getAllTeachers() {
|
||||||
|
return teacherService.getAllTeachers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> updateTeacher(@PathVariable Long id, @RequestBody Teacher teacher) {
|
||||||
|
teacherService.updateTeacher(id, teacher);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> deleteTeacher(@PathVariable Long id) {
|
||||||
|
teacherService.deleteTeacher(id);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package edu.unive.university.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Faculty {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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<TeacherEntity> teachers;
|
||||||
|
}
|
@ -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<GroupEntity> groups;
|
||||||
|
|
||||||
|
}
|
@ -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<DepartmentEntity> departments;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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<DepartmentEntity, Long> {
|
||||||
|
}
|
@ -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<DirectionEntity, Long> {
|
||||||
|
}
|
@ -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<FacultyEntity, Long> {
|
||||||
|
}
|
||||||
|
|
@ -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<GroupEntity, Long> {
|
||||||
|
}
|
@ -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<TeacherEntity, Long> {
|
||||||
|
}
|
@ -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<Department> getAllDepartments();
|
||||||
|
|
||||||
|
void updateDepartment(Long id, Department department);
|
||||||
|
|
||||||
|
void deleteDepartment(Long id);
|
||||||
|
}
|
@ -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<Department> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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<Direction> getAllDirections();
|
||||||
|
|
||||||
|
Direction updateDirection(Long id, Direction direction);
|
||||||
|
|
||||||
|
void deleteDirection(Long id);
|
||||||
|
}
|
@ -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<Direction> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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<Faculty> getAllFaculties();
|
||||||
|
|
||||||
|
void updateFaculty(Long id, Faculty faculty);
|
||||||
|
|
||||||
|
void deleteFaculty(Long id);
|
||||||
|
}
|
@ -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<Faculty> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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<Group> getAllGroups();
|
||||||
|
|
||||||
|
void updateGroup(Long id, Group group);
|
||||||
|
|
||||||
|
void deleteGroup(Long id);
|
||||||
|
}
|
@ -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<Group> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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<Teacher> getAllTeachers();
|
||||||
|
|
||||||
|
Teacher updateTeacher(Long id, Teacher teacher);
|
||||||
|
|
||||||
|
void deleteTeacher(Long id);
|
||||||
|
}
|
@ -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<Teacher> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
spring.application.name=university
|
|
18
university/src/main/resources/application.yml
Normal file
18
university/src/main/resources/application.yml
Normal file
@ -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
|
39
university/src/main/resources/db/migration/V1__init.sql
Normal file
39
university/src/main/resources/db/migration/V1__init.sql
Normal file
@ -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)
|
||||||
|
);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user