From b98e496f97378208b701212e962f5c22b263e85d Mon Sep 17 00:00:00 2001 From: Serhat Acar Date: Sun, 4 Feb 2024 23:26:12 +0300 Subject: [PATCH] Updated minor change --- .github/workflows/qodana_code_quality.yml | 19 +++++++++++ qodana.yaml | 31 ++++++++++++++++++ .../flightsearchapi/entity/Airport.java | 4 +++ .../flightsearchapi/entity/Flight.java | 7 +++- .../repository/AirportRepo.java | 7 ---- .../repository/AirportRepository.java | 12 +++++++ .../repository/FlightRepo.java | 7 ---- .../repository/FlightRepository.java | 12 +++++++ .../FlightsearchapiApplicationTests.java | 32 ++++++++++++++++--- 9 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/qodana_code_quality.yml create mode 100644 qodana.yaml delete mode 100644 src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepo.java create mode 100644 src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepository.java delete mode 100644 src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepo.java create mode 100644 src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepository.java diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml new file mode 100644 index 0000000..682e68e --- /dev/null +++ b/.github/workflows/qodana_code_quality.yml @@ -0,0 +1,19 @@ +name: Qodana +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + +jobs: + qodana: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2023.3 + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} \ No newline at end of file diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000..ebc500e --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,31 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +projectJDK: 21 #(Applied in CI/CD pipeline) + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-jvm:latest diff --git a/src/main/java/com/serhatacar/flightsearchapi/entity/Airport.java b/src/main/java/com/serhatacar/flightsearchapi/entity/Airport.java index e05633f..05740b1 100644 --- a/src/main/java/com/serhatacar/flightsearchapi/entity/Airport.java +++ b/src/main/java/com/serhatacar/flightsearchapi/entity/Airport.java @@ -1,13 +1,17 @@ package com.serhatacar.flightsearchapi.entity; import jakarta.persistence.*; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.time.LocalDateTime; import java.util.List; @Entity @Data +@AllArgsConstructor +@NoArgsConstructor public class Airport { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/serhatacar/flightsearchapi/entity/Flight.java b/src/main/java/com/serhatacar/flightsearchapi/entity/Flight.java index 7481a5b..69372f7 100644 --- a/src/main/java/com/serhatacar/flightsearchapi/entity/Flight.java +++ b/src/main/java/com/serhatacar/flightsearchapi/entity/Flight.java @@ -1,11 +1,16 @@ package com.serhatacar.flightsearchapi.entity; import jakarta.persistence.*; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; + import java.time.LocalDateTime; @Entity @Data +@AllArgsConstructor +@NoArgsConstructor public class Flight { @Id @GeneratedValue (strategy = GenerationType.IDENTITY) @@ -17,6 +22,6 @@ public class Flight { @JoinColumn(name = "arrival_airport_id") private Airport arrivalAirport; private LocalDateTime departureDateTime; - private LocalDateTime returnDateTime; + private LocalDateTime arrivalDateTime; private double price; } \ No newline at end of file diff --git a/src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepo.java b/src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepo.java deleted file mode 100644 index a6f11f5..0000000 --- a/src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepo.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.serhatacar.flightsearchapi.repository; - -import com.serhatacar.flightsearchapi.entity.Airport; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface AirportRepo extends JpaRepository { -} diff --git a/src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepository.java b/src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepository.java new file mode 100644 index 0000000..375a19a --- /dev/null +++ b/src/main/java/com/serhatacar/flightsearchapi/repository/AirportRepository.java @@ -0,0 +1,12 @@ +package com.serhatacar.flightsearchapi.repository; + +import com.serhatacar.flightsearchapi.entity.Airport; +import com.serhatacar.flightsearchapi.entity.Flight; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface AirportRepository extends JpaRepository { + List findAirportsByArrivalFlightsContains(Flight flight); + List findAirportsByDepartureFlightsContains(Flight flight); +} diff --git a/src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepo.java b/src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepo.java deleted file mode 100644 index 64b0d57..0000000 --- a/src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepo.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.serhatacar.flightsearchapi.repository; - -import com.serhatacar.flightsearchapi.entity.Flight; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface FlightRepo extends JpaRepository { -} diff --git a/src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepository.java b/src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepository.java new file mode 100644 index 0000000..e5f998d --- /dev/null +++ b/src/main/java/com/serhatacar/flightsearchapi/repository/FlightRepository.java @@ -0,0 +1,12 @@ +package com.serhatacar.flightsearchapi.repository; + +import com.serhatacar.flightsearchapi.entity.Airport; +import com.serhatacar.flightsearchapi.entity.Flight; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface FlightRepository extends JpaRepository { + List < Flight > findByArrivalAirport(Airport airport); + List < Flight > findByDepartureAirport(Airport airport); +} diff --git a/src/test/java/com/serhatacar/flightsearchapi/FlightsearchapiApplicationTests.java b/src/test/java/com/serhatacar/flightsearchapi/FlightsearchapiApplicationTests.java index 9311487..90f015c 100644 --- a/src/test/java/com/serhatacar/flightsearchapi/FlightsearchapiApplicationTests.java +++ b/src/test/java/com/serhatacar/flightsearchapi/FlightsearchapiApplicationTests.java @@ -1,13 +1,35 @@ package com.serhatacar.flightsearchapi; +import com.serhatacar.flightsearchapi.entity.Flight; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; -@SpringBootTest +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class FlightsearchapiApplicationTests { - @Test - void contextLoads() { - } + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testCreateFlight() { + Flight flight = new Flight(); + flight.setDepartureDateTime(LocalDateTime.now()); + flight.setArrivalDateTime(LocalDateTime.now().plusDays(1)); + flight.setPrice(100.0); + + ResponseEntity response = restTemplate.postForEntity("/flights", flight, Flight.class); + + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + assertEquals(flight.getPrice(), response.getBody().getPrice()); + } + -} +} \ No newline at end of file