diff --git a/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneController.java b/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneController.java new file mode 100644 index 0000000000000000000000000000000000000000..143e24e85c08429f18855594d6c14d3004f69c7c --- /dev/null +++ b/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneController.java @@ -0,0 +1,123 @@ +package cz.muni.fi.pa165.core.rest; + +import cz.muni.fi.pa165.core.api.AirplaneApi; +import cz.muni.fi.pa165.core.api.AirplaneApiDelegate; +import cz.muni.fi.pa165.core.model.AirplaneDto; +import cz.muni.fi.pa165.core.model.NewAirplaneDtoRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class AirplaneController implements AirplaneApiDelegate { + + /** + * POST /api/airplanes/{airplaneId}/airplaneTypes/{airplaneTypeId} : Assign airplane type to a airplane. + * + * @param airplaneId (required) + * @param airplaneTypeId (required) + * @return OK (status code 201) + * or Input data not correct (status code 400) + * @see AirplaneApi#assignAirplaneType + */ + @Override + public ResponseEntity<AirplaneDto> assignAirplaneType(Long airplaneId, Long airplaneTypeId) { + return AirplaneApiDelegate.super.assignAirplaneType(airplaneId, airplaneTypeId); + } + + /** + * POST /api/airplanes : Create a new airplane. + * Creates a new airplane and returns it as a response. + * + * @param newAirplaneDtoRequest (required) + * @return Created (status code 201) + * or Input data not correct (status code 400) + * @see AirplaneApi#createAirplane + */ + @Override + public ResponseEntity<AirplaneDto> createAirplane(NewAirplaneDtoRequest newAirplaneDtoRequest) { + return AirplaneApiDelegate.super.createAirplane(newAirplaneDtoRequest); + } + + /** + * DELETE /api/airplanes/{id} : Delete airplane by id. + * + * @param id (required) + * @return Deleted (status code 204) + * or Not Found (status code 404) + * @see AirplaneApi#deleteAirplane + */ + @Override + public ResponseEntity<Void> deleteAirplane(Long id) { + return AirplaneApiDelegate.super.deleteAirplane(id); + } + + /** + * DELETE /api/airplanes/{airplaneId}/airplaneTypes/{airplaneTypeId} : Delete assignment of airplane type to an airplane. + * + * @param airplaneId (required) + * @param airplaneTypeId (required) + * @return Deleted (status code 204) + * or Not Found (status code 404) + * @see AirplaneApi#deleteAirplaneTypeAssignment + */ + @Override + public ResponseEntity<Void> deleteAirplaneTypeAssignment(Long airplaneId, Long airplaneTypeId) { + return AirplaneApiDelegate.super.deleteAirplaneTypeAssignment(airplaneId, airplaneTypeId); + } + + /** + * GET /api/airplanes/{id} : Get airplane by id. + * Returns an object representing an airplane. + * + * @param id (required) + * @return OK (status code 200) + * @see AirplaneApi#getAirplaneById + */ + @Override + public ResponseEntity<AirplaneDto> getAirplaneById(Long id) { + return AirplaneApiDelegate.super.getAirplaneById(id); + } + + /** + * GET /api/airplanes : Get all airplanes. + * Returns an array of objects representing airplanes. + * + * @return OK (status code 200) + * @see AirplaneApi#getAllAirplanes + */ + @Override + public ResponseEntity<List<AirplaneDto>> getAllAirplanes() { + return AirplaneApiDelegate.super.getAllAirplanes(); + } + + /** + * PUT /api/airplanes/{id} : Update airplane by id. + * Updates a airplane by id and returns it as a response. + * + * @param id (required) + * @param airplaneDto (required) + * @return OK (status code 200) + * or Input data not correct (status code 400) + * @see AirplaneApi#updateAirplane + */ + @Override + public ResponseEntity<AirplaneDto> updateAirplane(Long id, AirplaneDto airplaneDto) { + return AirplaneApiDelegate.super.updateAirplane(id, airplaneDto); + } + + /** + * PUT /api/airplanes/{airplaneId}/airplaneTypes/{airplaneTypeId} : Update assignment of airplane type to an airplane. + * + * @param airplaneId (required) + * @param airplaneTypeId (required) + * @return OK (status code 200) + * or Input data not correct (status code 400) + * @see AirplaneApi#updateAirplaneTypeAssignment + */ + @Override + public ResponseEntity<AirplaneDto> updateAirplaneTypeAssignment(Long airplaneId, Long airplaneTypeId) { + return AirplaneApiDelegate.super.updateAirplaneTypeAssignment(airplaneId, airplaneTypeId); + } +} diff --git a/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneTypeController.java b/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneTypeController.java index 80dc006f85f3164844056f2fe674b0cfc0e9d26b..86419eaf19d9b606fc2a198fd9cac46bf29def19 100644 --- a/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneTypeController.java +++ b/core/src/main/java/cz/muni/fi/pa165/core/rest/AirplaneTypeController.java @@ -1,7 +1,9 @@ package cz.muni.fi.pa165.core.rest; +import cz.muni.fi.pa165.core.api.AirplaneTypeApi; import cz.muni.fi.pa165.core.api.AirplaneTypeApiDelegate; import cz.muni.fi.pa165.core.model.AirplaneTypeDto; +import cz.muni.fi.pa165.core.model.NewAirplaneTypeDtoRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -10,26 +12,68 @@ import java.util.List; @RestController public class AirplaneTypeController implements AirplaneTypeApiDelegate { + /** + * POST /api/airplaneTypes : Create a new airplane type. + * Creates a new airplane type and returns it as a response. + * + * @param newAirplaneTypeDtoRequest (required) + * @return Created (status code 201) + * or Input data not correct (status code 400) + * @see AirplaneTypeApi#createAirplaneType + */ @Override - public ResponseEntity<AirplaneTypeDto> createAirplaneType(AirplaneTypeDto airplaneTypeDto) { - return AirplaneTypeApiDelegate.super.createAirplaneType(airplaneTypeDto); + public ResponseEntity<AirplaneTypeDto> createAirplaneType(NewAirplaneTypeDtoRequest newAirplaneTypeDtoRequest) { + return AirplaneTypeApiDelegate.super.createAirplaneType(newAirplaneTypeDtoRequest); } + /** + * DELETE /api/airplaneTypes/{id} : Delete airplane type by id. + * + * @param id (required) + * @return Deleted (status code 204) + * or Not Found (status code 404) + * @see AirplaneTypeApi#deleteAirplaneType + */ @Override public ResponseEntity<Void> deleteAirplaneType(Long id) { return AirplaneTypeApiDelegate.super.deleteAirplaneType(id); } + /** + * GET /api/airplaneTypes/{id} : Get airplane type by id. + * Returns an object representing an airplane type. + * + * @param id (required) + * @return OK (status code 200) + * @see AirplaneTypeApi#getAirplaneTypeById + */ @Override public ResponseEntity<AirplaneTypeDto> getAirplaneTypeById(Long id) { return AirplaneTypeApiDelegate.super.getAirplaneTypeById(id); } + /** + * GET /api/airplaneTypes : Get all airplane types. + * Returns an array of objects representing airplane types. + * + * @return OK (status code 200) + * @see AirplaneTypeApi#getAllAirplaneTypes + */ @Override public ResponseEntity<List<AirplaneTypeDto>> getAllAirplaneTypes() { return AirplaneTypeApiDelegate.super.getAllAirplaneTypes(); } + /** + * PUT /api/airplaneTypes/{id} : Update airplane type by id. + * Updates a airplane type by id and returns it as a response. + * + * @param id (required) + * @param airplaneTypeDto (required) + * @return OK (status code 200) + * or Input data not correct (status code 400) + * @see AirplaneTypeApi#updateAirplaneType + */ @Override public ResponseEntity<AirplaneTypeDto> updateAirplaneType(Long id, AirplaneTypeDto airplaneTypeDto) { return AirplaneTypeApiDelegate.super.updateAirplaneType(id, airplaneTypeDto); diff --git a/core/src/main/java/cz/muni/fi/pa165/core/rest/FlightController.java b/core/src/main/java/cz/muni/fi/pa165/core/rest/FlightController.java index a36c47cc094fca0af97d767f079a3581e65d6d29..f36ad554b1f3791375a6337663f1338c6a589b06 100644 --- a/core/src/main/java/cz/muni/fi/pa165/core/rest/FlightController.java +++ b/core/src/main/java/cz/muni/fi/pa165/core/rest/FlightController.java @@ -1,41 +1,79 @@ package cz.muni.fi.pa165.core.rest; +import cz.muni.fi.pa165.core.api.FlightApi; import cz.muni.fi.pa165.core.api.FlightApiDelegate; import cz.muni.fi.pa165.core.model.FlightDto; import cz.muni.fi.pa165.core.model.NewFlightDtoRequest; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; @RestController public class FlightController implements FlightApiDelegate { - private final List<FlightDto> flightDtos = new CopyOnWriteArrayList<>(); - - @Override - public ResponseEntity<List<FlightDto>> getAllFlights() { - flightDtos.add(new FlightDto().id(1L)); - return new ResponseEntity<>(flightDtos, HttpStatus.OK); - } - + /** + * POST /api/flights : Create a new flight. + * Creates a new flight and returns it as a response. + * + * @param newFlightDtoRequest (required) + * @return Created (status code 201) + * or Input data not correct (status code 400) + * @see FlightApi#createFlight + */ @Override public ResponseEntity<FlightDto> createFlight(NewFlightDtoRequest newFlightDtoRequest) { return FlightApiDelegate.super.createFlight(newFlightDtoRequest); } + /** + * DELETE /api/flights/{id} : Delete flight by id. + * + * @param id (required) + * @return Deleted (status code 204) + * or Not Found (status code 404) + * @see FlightApi#deleteFlight + */ @Override public ResponseEntity<Void> deleteFlight(Long id) { return FlightApiDelegate.super.deleteFlight(id); } + /** + * GET /api/flights : Get all flights. + * Returns an array of objects representing flights. + * + * @return OK (status code 200) + * @see FlightApi#getAllFlights + */ + @Override + public ResponseEntity<List<FlightDto>> getAllFlights() { + return FlightApiDelegate.super.getAllFlights(); + } + + /** + * GET /api/flights/{id} : Get flight by id. + * Returns an object representing a flight. + * + * @param id (required) + * @return OK (status code 200) + * @see FlightApi#getFlightById + */ @Override public ResponseEntity<FlightDto> getFlightById(Long id) { return FlightApiDelegate.super.getFlightById(id); } + /** + * PUT /api/flights/{id} : Update flight by id. + * Updates a flight by id and returns it as a response. + * + * @param id (required) + * @param newFlightDtoRequest (required) + * @return OK (status code 200) + * or Input data not correct (status code 400) + * @see FlightApi#updateFlight + */ @Override public ResponseEntity<FlightDto> updateFlight(Long id, NewFlightDtoRequest newFlightDtoRequest) { return FlightApiDelegate.super.updateFlight(id, newFlightDtoRequest); diff --git a/core/src/main/java/cz/muni/fi/pa165/core/rest/StewardController.java b/core/src/main/java/cz/muni/fi/pa165/core/rest/StewardController.java index 931e16f2c0fd9c414580e232b44c15a0a15e2db6..c24bdc0a7bdc783ec10b4ad1d29f686983f8f842 100644 --- a/core/src/main/java/cz/muni/fi/pa165/core/rest/StewardController.java +++ b/core/src/main/java/cz/muni/fi/pa165/core/rest/StewardController.java @@ -1,98 +1,136 @@ package cz.muni.fi.pa165.core.rest; +import cz.muni.fi.pa165.core.api.StewardApi; import cz.muni.fi.pa165.core.api.StewardApiDelegate; import cz.muni.fi.pa165.core.model.*; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; @RestController public class StewardController implements StewardApiDelegate { - private final List<StewardDto> stewardDtos = new CopyOnWriteArrayList<>(); - + /** + * POST /api/stewards : Create a new steward. + * Creates a new steward and returns it as a response. + * + * @param newStewardDtoRequest (required) + * @return Response containing a single Steward. (status code 201) + * or Input data not correct (status code 400) + * @see StewardApi#createSteward + */ @Override - public ResponseEntity<List<StewardDto>> getAllStewards() { - stewardDtos.add(new StewardDto().id(1L).firstName("John").lastName("Doe")); - return new ResponseEntity<>(stewardDtos, HttpStatus.OK); + public ResponseEntity<StewardDto> createSteward(NewStewardDtoRequest newStewardDtoRequest) { + return StewardApiDelegate.super.createSteward(newStewardDtoRequest); } + /** + * POST /api/stewards/{stewardId}/flights/{flightId} : Assign steward to a flight. + * + * @param stewardId (required) + * @param flightId (required) + * @return Response containing a single Steward. (status code 201) + * or Input data not correct (status code 400) + * @see StewardApi#createStewardFlights + */ @Override - public ResponseEntity<StewardDto> getSteward(Long id) { - var stewardDto = stewardDtos - .stream() - .filter(x -> x.getId().equals(id)) - .findFirst() - .orElse(null); - - return new ResponseEntity<>(stewardDto, stewardDto != null ? HttpStatus.OK : HttpStatus.NOT_FOUND); + public ResponseEntity<StewardDto> createStewardFlights(Long stewardId, Long flightId) { + return StewardApiDelegate.super.createStewardFlights(stewardId, flightId); } + /** + * DELETE /api/stewards/{id} : Delete steward by id. + * + * @param id (required) + * @return Deleted (status code 204) + * or Not Found (status code 404) + * @see StewardApi#deleteSteward + */ @Override - public ResponseEntity<PageStewardDto> getStewardsPaged(Integer page, Integer size, List<String> sort) { - var pageRequest = PageRequest.of(page, size); - var stewards = stewardDtos.stream().skip(pageRequest.getOffset()).limit(pageRequest.getPageSize()).toList(); - var result = new PageImpl<>(stewards, pageRequest, stewardDtos.size()); - - var s = new SortObject() - .sorted(pageRequest.getSort().isSorted()) - .unsorted(pageRequest.getSort().isUnsorted()) - .empty(pageRequest.getSort().isEmpty()); - - var pageableObject = new PageableObject() - .paged(pageRequest.isPaged()) - .unpaged(pageRequest.isUnpaged()) - .pageNumber(pageRequest.getPageNumber()) - .pageSize(pageRequest.getPageSize()) - .sort(s) - .offset(pageRequest.getOffset()); - - var pageStewardDto = new PageStewardDto() - .content(stewards) - .pageable(pageableObject) - .last(result.isLast()) - .first(result.isFirst()) - .empty(result.isEmpty()) - .totalPages(result.getTotalPages()) - .totalElements(result.getTotalElements()) - .number(result.getNumber()) - .numberOfElements(result.getNumberOfElements()) - .size(result.getSize()) - .sort(s); - - return new ResponseEntity<>(pageStewardDto, HttpStatus.OK); + public ResponseEntity<Void> deleteSteward(Long id) { + return StewardApiDelegate.super.deleteSteward(id); } + /** + * DELETE /api/stewards/{stewardId}/flights/{flightId} : Delete assignment of steward to a flight. + * + * @param stewardId (required) + * @param flightId (required) + * @return Deleted (status code 204) + * or Not Found (status code 404) + * @see StewardApi#deleteStewardFlights + */ @Override - public ResponseEntity<StewardDto> createSteward(NewStewardDtoRequest newStewardDtoRequest) { - return StewardApiDelegate.super.createSteward(newStewardDtoRequest); + public ResponseEntity<Void> deleteStewardFlights(Long stewardId, Long flightId) { + return StewardApiDelegate.super.deleteStewardFlights(stewardId, flightId); } + /** + * GET /api/stewards : Get all stewards. + * Returns an array of objects representing stewards. + * + * @return OK (status code 200) + * @see StewardApi#getAllStewards + */ @Override - public ResponseEntity<Void> deleteSteward(Long id) { - return StewardApiDelegate.super.deleteSteward(id); + public ResponseEntity<List<StewardDto>> getAllStewards() { + return StewardApiDelegate.super.getAllStewards(); } + /** + * GET /api/stewards/{id} : Get steward by id + * Returns a steward by id. + * + * @param id (required) + * @return OK (status code 200) + * or Not Found (status code 404) + * @see StewardApi#getSteward + */ @Override - public ResponseEntity<StewardDto> createStewardFlights(Long stewardId, Long flightId) { - return StewardApiDelegate.super.createStewardFlights(stewardId, flightId); + public ResponseEntity<StewardDto> getSteward(Long id) { + return StewardApiDelegate.super.getSteward(id); } + /** + * GET /api/stewards/paged : Paged stewards + * Returns a page of stewards. The parameter `page` specifies zero-based index of the requested page, and the parameter `size` specifies the size of the page. + * + * @param page Zero-based page index (0..N) (optional, default to 0) + * @param size The size of the page to be returned (optional, default to 20) + * @param sort Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported. (optional) + * @return OK (status code 200) + * @see StewardApi#getStewardsPaged + */ @Override - public ResponseEntity<Void> deleteStewardFlights(Long stewardId, Long flightId) { - return StewardApiDelegate.super.deleteStewardFlights(stewardId, flightId); + public ResponseEntity<PageStewardDto> getStewardsPaged(Integer page, Integer size, List<String> sort) { + return StewardApiDelegate.super.getStewardsPaged(page, size, sort); } + /** + * PUT /api/stewards/{id} : Update steward by id. + * Updates a steward by id and returns it as a response. + * + * @param id (required) + * @param newStewardDtoRequest (required) + * @return Response containing a single Steward. (status code 200) + * or Input data not correct (status code 400) + * @see StewardApi#updateSteward + */ @Override public ResponseEntity<StewardDto> updateSteward(Long id, NewStewardDtoRequest newStewardDtoRequest) { return StewardApiDelegate.super.updateSteward(id, newStewardDtoRequest); } + /** + * PUT /api/stewards/{stewardId}/flights/{flightId} : Update assignment of steward to a flight. + * + * @param stewardId (required) + * @param flightId (required) + * @return Response containing a single Steward. (status code 200) + * or Input data not correct (status code 400) + * @see StewardApi#updateStewardFlights + */ @Override public ResponseEntity<StewardDto> updateStewardFlights(Long stewardId, Long flightId) { return StewardApiDelegate.super.updateStewardFlights(stewardId, flightId); diff --git a/openapi.yaml b/openapi.yaml index fd5f17b13a2fddbd06e7dee3c5807f54f7f1ef8c..e21229b413b03ce1b9be847584978e38f87fb5f4 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -414,7 +414,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/AirplaneTypeDto' + $ref: '#/components/schemas/NewAirplaneTypeDtoRequest' required: true responses: "201": @@ -503,6 +503,211 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorMessage' + /api/airplanes: + get: + tags: + - Airplane + summary: Get all airplanes. + description: Returns an array of objects representing airplanes. + operationId: getAllAirplanes + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/AirplaneDto' + post: + tags: + - Airplane + summary: Create a new airplane. + description: Creates a new airplane and returns it as a response. + operationId: createAirplane + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/NewAirplaneDtoRequest' + required: true + responses: + "201": + description: Created + content: + application/json: + schema: + $ref: '#/components/schemas/AirplaneDto' + "400": + description: Input data not correct + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage' + /api/airplanes/{id}: + get: + tags: + - Airplane + summary: Get airplane by id. + description: Returns an object representing an airplane. + operationId: getAirplaneById + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AirplaneDto' + delete: + tags: + - Airplane + summary: Delete airplane by id. + operationId: deleteAirplane + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + responses: + "204": + description: Deleted + "404": + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage' + put: + tags: + - Airplane + summary: Update airplane by id. + operationId: updateAirplane + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + description: Updates a airplane by id and returns it as a response. + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AirplaneDto' + required: true + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AirplaneDto' + "400": + description: Input data not correct + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage' + /api/airplanes/{airplaneId}/airplaneTypes/{airplaneTypeId}: + post: + tags: + - Airplane + summary: Assign airplane type to a airplane. + operationId: assignAirplaneType + parameters: + - name: airplaneId + in: path + required: true + schema: + type: integer + format: int64 + - name: airplaneTypeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "201": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AirplaneDto' + "400": + description: Input data not correct + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage' + put: + tags: + - Airplane + summary: Update assignment of airplane type to an airplane. + operationId: updateAirplaneTypeAssignment + parameters: + - name: airplaneId + in: path + required: true + schema: + type: integer + format: int64 + - name: airplaneTypeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/AirplaneDto' + "400": + description: Input data not correct + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage' + delete: + tags: + - Airplane + summary: Delete assignment of airplane type to an airplane. + operationId: deleteAirplaneTypeAssignment + parameters: + - name: airplaneId + in: path + required: true + schema: + type: integer + format: int64 + - name: airplaneTypeId + in: path + required: true + schema: + type: integer + format: int64 + responses: + "204": + description: Deleted + "404": + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage' components: schemas: DomainEntity: @@ -650,6 +855,17 @@ components: type: string description: airplane type name example: Boeing 747 + NewAirplaneTypeDtoRequest: + type: object + title: New Airplane Type Request + description: Object for requesting a new Airplane Type. + required: + - name + properties: + name: + type: string + description: airplane type name + example: Boeing 747 AirplaneDto: allOf: - $ref: '#/components/schemas/DomainEntity' @@ -673,6 +889,23 @@ components: example: 150 type: $ref: '#/components/schemas/AirplaneTypeDto' + NewAirplaneDtoRequest: + type: object + title: New Airplane Request + description: Object for requesting a new Airplane. + required: + - name + - capacity + properties: + name: + type: string + description: airplane name + example: Spitfire + capacity: + type: integer + description: airplane seat capacity + format: int32 + example: 150 PageableObject: type: object title: Pageable Object