Compare commits
No commits in common. "e58961ab74dc59818e8a1fc9a340975f64f13916" and "6e460ef5fc8c79051d6bb91207fa523352d7869c" have entirely different histories.
e58961ab74
...
6e460ef5fc
@ -31,10 +31,6 @@
|
|||||||
<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>
|
||||||
@ -72,32 +68,6 @@
|
|||||||
<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>
|
||||||
@ -122,11 +92,6 @@
|
|||||||
<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,10 +2,8 @@ package edu.unive.schedule;
|
|||||||
|
|
||||||
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 ScheduleApplication {
|
public class ScheduleApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package edu.unive.schedule.controller;
|
|
||||||
|
|
||||||
import edu.unive.schedule.domain.Schedule;
|
|
||||||
import edu.unive.schedule.service.ScheduleService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ScheduleController implements ScheduleApi {
|
|
||||||
|
|
||||||
private final ScheduleService scheduleService;
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package edu.unive.schedule.domain;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class Schedule {
|
|
||||||
private Long id;
|
|
||||||
private int pairNumber;
|
|
||||||
private Long classroomId;
|
|
||||||
private Long courseId; // ID курса из внешнего микросервиса
|
|
||||||
private Long teacherId; // ID преподавателя из внешнего микросервиса
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package edu.unive.schedule.domain.entity;
|
|
||||||
|
|
||||||
public enum ClassroomType {
|
|
||||||
LECTURE,
|
|
||||||
LAB
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package edu.unive.schedule.domain.entity;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@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", nullable = false)
|
|
||||||
private int pairNumber;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "classroom_id")
|
|
||||||
private ClassroomEntity classroom;
|
|
||||||
|
|
||||||
private Long courseId; // ID курса из внешнего микросервиса
|
|
||||||
private Long teacherId; // ID преподавателя из внешнего микросервиса
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
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> {
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
package edu.unive.schedule.repository;
|
|
||||||
|
|
||||||
import edu.unive.schedule.domain.entity.ScheduleEntity;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
|
|
||||||
public interface ScheduleRepository extends JpaRepository<ScheduleEntity, Long> {
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
package edu.unive.schedule.service;
|
|
||||||
|
|
||||||
import edu.unive.schedule.domain.Classroom;
|
|
||||||
|
|
||||||
public interface ClassroomService {
|
|
||||||
void createClassroom(Classroom classroom);
|
|
||||||
Classroom getClassroomById(Long id);
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
1
schedule/src/main/resources/application.properties
Normal file
1
schedule/src/main/resources/application.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
spring.application.name=schedule
|
@ -1,18 +0,0 @@
|
|||||||
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
|
|
@ -1,16 +0,0 @@
|
|||||||
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,
|
|
||||||
classroom_id BIGINT,
|
|
||||||
course_id BIGINT,
|
|
||||||
teacher_id BIGINT,
|
|
||||||
FOREIGN KEY (classroom_id) REFERENCES classroom(id)
|
|
||||||
);
|
|
@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class ScheduleEntityApplicationTests {
|
class ScheduleApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
Loading…
x
Reference in New Issue
Block a user