This project is a RESTful API built using Java Spring Boot framework, aimed at managing flight reservations. It provides both user-facing functionalities, such as booking flights, and administrative functionalities, such as managing flights and users.
The system allows users to search for flights based on departure and arrival points, view details, and make reservations. Admin users have additional privileges, including flight and user management.
- Flight: Represents a scheduled trip from a departure airport to an arrival airport.
- Booking: Represents a reservation for a particular flight made by a user.
These are the core components around which the system revolves.
- Java 17: Programming language
- Spring Boot: Framework for creating RESTful APIs
- Spring Data JPA: Data access framework
- Spring Security: Security framework
- Maven: Dependency management
- JUnit 5: Testing framework
- Mockito: Mocking framework
- PostgreSQL: Database
- Docker: Containerization
- Swagger: API documentation
- JWT: Security mechanism for user authentication
- GitHub Actions: CI/CD pipeline
Field | Type | Description |
---|---|---|
id | Long | Primary Key |
name | String | User's name |
String (Unique) | User's email | |
phoneNumber | String | Contact number |
password | String | Hashed password |
role | Enum (ADMIN, USER) | User's role |
Field | Type | Description |
---|---|---|
id | Long | Primary Key |
flightNumber | String | Flight identifier |
capacity | Integer | Available seats |
departureAirport | String | Departure airport code |
arrivalAirport | String | Arrival airport code |
departureDate | LocalDateTime | Scheduled departure |
arrivalDate | LocalDateTime | Scheduled arrival |
price | Decimal (10, 2) | Flight cost |
Field | Type | Description |
---|---|---|
id | Long | Primary Key |
bookingNumber | String | Unique booking identifier |
userId | Long | References User(id) |
flightId | Long | References Flight(id) |
This project uses GitHub Actions for continuous integration and delivery. The workflow can be found in the .github/workflows/app.yml
file.
The CI/CD pipeline consists of two jobs:
- Triggered on pushes or pull requests to the main branch.
- Sets up a PostgreSQL database for testing.
- Builds the project using Maven, caching dependencies.
- Archives the JAR artifact if the build is successful.
- Runs after the build job is successful.
- Sets up a PostgreSQL database for integration testing.
- Runs unit and integration tests.
- Archives test reports for review.
-
Install Docker and Docker Compose on your machine.
-
In the project root directory, run the following command to start the application:
docker-compose up
-
To stop the application, use:
docker-compose down
-
The application will be accessible at
http://localhost:8080
. -
The Swagger documentation will be available at
http://localhost:8080/swagger-ui.html
.
-
Install Java 8+ and Maven on your machine.
-
Set up a PostgreSQL database and update the
application.properties
file with the connection details. -
Run the following command in the project root directory:
mvn spring-boot:run
-
The application will be accessible at
http://localhost:8080
. -
The Swagger documentation will be available at
http://localhost:8080/swagger-ui.html
.
POST /api/users/register
: Register a new user.POST /api/users/login
: Log in and retrieve a JWT token.POST /api/bookings/create
: Create a new flight booking.GET /api/flights/search
: Search for flights by departure and arrival airports.
POST /api/flights/addFlights
: Add a new flight.PUT /api/flights/{id}
: Update the details of a flight by its ID.DELETE /api/flights/{id}
: Remove a flight by its ID.GET /api/users/{id}
: Retrieve the details of a user by their ID.GET /api/users
: Retrieve all users.GET /api/bookings
: Retrieve all bookings.
- URL:
GET /api/flights/search?departure=IST&arrival=AMS&date=2024-07-15
- Method:
GET
[
{
"id": 1,
"flightNumber": "TK1985",
"capacity": 250,
"departureAirport": "IST",
"arrivalAirport": "AMS",
"departureDate": "2024-07-15T10:30:00",
"arrivalDate": "2024-07-15T13:45:00",
"price": 750.0
},
{
"id": 2,
"flightNumber": "TK1986",
"capacity": 210,
"departureAirport": "IST",
"arrivalAirport": "AMS",
"departureDate": "2024-07-15T18:00:00",
"arrivalDate": "2024-07-15T21:15:00",
"price": 820.0
}
]
- URL:
POST /api/bookings/create
- Method:
POST
- Request Body: JSON
- Example:
{ "flightNumber": 1, "passengerName": "John Doe", "passengerEmail": "[email protected]", "passengerPhone": "+1234567890" }
- Response Body: JSON
{ "id": 123, "bookingNumber": "BN456", "userId": 1, "flightId": 1, "passengerName": "John Doe", "passengerEmail": "[email protected]", "passengerPhone": "+1234567890" }
The API documentation is available at http://localhost:8080/swagger-ui/index.html.