Skip to content
Snippets Groups Projects
Commit 8940442d authored by Petr Kabourek's avatar Petr Kabourek
Browse files

Merge branch 'airports-planes-service' into 'main'

Airports planes service

See merge request !5
parents ef67bf50 5a37ac07
No related branches found
No related tags found
1 merge request!5Airports planes service
Showing
with 299 additions and 8 deletions
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.8.0</version>
<configuration>
<release>8</release>
<verbose>true</verbose>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
......
package cz.muni.fi.pa165.api.employee; package cz.muni.fi.pa165.api.employee;
import cz.muni.fi.pa165.api.plane.PlaneType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
@Data @Data
......
...@@ -12,6 +12,7 @@ import java.util.UUID; ...@@ -12,6 +12,7 @@ import java.util.UUID;
public class Plane { public class Plane {
private UUID id; private UUID id;
private String name; private String name;
private PlaneType planeType;
private int maxCapacity; private int maxCapacity;
private short pilotsRequired; private short pilotsRequired;
} }
package cz.muni.fi.pa165.api.employee; package cz.muni.fi.pa165.api.plane;
public enum PlaneType { public enum PlaneType {
CESSNA, CESSNA,
......
package cz.muni.fi.pa165.api.plane.requests;
import cz.muni.fi.pa165.api.plane.PlaneType;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class PlaneRequest {
private String name;
private PlaneType planeType;
private int maxCapacity;
private short pilotsRequired;
}
package cz.muni.fi.pa165.flight; package cz.muni.fi.pa165;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -15,7 +15,7 @@ public class SwaggerConfig { ...@@ -15,7 +15,7 @@ public class SwaggerConfig {
@Bean @Bean
public Docket facadesV1Api() { public Docket facadesV1Api() {
return createDocket() return createDocket()
.groupName("Facades - v1") .groupName("Human Resources")
.select() .select()
.apis(RequestHandlerSelectors.basePackage( .apis(RequestHandlerSelectors.basePackage(
cz.muni.fi.pa165.hr.rest.StewardController.class.getPackageName())) cz.muni.fi.pa165.hr.rest.StewardController.class.getPackageName()))
......
...@@ -2,13 +2,12 @@ package cz.muni.fi.pa165.hr.facade; ...@@ -2,13 +2,12 @@ package cz.muni.fi.pa165.hr.facade;
import cz.muni.fi.pa165.api.employee.Employee; import cz.muni.fi.pa165.api.employee.Employee;
import cz.muni.fi.pa165.api.employee.Pilot; import cz.muni.fi.pa165.api.employee.Pilot;
import cz.muni.fi.pa165.api.employee.PlaneType; import cz.muni.fi.pa165.api.plane.PlaneType;
import cz.muni.fi.pa165.api.employee.Steward; import cz.muni.fi.pa165.api.employee.Steward;
import cz.muni.fi.pa165.api.employee.requests.EmployeeRequest; import cz.muni.fi.pa165.api.employee.requests.EmployeeRequest;
import cz.muni.fi.pa165.api.employee.requests.PilotRequest; import cz.muni.fi.pa165.api.employee.requests.PilotRequest;
import cz.muni.fi.pa165.api.employee.requests.StewardRequest; import cz.muni.fi.pa165.api.employee.requests.StewardRequest;
import cz.muni.fi.pa165.hr.service.EmployeeService; import cz.muni.fi.pa165.hr.service.EmployeeService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
......
package cz.muni.fi.pa165.hr.rest; package cz.muni.fi.pa165.hr.rest;
import cz.muni.fi.pa165.api.employee.Pilot; import cz.muni.fi.pa165.api.employee.Pilot;
import cz.muni.fi.pa165.api.employee.PlaneType; import cz.muni.fi.pa165.api.plane.PlaneType;
import cz.muni.fi.pa165.api.employee.requests.PilotRequest; import cz.muni.fi.pa165.api.employee.requests.PilotRequest;
import cz.muni.fi.pa165.hr.facade.EmployeeFacade; import cz.muni.fi.pa165.hr.facade.EmployeeFacade;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
......
package cz.muni.fi.pa165.hr.service; package cz.muni.fi.pa165.hr.service;
import cz.muni.fi.pa165.api.employee.PlaneType; import cz.muni.fi.pa165.api.plane.PlaneType;
import cz.muni.fi.pa165.hr.dao.Employee; import cz.muni.fi.pa165.hr.dao.Employee;
import cz.muni.fi.pa165.hr.dao.Pilot; import cz.muni.fi.pa165.hr.dao.Pilot;
import cz.muni.fi.pa165.hr.dao.Steward; import cz.muni.fi.pa165.hr.dao.Steward;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
</parent> </parent>
<artifactId>airports-planes-service</artifactId> <artifactId>airports-planes-service</artifactId>
<version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
...@@ -17,4 +18,77 @@ ...@@ -17,4 +18,77 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>airport-manager-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-ui.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
package cz.muni.fi.pa165.planes;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
\ No newline at end of file
package cz.muni.fi.pa165.planes;
public class Constants {
public static final String PLANES_SCHEMA = "planes";
}
package cz.muni.fi.pa165.planes;
import cz.muni.fi.pa165.planes.rest.PlaneController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket facadesV1Api() {
return createDocket()
.groupName("Planes")
.select()
.apis(RequestHandlerSelectors.basePackage(
PlaneController.class.getPackageName()))
.paths(PathSelectors.any())
.build();
}
private Docket createDocket() {
return new Docket(DocumentationType.SWAGGER_2);
}
}
\ No newline at end of file
package cz.muni.fi.pa165.planes.dao;
import cz.muni.fi.pa165.planes.Constants;
import lombok.Data;
import javax.persistence.*;
import java.util.UUID;
@Data
@Entity
@Table(name = "plane", schema = Constants.PLANES_SCHEMA)
public class Plane {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
private String name;
private PlaneType planeType;
private int maxCapacity;
private short pilotsRequired;
}
package cz.muni.fi.pa165.planes.dao;
public enum PlaneType {
CESSNA,
AIRBUS_A380,
AIRBUS_A350,
AIRBUS_A320,
AIRBUS_A310,
}
package cz.muni.fi.pa165.planes.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.NOT_FOUND)
public class PlaneNotFoundException extends RuntimeException {
public PlaneNotFoundException() {
}
public PlaneNotFoundException(String message) {
super(message);
}
public PlaneNotFoundException(String message, Throwable cause) {
super(message, cause);
}
public PlaneNotFoundException(Throwable cause) {
super(cause);
}
public PlaneNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
package cz.muni.fi.pa165.planes.facade;
import cz.muni.fi.pa165.api.plane.PlaneType;
import cz.muni.fi.pa165.api.plane.Plane;
import cz.muni.fi.pa165.api.plane.requests.PlaneRequest;
import cz.muni.fi.pa165.planes.service.PlaneService;
import lombok.AllArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.UUID;
@Service
@AllArgsConstructor
public class PlaneFacade {
private final PlaneService planeService;
private final ModelMapper modelMapper = new ModelMapper();
public Plane create(PlaneRequest planeRequest) {
var result = planeService.create(modelMapper.map(planeRequest, cz.muni.fi.pa165.planes.dao.Plane.class));
return modelMapper.map(result, Plane.class);
}
public Plane get(UUID id) {
var result = planeService.get(id);
return modelMapper.map(result, Plane.class);
}
public Plane updateName(UUID id, String name) {
var result = planeService.updateName(id, name);
return modelMapper.map(result, Plane.class);
}
public List<Plane> getByType(PlaneType planeType) {
var result = planeService.getByType(modelMapper.map(planeType,cz.muni.fi.pa165.planes.dao.PlaneType.class));
return result.stream().map(p -> modelMapper.map(p, Plane.class)).toList();
}
}
package cz.muni.fi.pa165.planes.repository;
import cz.muni.fi.pa165.planes.dao.PlaneType;
import cz.muni.fi.pa165.planes.dao.Plane;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.UUID;
@Repository
public interface PlaneRepository extends CrudRepository<Plane, UUID> {
List<Plane> findByPlaneType(PlaneType planeType);
}
package cz.muni.fi.pa165.planes.rest;
import cz.muni.fi.pa165.planes.facade.PlaneFacade;
import cz.muni.fi.pa165.api.plane.PlaneType;
import cz.muni.fi.pa165.api.plane.Plane;
import cz.muni.fi.pa165.api.plane.requests.PlaneRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.UUID;
@RestController
@RequiredArgsConstructor
public class PlaneController {
private PlaneFacade planeFacade;
@PostMapping("/plane")
public Plane create(@RequestBody PlaneRequest request) {
return planeFacade.create(request);
}
@GetMapping("/plane/{id}")
public Plane get(@PathVariable UUID id) {
return planeFacade.get(id);
}
@PutMapping("/plane/{id}")
public Plane updateName(@PathVariable UUID id, @RequestParam String name) {
return planeFacade.updateName(id, name);
}
@GetMapping("/plane/type")
public List<Plane> getByType(@RequestParam PlaneType planeType) {
return planeFacade.getByType(planeType);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment