Project: Flight Booking System API
Objective: Implement a RESTful API for a Flight Booking System using Java and Spring Boot. The API should allow users to perform CRUD (Create, Read, Update, Delete) operations on flights and passengers and to book flights.
Requirements:
-
Initialize a new Spring Boot project using Spring Initializr. Choose the following dependencies: Web, JPA, H2, and Lombok.
-
Structure your project with the following packages:
model
: Contains domain model classes (Flight
,Passenger
,Booking
)repository
: Contains repository interfaces extendingJpaRepository
service
: Contains service classes to encapsulate business logiccontroller
: Contains REST API controllersexception
: Contains custom exception classesdto
: Contains data transfer objects (DTOs) used in the API
-
Implement the domain model:
Flight
class: Fields should includeid
,flightNumber
,departure
,destination
,departureTime
,arrivalTime
,capacity
, and a list ofBooking
relationships (OneToMany)Passenger
class: Fields should includeid
,name
,email
,phone
, and a list ofBooking
relationships (OneToMany)Booking
class: Fields should includeid
,bookingDate
,status
, aFlight
relationship (ManyToOne), and aPassenger
relationship (ManyToOne)
-
Implement the repositories:
FlightRepository
: ExtendsJpaRepository<Flight, Long>
PassengerRepository
: ExtendsJpaRepository<Passenger, Long>
BookingRepository
: ExtendsJpaRepository<Booking, Long>
-
Implement the services:
FlightService
: Contains methods for creating, updating, deleting, and retrieving flightsPassengerService
: Contains methods for creating, updating, deleting, and retrieving passengersBookingService
: Contains methods for creating, deleting, and retrieving bookings, as well as a method for booking a flight
-
Implement the REST API controllers:
FlightController
: Handles HTTP requests for CRUD operations on flightsPassengerController
: Handles HTTP requests for CRUD operations on passengersBookingController
: Handles HTTP requests for booking operations
-
Implement DTOs for the API:
FlightDTO
: Contains fields forid
,flightNumber
,departure
,destination
,departureTime
,arrivalTime
,capacity
PassengerDTO
: Contains fields forid
,name
,email
,phone
BookingDTO
: Contains fields forid
,bookingDate
,status
, aFlightDTO
, and aPassengerDTO
-
Implement exception handling:
- Create custom exceptions (
ResourceNotFoundException
,BadRequestException
) - Implement a global exception handler with
@ControllerAdvice
to handle exceptions and return appropriate HTTP response status codes
- Create custom exceptions (
-
Configure an H2 in-memory database for the application.
-
Write unit tests for the service classes using JUnit and Mockito.
-
(Optional) Implement API documentation using Swagger or OpenAPI.
Deliverables:
- A fully functional Spring Boot project, including source code and tests
- A README file with instructions on how to build and run the project, as well as an explanation of any design decisions you made
When you submit your project, please include all necessary files in a