-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/AliRizaAynaci/flight-reserv…
- Loading branch information
Showing
23 changed files
with
469 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Flight Reservation CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: flightreservation | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Cache Maven dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.m2/repository | ||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Build with Maven | ||
run: mvn -B clean package | ||
- name: Archive Production Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: package | ||
path: target/*.jar | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: flightreservation | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Cache Maven dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.m2/repository | ||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Run Tests with Maven | ||
run: mvn -B verify | ||
- name: Archive Test Reports | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-reports | ||
path: target/surefire-reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM openjdk:17-jdk-slim AS build | ||
|
||
COPY pom.xml mvnw ./ | ||
COPY .mvn .mvn | ||
RUN ./mvnw dependency:resolve | ||
|
||
COPY src src | ||
RUN ./mvnw package -DskipTests | ||
|
||
FROM openjdk:17-jdk-slim | ||
WORKDIR /flightreservation | ||
COPY --from=build target/*.jar flightreservation.jar | ||
|
||
ENTRYPOINT ["java", "-jar", "flightreservation.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: '3.9' | ||
|
||
services: | ||
app: | ||
image: 'flightreservation' | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
container_name: flightreservation | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/flightreservation | ||
- SPRING_DATASOURCE_USERNAME=postgres | ||
- SPRING_DATASOURCE_PASSWORD=password | ||
depends_on: | ||
- db | ||
|
||
db: | ||
image: postgres:13-alpine | ||
container_name: postgres | ||
environment: | ||
- POSTGRES_DB=flightreservation | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=password | ||
- POSTGRES_HOST_AUTH_METHOD=trust |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/flightreservation/controller/BookingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.flightreservation.controller; | ||
|
||
import com.flightreservation.dto.BookingCreateDTO; | ||
import com.flightreservation.dto.BookingDTO; | ||
import com.flightreservation.exception.BusinessRuleException; | ||
import com.flightreservation.exception.FlightNotFoundException; | ||
import com.flightreservation.exception.UserNotFoundException; | ||
import com.flightreservation.service.BookingService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/bookings") | ||
public class BookingController { | ||
|
||
private final BookingService bookingService; | ||
|
||
public BookingController(BookingService bookingService) { | ||
this.bookingService = bookingService; | ||
} | ||
|
||
@PostMapping("/create") | ||
public ResponseEntity<BookingDTO> createBooking(@RequestBody BookingCreateDTO bookingCreateDTO) { | ||
try { | ||
BookingDTO booking = bookingService.createBooking(bookingCreateDTO); | ||
return ResponseEntity.ok(booking); | ||
} catch (FlightNotFoundException | UserNotFoundException | BusinessRuleException e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); | ||
} | ||
} | ||
|
||
@PreAuthorize("hasRole('ADMIN')") | ||
@GetMapping | ||
public ResponseEntity<List<BookingDTO>> getAllBookings() { | ||
List<BookingDTO> bookings = bookingService.getAllBookings(); | ||
return ResponseEntity.ok(bookings); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/flightreservation/controller/FlightController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.flightreservation.controller; | ||
|
||
import com.flightreservation.dto.FlightDTO; | ||
import com.flightreservation.model.entity.Flight; | ||
import com.flightreservation.service.FlightService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/flights") | ||
public class FlightController { | ||
|
||
private final FlightService flightService; | ||
|
||
public FlightController(FlightService flightService) { | ||
this.flightService = flightService; | ||
} | ||
|
||
@GetMapping("/search") | ||
public ResponseEntity<List<FlightDTO>> searchFlights(@RequestParam("departure") String departureAirport, | ||
@RequestParam("arrival") String arrivalAirport) { | ||
List<FlightDTO> flights = flightService.searchFlights(departureAirport, arrivalAirport); | ||
return ResponseEntity.ok(flights); | ||
} | ||
|
||
@PreAuthorize("hasRole('ADMIN')") | ||
@PostMapping("/addFlights") | ||
public ResponseEntity<Flight> addFlight(@RequestBody FlightDTO flightDTO) { | ||
Flight flight = flightService.addFlight(flightDTO); | ||
return ResponseEntity.ok(flight); | ||
} | ||
|
||
@PreAuthorize("hasRole('ADMIN')") | ||
@PutMapping("/{id}") | ||
public ResponseEntity<Flight> updateFlight(@PathVariable Long id, @RequestBody FlightDTO flightDTO) { | ||
Flight flight = flightService.updateFlight(id, flightDTO); | ||
return ResponseEntity.ok(flight); | ||
} | ||
|
||
@PreAuthorize("hasRole('ADMIN')") | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<String> deleteFlight(@PathVariable Long id) { | ||
flightService.deleteFlight(id); | ||
return ResponseEntity.ok("Flight with id " + id + " has been successfully deleted."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/flightreservation/exception/BookingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.flightreservation.exception; | ||
|
||
public class BookingException extends RuntimeException { | ||
|
||
public BookingException(String s) { | ||
super(s); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/flightreservation/exception/FlightNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.flightreservation.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
public class FlightNotFoundException extends RuntimeException { | ||
|
||
public FlightNotFoundException(String s) { | ||
super(s); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/flightreservation/exception/UserNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.flightreservation.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
public class UserNotFoundException extends RuntimeException { | ||
|
||
public UserNotFoundException(String s) { | ||
super(s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.