Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
ebf269d45b | |||
|
b6f1d34e29 | ||
01a2b1b0ea | |||
|
c1d1db14b0 | ||
|
f58b3c5cfa | ||
|
1cd45c49f0 | ||
|
867345d696 | ||
|
b6fcd0c52b | ||
e58961ab74 | |||
|
b83d88f442 | ||
|
663df6a313 | ||
|
7b2cfb24a1 | ||
|
90871685e9 |
@ -31,6 +31,10 @@
|
||||
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
@ -68,6 +72,38 @@
|
||||
<artifactId>spring-kafka-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.29</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@ -92,6 +128,11 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.5.5.Final</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -2,8 +2,12 @@ package edu.unive.schedule;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("classpath:application.yml")
|
||||
@EnableFeignClients
|
||||
public class ScheduleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -0,0 +1,27 @@
|
||||
package edu.unive.schedule.client;
|
||||
|
||||
import edu.unive.schedule.domain.Group;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = "group-service", url = "http://localhost:8281/api/groups")
|
||||
public interface GroupServiceClient {
|
||||
|
||||
@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,27 @@
|
||||
package edu.unive.schedule.client;
|
||||
|
||||
import edu.unive.schedule.domain.Teacher;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(name = "teacher-service", url = "http://localhost:8281/api/teachers")
|
||||
public interface TeacherServiceClient {
|
||||
|
||||
@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,14 @@
|
||||
package edu.unive.schedule.controller;
|
||||
|
||||
import edu.unive.schedule.domain.Classroom;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RequestMapping("/api/classrooms")
|
||||
public interface ClassroomApi {
|
||||
@PostMapping
|
||||
ResponseEntity<Void> createClassroom(@RequestBody Classroom classroomDTO);
|
||||
|
||||
@GetMapping("/{id}")
|
||||
ResponseEntity<Classroom> getClassroom(@PathVariable Long id);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package edu.unive.schedule.controller;
|
||||
|
||||
import edu.unive.schedule.domain.Classroom;
|
||||
import edu.unive.schedule.service.ClassroomService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class ClassroomController implements ClassroomApi{
|
||||
|
||||
private final ClassroomService classroomService;
|
||||
|
||||
public ResponseEntity<Void> createClassroom(Classroom classroomDTO) {
|
||||
classroomService.createClassroom(classroomDTO);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
public ResponseEntity<Classroom> getClassroom(Long id) {
|
||||
var dto = classroomService.getClassroomById(id);
|
||||
return ResponseEntity.ok(dto);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package edu.unive.schedule.controller;
|
||||
|
||||
import edu.unive.schedule.domain.Schedule;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RequestMapping("/api/schedules")
|
||||
public interface ScheduleApi {
|
||||
|
||||
@PostMapping
|
||||
ResponseEntity<Void> createSchedule(@RequestBody Schedule scheduleDTO);
|
||||
|
||||
@PutMapping("/{id}")
|
||||
ResponseEntity<Schedule> updateSchedule(@PathVariable Long id, @RequestBody Schedule scheduleDTO);
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
ResponseEntity<Void> deleteSchedule(@PathVariable Long id);
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
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<Void> createSchedule(Schedule scheduleDTO) {
|
||||
scheduleService.createSchedule(scheduleDTO);
|
||||
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Schedule> updateSchedule(Long id, Schedule scheduleDTO) {
|
||||
scheduleService.updateSchedule(id, scheduleDTO);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteSchedule(@PathVariable Long id) {
|
||||
scheduleService.deleteSchedule(id);
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package edu.unive.schedule.domain;
|
||||
|
||||
|
||||
import edu.unive.schedule.domain.entity.ClassroomType;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Classroom {
|
||||
private Long id;
|
||||
private String name;
|
||||
private ClassroomType type;
|
||||
}
|
10
schedule/src/main/java/edu/unive/schedule/domain/Group.java
Normal file
10
schedule/src/main/java/edu/unive/schedule/domain/Group.java
Normal file
@ -0,0 +1,10 @@
|
||||
package edu.unive.schedule.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Group {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Long directionId;
|
||||
}
|
@ -0,0 +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<Long> groupIds;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package edu.unive.schedule.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Teacher {
|
||||
private Long id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private Long departmentId;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package edu.unive.schedule.domain.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "classroom")
|
||||
public class ClassroomEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
private Long id;
|
||||
@Column(name = "name", nullable = false)
|
||||
private String name;
|
||||
@Column(name = "type", nullable = false)
|
||||
private ClassroomType type;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package edu.unive.schedule.domain.entity;
|
||||
|
||||
public enum ClassroomType {
|
||||
LECTURE,
|
||||
LAB
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package edu.unive.schedule.domain.entity;
|
||||
|
||||
public enum DayOfWeek {
|
||||
MONDAY,
|
||||
TUESDAY,
|
||||
WEDNESDAY,
|
||||
THURSDAY,
|
||||
FRIDAY,
|
||||
SATURDAY,
|
||||
SUNDAY
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package edu.unive.schedule.domain.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "schedule")
|
||||
public class ScheduleEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false, unique = true)
|
||||
private Long id;
|
||||
@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<Long> 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 преподавателя из внешнего микросервиса
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package edu.unive.schedule.domain.mapper;
|
||||
|
||||
import edu.unive.schedule.domain.Classroom;
|
||||
import edu.unive.schedule.domain.entity.ClassroomEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ClassroomEntityMapper {
|
||||
ClassroomEntity ToEntity(Classroom classroom);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package edu.unive.schedule.domain.mapper;
|
||||
|
||||
import edu.unive.schedule.domain.Classroom;
|
||||
import edu.unive.schedule.domain.entity.ClassroomEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ClassroomMapper {
|
||||
Classroom toDTO(ClassroomEntity classroomEntity);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package edu.unive.schedule.domain.mapper;
|
||||
|
||||
import edu.unive.schedule.domain.Schedule;
|
||||
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ScheduleEntityMapper {
|
||||
@Mapping(source = "classroomId", target = "classroom.id")
|
||||
ScheduleEntity toEntity(Schedule schedule);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package edu.unive.schedule.domain.mapper;
|
||||
|
||||
import edu.unive.schedule.domain.Schedule;
|
||||
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ScheduleMapper {
|
||||
@Mapping(source = "classroomEntity.id", target = "classroomId")
|
||||
Schedule toDTO(ScheduleEntity classroomEntity);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package edu.unive.schedule.repository;
|
||||
|
||||
import edu.unive.schedule.domain.entity.ClassroomEntity;
|
||||
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
|
||||
public interface ClassroomRepository extends JpaRepository<ClassroomEntity, Long> {
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
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<ScheduleEntity, Long> {
|
||||
List<ScheduleEntity> findByGroupIdsContaining(Long groupId);
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package edu.unive.schedule.service;
|
||||
|
||||
import edu.unive.schedule.domain.Classroom;
|
||||
|
||||
public interface ClassroomService {
|
||||
void createClassroom(Classroom classroom);
|
||||
Classroom getClassroomById(Long id);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package edu.unive.schedule.service;
|
||||
|
||||
import edu.unive.schedule.domain.Classroom;
|
||||
import edu.unive.schedule.domain.mapper.ClassroomEntityMapper;
|
||||
import edu.unive.schedule.domain.mapper.ClassroomMapper;
|
||||
import edu.unive.schedule.repository.ClassroomRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ClassroomServiceImpl implements ClassroomService {
|
||||
|
||||
private final ClassroomRepository classroomRepository;
|
||||
private final ClassroomEntityMapper classroomEntityMapper;
|
||||
private final ClassroomMapper classroomMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void createClassroom(Classroom classroomDTO) {
|
||||
var entity = classroomEntityMapper.ToEntity(classroomDTO);
|
||||
entity.setId(null);
|
||||
classroomRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classroom getClassroomById(Long id) {
|
||||
return classroomMapper.toDTO(classroomRepository.findById(id).orElse(null));
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package edu.unive.schedule.service;
|
||||
|
||||
import edu.unive.schedule.client.GroupServiceClient;
|
||||
import edu.unive.schedule.client.TeacherServiceClient;
|
||||
import edu.unive.schedule.domain.Group;
|
||||
import edu.unive.schedule.domain.Teacher;
|
||||
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.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@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 = fetchGroupNames(schedule.getGroupIds());
|
||||
|
||||
// Получаем данные о преподавателе из внешнего микросервиса
|
||||
String teacherName = fetchTeacherName(schedule.getTeacherId());
|
||||
|
||||
// Формируем текст для PDF
|
||||
String classroomName = (schedule.getClassroom() != null) ? schedule.getClassroom().getName() : "N/A";
|
||||
|
||||
String text = String.format(
|
||||
"Week %d, %s, Pair %d: Course %s - Classroom %s (Teacher: %s, Groups: %s)",
|
||||
schedule.getWeekNumber(),
|
||||
schedule.getDayOfWeek(),
|
||||
schedule.getPairNumber(),
|
||||
schedule.getCourseId(),
|
||||
classroomName,
|
||||
teacherName,
|
||||
groupNames
|
||||
);
|
||||
|
||||
// Выводим текст на страницу PDF
|
||||
contentStream.beginText();
|
||||
contentStream.newLineAtOffset(100, yOffset);
|
||||
contentStream.showText(text);
|
||||
contentStream.endText();
|
||||
|
||||
yOffset -= 20; // Смещение следующей строки вниз
|
||||
}
|
||||
}
|
||||
|
||||
// Сохраняем документ PDF в ByteArrayOutputStream
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
document.save(byteArrayOutputStream);
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Метод для получения названий групп.
|
||||
*
|
||||
* @param groupIds Список ID групп
|
||||
* @return Строка с названиями групп через запятую или "No Groups"
|
||||
*/
|
||||
private String fetchGroupNames(List<Long> groupIds) {
|
||||
if (groupIds == null || groupIds.isEmpty()) {
|
||||
return "No Groups";
|
||||
}
|
||||
|
||||
return groupIds.stream()
|
||||
.map(groupId -> {
|
||||
ResponseEntity<Group> groupResponse = groupServiceClient.getGroupById(groupId);
|
||||
Group group = groupResponse.getBody();
|
||||
return (group != null) ? group.getName() : "Unknown Group";
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
/**
|
||||
* Метод для получения имени преподавателя.
|
||||
*
|
||||
* @param teacherId ID преподавателя
|
||||
* @return Имя преподавателя или "Unknown Teacher"
|
||||
*/
|
||||
private String fetchTeacherName(Long teacherId) {
|
||||
if (teacherId == null) {
|
||||
return "Unknown Teacher";
|
||||
}
|
||||
|
||||
ResponseEntity<Teacher> teacherResponse = teacherServiceClient.getTeacherById(teacherId);
|
||||
Teacher teacher = teacherResponse.getBody();
|
||||
return (teacher != null && teacher.getLastName() != null) ? teacher.getLastName() : "Unknown Teacher";
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package edu.unive.schedule.service;
|
||||
|
||||
import edu.unive.schedule.domain.Schedule;
|
||||
|
||||
public interface ScheduleService {
|
||||
void createSchedule(Schedule schedule);
|
||||
void updateSchedule(Long id, Schedule schedule);
|
||||
void deleteSchedule(Long id);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package edu.unive.schedule.service;
|
||||
|
||||
import edu.unive.schedule.domain.Schedule;
|
||||
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
||||
import edu.unive.schedule.domain.mapper.ScheduleEntityMapper;
|
||||
import edu.unive.schedule.repository.ScheduleRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ScheduleServiceImpl implements ScheduleService {
|
||||
|
||||
private final ScheduleRepository scheduleRepository;
|
||||
|
||||
private final ScheduleEntityMapper scheduleEntityMapper;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void createSchedule(Schedule scheduleDTO) {
|
||||
ScheduleEntity entity = scheduleEntityMapper.toEntity(scheduleDTO);
|
||||
entity.setId(null);
|
||||
scheduleRepository.save(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updateSchedule(Long id, Schedule scheduleDTO) {
|
||||
ScheduleEntity entity = scheduleEntityMapper.toEntity(scheduleDTO);
|
||||
scheduleRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSchedule(Long id) {
|
||||
scheduleRepository.deleteById(id);
|
||||
}
|
||||
|
||||
//TODO генерация расписания
|
||||
}
|
@ -1 +0,0 @@
|
||||
spring.application.name=schedule
|
18
schedule/src/main/resources/application.yml
Normal file
18
schedule/src/main/resources/application.yml
Normal file
@ -0,0 +1,18 @@
|
||||
server:
|
||||
port: 8280
|
||||
spring:
|
||||
application.name: schedule
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/u_schedule
|
||||
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
|
25
schedule/src/main/resources/db/migration/V1__Init.sql
Normal file
25
schedule/src/main/resources/db/migration/V1__Init.sql
Normal file
@ -0,0 +1,25 @@
|
||||
CREATE TABLE classroom (
|
||||
id BIGSERIAL
|
||||
CONSTRAINT classroom_pk PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(50) NOT NULL
|
||||
);
|
||||
|
||||
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)
|
||||
);
|
@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ScheduleApplicationTests {
|
||||
class ScheduleEntityApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
@ -31,6 +31,10 @@
|
||||
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
@ -68,6 +72,32 @@
|
||||
<artifactId>spring-kafka-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@ -92,6 +122,11 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.5.5.Final</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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