Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RaminMammadzada/c869196099d16416ccafe338e7009e73 to your computer and use it in GitHub Desktop.
Save RaminMammadzada/c869196099d16416ccafe338e7009e73 to your computer and use it in GitHub Desktop.
Sample Project: Flight Booking System API

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:

  1. Initialize a new Spring Boot project using Spring Initializr. Choose the following dependencies: Web, JPA, H2, and Lombok.

  2. Structure your project with the following packages:

    • model: Contains domain model classes (Flight, Passenger, Booking)
    • repository: Contains repository interfaces extending JpaRepository
    • service: Contains service classes to encapsulate business logic
    • controller: Contains REST API controllers
    • exception: Contains custom exception classes
    • dto: Contains data transfer objects (DTOs) used in the API
  3. Implement the domain model:

    • Flight class: Fields should include id, flightNumber, departure, destination, departureTime, arrivalTime, capacity, and a list of Booking relationships (OneToMany)
    • Passenger class: Fields should include id, name, email, phone, and a list of Booking relationships (OneToMany)
    • Booking class: Fields should include id, bookingDate, status, a Flight relationship (ManyToOne), and a Passenger relationship (ManyToOne)
  4. Implement the repositories:

    • FlightRepository: Extends JpaRepository<Flight, Long>
    • PassengerRepository: Extends JpaRepository<Passenger, Long>
    • BookingRepository: Extends JpaRepository<Booking, Long>
  5. Implement the services:

    • FlightService: Contains methods for creating, updating, deleting, and retrieving flights
    • PassengerService: Contains methods for creating, updating, deleting, and retrieving passengers
    • BookingService: Contains methods for creating, deleting, and retrieving bookings, as well as a method for booking a flight
  6. Implement the REST API controllers:

    • FlightController: Handles HTTP requests for CRUD operations on flights
    • PassengerController: Handles HTTP requests for CRUD operations on passengers
    • BookingController: Handles HTTP requests for booking operations
  7. Implement DTOs for the API:

    • FlightDTO: Contains fields for id, flightNumber, departure, destination, departureTime, arrivalTime, capacity
    • PassengerDTO: Contains fields for id, name, email, phone
    • BookingDTO: Contains fields for id, bookingDate, status, a FlightDTO, and a PassengerDTO
  8. 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
  9. Configure an H2 in-memory database for the application.

  10. Write unit tests for the service classes using JUnit and Mockito.

  11. (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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment