Flight Search API is a Java project that creates the backend side of a flight search application. This API provides CRUD operations to manage flights and airports and also includes a Search API to list flights that match the given origin, destination, departure date and return date.
The project is written in Java(version 21) and developed using the Spring Boot(version 3.2.1) framework. MySQL was used as the database.
-
Controller Layer: For API endpoints.
-
Service Layer: For business logic.
-
Repository Layer: For database access.
-
Entity Layer: Classes to represent database tables.
-
Security Layer: For authentication and authorization.
- Maven
- Spring Boot Starter Web
- Spring Boot Starter Data JPA
- Spring Boot Starter Security
- H2 Database
- MySQL connecter
-
Flight
- id (Long)
- departureAirport (Airport)
- arrivalAirport (Airport)
- departureDateTime (DateTime)
- arrivalDateTime (DateTime)
- price (BigDecimal)
-
Airport
- id (Long)
- city (String)
departureLocation
: Departure locationarrivalLocation
: Arrival locationdepartureDate
: Departure datereturnDate
: Return date (optional)
- Basic CRUD operations are supported for flights.
- Basic CRUD operations are supported for airports.
GET /api/flights/search
-
-one way flight: ?departureCity=""&arrivalCity=""&departureDate=yyyy-mm-dd: Retrieve one-way flights according to filters. -two way flight: ?departureCity=""&arrivalCity=""&departureDate=yyyy-mm-dd&returnDate=yyyy-mm-dd: Retrieve two-way flights according to filter
- Secure hashing of data using the HMAC algorithm was used to verify user identity.
- localhost:8080/login
- username and password
- The API uses JWT for authentication. Include the obtained JWT token in the Authorization header for secured endpoints.
- In Postman,
- POST -> localhost:8080/login -> Body ->
- enter username and password -> send
- created -> JWT token -> copy
- GET -> http://localhost:8080/search?departureCity=Istanbul&arrivalCity=Ankara&departureDate=2023-12-24T08:00:00&returnDate=2023-12-24T12:00:00
- Headers-> select the paste value Bearer token in the authorization tab -> send
- POST -> localhost:8080/login -> Body ->
- In Postman,
A background job running daily at a specific time (for now every 60 seconds)retrieves flight information from a third-party API and stores it in the database.
Mock data is generated by making a mock API request.(-StartupRunner.java)
- Clone the project: git clone https://github.com/gamzegenc99/FlightSearchAPI.git
- Navigate to the project directory: cd FlightSearchAPI
- Run the application: ./mvnw spring-boot:run
- Access Swagger documentation in the browser: http://localhost:8080/swagger-ui.html
- Java version 21, If you want to change it according to the version on your computer, you can change it from pom.xml.
- Credential for login: username : username , password : password
- If MySQL is not installed on your computer you can use H2 database, resources -> application.properties put MySQL in the comment line and remove the H2 database from the comment line.