Merge pull request 'Первый запрос на слияние пока никто не видит' (#1) from feature/egor/start into dev
Reviewed-on: #1
This commit is contained in:
commit
e58961ab74
@ -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.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) {
|
||||||
|
@ -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,33 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
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 преподавателя из внешнего микросервиса
|
||||||
|
}
|
@ -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,25 @@
|
|||||||
|
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 преподавателя из внешнего микросервиса
|
||||||
|
}
|
@ -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,9 @@
|
|||||||
|
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> {
|
||||||
|
}
|
||||||
|
|
@ -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,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,38 @@
|
|||||||
|
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 +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
|
16
schedule/src/main/resources/db/migration/V1__Init.sql
Normal file
16
schedule/src/main/resources/db/migration/V1__Init.sql
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
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 ScheduleApplicationTests {
|
class ScheduleEntityApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
Loading…
x
Reference in New Issue
Block a user