Skip to content

Flight Operation service having flight instance and schedules#7

Merged
vikasutf8 merged 12 commits into
dev-workfrom
dev-work-flight-ops
Apr 20, 2026
Merged

Flight Operation service having flight instance and schedules#7
vikasutf8 merged 12 commits into
dev-workfrom
dev-work-flight-ops

Conversation

@vikasutf8
Copy link
Copy Markdown
Owner

@vikasutf8 vikasutf8 commented Apr 20, 2026

Flight Operation service having flight instance and schedules
This pull request introduces the new FlightSchedule feature for flight scheduling, along with supporting entities, requests, and validation logic. It also updates project configuration files to include the new flight-ops-service module and ensures proper IDE and build tool integration.

Flight scheduling feature and supporting entities:

  • Added FlightScheduleRequest DTO with validation logic for scheduling flights, including checks for time and date consistency, unique operating days, and active status.
  • Added FlightInstanceRequest and FlightRequest DTOs to support creation and update operations for flight instances and flights, including field-level validation and status handling. [1] [2]
  • Introduced the FlightStatus enum to standardize flight status values across the application.

Project and IDE configuration:

  • Registered the new flight-ops-service module in .idea/compiler.xml, .idea/encodings.xml, and .idea/misc.xml for proper build, encoding, and Maven integration. [1] [2] [3] [4]
  • Updated .idea/workspace.xml to track new files, tasks, and commit messages related to the flight scheduling feature and the new module. [1] [2] [3] [4] [5] [6]

Summary by Sourcery

Add a new flight-ops-service microservice for managing flights, flight schedules, and flight instances, including REST APIs, persistence models, and supporting DTOs and mappers.

New Features:

  • Introduce Flight, FlightSchedule, and FlightInstance domain entities with JPA mappings and audit fields for flight operations.
  • Add REST controllers and services to create, update, delete, and query flights, flight instances, and flight schedules with basic business rules and validations.
  • Provide request/response DTOs and mapping utilities for flights, flight instances, and flight schedules, along with a shared FlightStatus enum.

Enhancements:

  • Register the new flight-ops-service module in the services Maven aggregator and wire it with common-lib for shared types.
  • Add Maven wrapper, build configuration, and minimal application bootstrap for the new flight-ops-service module.

Tests:

  • Add a Spring Boot context load test for the new flight-ops-service module.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 20, 2026

Reviewer's Guide

Introduces a new flight-ops-service Spring Boot microservice that models flights, recurring flight schedules, and concrete flight instances, exposes CRUD/search REST APIs around them, and wires the module into the existing multi-module build alongside shared request/response DTOs and a FlightStatus enum in common-lib.

Sequence diagram for creating a flight schedule and generating flight instances

sequenceDiagram
    actor AirlineAdmin
    participant FlightScheduleController
    participant FlightScheduleServiceImpl as FlightScheduleService
    participant FlightRepository
    participant FlightScheduleRepository
    participant FlightInstanceServiceImpl as FlightInstanceService
    participant FlightInstanceRepository

    AirlineAdmin->>FlightScheduleController: POST /api/v1/flight-schedules
    FlightScheduleController->>FlightScheduleService: createFlightSchedule(request, userId)

    FlightScheduleService->>FlightRepository: findById(request.flightId)
    FlightRepository-->>FlightScheduleService: Flight

    FlightScheduleService->>FlightScheduleService: validate dates and business rules

    FlightScheduleService->>FlightScheduleRepository: save(FlightScheduleMapper.toEntity(request, flight))
    FlightScheduleRepository-->>FlightScheduleService: saved FlightSchedule (fs)

    FlightScheduleService->>FlightScheduleService: build FlightInstanceRequest template

    loop for each date between startDate and endDate
        FlightScheduleService->>FlightScheduleService: check operatingDays contains current date dayOfWeek
        alt operating day
            FlightScheduleService->>FlightScheduleService: set departureTime and arrivalTime on FlightInstanceRequest
            FlightScheduleService->>FlightInstanceService: createFlightInstance(airlineId, flightInstanceRequest)
            FlightInstanceService->>FlightRepository: findById(flightInstanceRequest.flightId)
            FlightRepository-->>FlightInstanceService: Flight
            FlightInstanceService->>FlightInstanceRepository: save(FlightInstanceMapper.toEntity(request, flight))
            FlightInstanceRepository-->>FlightInstanceService: FlightInstance
        end
    end

    FlightScheduleService-->>FlightScheduleController: FlightScheduleResponse
    FlightScheduleController-->>AirlineAdmin: 201 Created with schedule details
Loading

ER diagram for flights, schedules, and instances

erDiagram
    FLIGHT {
        Long id PK
        String flight_number
        Long airline_id
        Long aircraft_id
        Long departure_airport_id
        Long arrival_airport_id
        String status
        Instant created_at
        Instant updated_at
    }

    FLIGHT_SCHEDULE {
        Long id PK
        Long flight_id FK
        Long airline_id
        Long departure_airport_id
        Long arrival_airport_id
        Instant departure_time
        Instant arrival_time
        LocalDate start_date
        LocalDate end_date
        String operating_days
        Boolean is_active
        Instant created_at
        Instant updated_at
    }

    FLIGHT_INSTANCE {
        Long id PK
        Long flight_id FK
        Long airline_id
        Long departure_airport_id
        Long arrival_airport_id
        Long schedule_id
        Instant departure_time
        Instant arrival_time
        Integer total_seats
        Integer available_seats
        String status
        Integer min_advance_booking_days
        Integer max_advance_booking_days
        Boolean is_active
        Instant created_at
        Instant updated_at
    }

    FLIGHT ||--o{ FLIGHT_SCHEDULE : has
    FLIGHT ||--o{ FLIGHT_INSTANCE : materializes
    FLIGHT_SCHEDULE ||--o{ FLIGHT_INSTANCE : generates
Loading

Class diagram for core flight operations domain and persistence

classDiagram
    direction LR

    class Flight {
        +Long id
        +String flightNumber
        +Long airlineId
        +Long aircraftId
        +Long departureAirportId
        +Long arrivalAirportId
        +FlightStatus status
        +Instant createdAt
        +Instant updatedAt
        +boolean isActive()
        +boolean isInProgress()
    }

    class FlightInstance {
        +Long id
        +Flight flight
        +Long airlineId
        +Long departureAirportId
        +Long arrivalAirportId
        +Long scheduleId
        +Instant departureTime
        +Instant arrivalTime
        +Integer totalSeats
        +Integer availableSeats
        +FlightStatus status
        +Integer minAdvanceBookingDays
        +Integer maxAdvanceBookingDays
        +Boolean isActive
        +Instant createdAt
        +Instant updatedAt
        +String getFormatedDuration()
        +void normalizeAndValidate()
    }

    class FlightSchedule {
        +Long id
        +Flight flight
        +Long airlineId
        +Long departureAirportId
        +Long arrivalAirportId
        +Instant departureTime
        +Instant arrivalTime
        +LocalDate startDate
        +LocalDate endDate
        +List~DayOfWeek~ operatingDays
        +Boolean isActive
        +Instant createdAt
        +Instant updatedAt
        +boolean isCurrentlyValid()
        +boolean operatesOn(DayOfWeek dow)
        +String getFormattedOperatingDays()
        +void validateAndNormalize()
    }

    class FlightStatus {
        <<enum>>
        SCHEDULED
        DELAYED
        CANCELLED
        IN_AIR
        LANDED
        BOARDING
        DEPARTED
        ARRIVED
        DIVERTED
        COMPLETED
    }

    class FlightRepository {
        <<interface>>
        +Page~Flight~ findByAirlineId(Long airlineId, Pageable pageable)
        +boolean existByFlightNumber(String flightNumber)
        +Optional~Flight~ findById(Long id)
        +Flight save(Flight flight)
        +List~Flight~ findAll()
        +boolean existsById(Long id)
        +void deleteById(Long id)
    }

    class FlightInstanceRepository {
        <<interface>>
        +Page~FlightInstance~ findByAirlineId(Long airlineId, Long departureAirportId, Long arrivalAirportId, Long flightId, LocalDateTime dayStart, LocalDateTime dayEnd, Pageable pageable)
        +Optional~FlightInstance~ findById(Long id)
        +FlightInstance save(FlightInstance instance)
        +boolean existsById(Long id)
        +void deleteById(Long id)
    }

    class FlightScheduleRepository {
        <<interface>>
        +List~FlightSchedule~ findByFlightAirlineId(Long airlineId)
        +List~FlightSchedule~ findByAirlineIdAndIsActiveTrue(Long airlineId)
        +List~FlightSchedule~ findByFlightIdOrderByStartDate(Long flightId)
        +List~FlightSchedule~ findOverlappingSchedules(Long flightId, LocalDate startDate, LocalDate endDate)
        +boolean existsByFlightIdAndStartDateAndEndDate(Long flightId, LocalDate startDate, LocalDate endDate)
        +Optional~FlightSchedule~ findById(Long id)
        +FlightSchedule save(FlightSchedule schedule)
        +boolean existsById(Long id)
        +void deleteById(Long id)
    }

    Flight "1" --> "*" FlightInstance : has_instances
    Flight "1" --> "*" FlightSchedule : has_schedules
    FlightStatus <.. Flight : uses
    FlightStatus <.. FlightInstance : uses

    FlightRepository ..|> JpaRepository
    FlightInstanceRepository ..|> JpaRepository
    FlightScheduleRepository ..|> JpaRepository

    class JpaRepository {
        <<interface>>
    }
Loading

Class diagram for flight operations API, services, mappers, and DTOs

classDiagram
    direction LR

    class FlightController {
        +ResponseEntity~ApiResponse~ createFlight(FlightRequest request)
        +ResponseEntity~ApiResponse~ updateFlight(Long id, FlightRequest request)
        +ResponseEntity~Void~ deleteFlight(Long id)
        +ResponseEntity~ApiResponse~ changeStatus(Long id, FlightStatus newStatus)
        +ResponseEntity~ApiResponse~ getFlightById(Long id)
        +ResponseEntity~ApiResponse~ getAllFlights()
        +ResponseEntity~ApiResponse~ getFlightByAirline(Long airlineId, Long departureAirportId, Long arrivalAirportId, Pageable pageable)
    }

    class FlightInstanceController {
        +ResponseEntity~ApiResponse~ createFlightInstance(FlightInstanceRequest request)
        +ResponseEntity~ApiResponse~ updateFlightInstance(Long id, FlightInstanceRequest request)
        +ResponseEntity~ApiResponse~ getFlightInstanceById(Long id)
        +ResponseEntity~ApiResponse~ getFlightInstancesByAirline(Long airlineId, Long departureAirportId, Long arrivalAirportId, LocalDate onDate, Long flightId, Pageable pageable)
        +ResponseEntity~Void~ deleteFlightInstance(Long id)
    }

    class FlightScheduleController {
        +ResponseEntity~FlightScheduleResponse~ createFlightSchedule(FlightScheduleRequest request, Long userId)
        +ResponseEntity~FlightScheduleResponse~ getFlightScheduleById(Long id)
        +ResponseEntity~List~ getAllFlightSchedulesByAirline(Long userId)
        +ResponseEntity~FlightScheduleResponse~ updateFlightSchedule(Long id, FlightScheduleRequest request)
        +ResponseEntity~Void~ deleteFlightSchedule(Long id)
    }

    class FlightService {
        <<interface>>
        +FlightResponse createFlight(Long airlineId, FlightRequest flightRequest)
        +FlightResponse updateFlight(Long id, FlightRequest flightRequest)
        +List~FlightResponse~ getAllFlights()
        +List~FlightResponse~ getFlightByAirline(Long airlineId, Long departureAirportId, Long arrivalAirportId, Pageable pageable)
        +FlightResponse getFlightById(Long id)
        +void deleteFlight(Long id)
        +FlightResponse changeStatus(Long id, FlightStatus newStatus)
    }

    class FlightServiceImpl {
        +FlightResponse createFlight(Long airlineId, FlightRequest flightRequest)
        +FlightResponse updateFlight(Long id, FlightRequest flightRequest)
        +List~FlightResponse~ getAllFlights()
        +List~FlightResponse~ getFlightByAirline(Long airlineId, Long departureAirportId, Long arrivalAirportId, Pageable pageable)
        +FlightResponse getFlightById(Long id)
        +void deleteFlight(Long id)
        +FlightResponse changeStatus(Long id, FlightStatus newStatus)
        -FlightRepository flightRepository
    }

    class FlightInstanceService {
        <<interface>>
        +FlightInstanceResponse getFlightInstanceById(Long id)
        +FlightInstanceResponse createFlightInstance(Long userId, FlightInstanceRequest flightInstanceRequest)
        +FlightInstanceResponse updateFlightInstance(Long id, FlightInstanceRequest flightInstanceRequest)
        +void deleteFlightInstance(Long id)
        +Page~FlightInstanceResponse~ getFlightInstancesByAirlineId(Long airlineId, Long departureAirportId, Long arrivalAirportId, LocalDate onDate, Long flightId, Pageable pageable)
    }

    class FlightInstanceServiceImpl {
        +FlightInstanceResponse getFlightInstanceById(Long id)
        +FlightInstanceResponse createFlightInstance(Long userId, FlightInstanceRequest flightInstanceRequest)
        +FlightInstanceResponse updateFlightInstance(Long id, FlightInstanceRequest flightInstanceRequest)
        +void deleteFlightInstance(Long id)
        +Page~FlightInstanceResponse~ getFlightInstancesByAirlineId(Long airlineId, Long departureAirportId, Long arrivalAirportId, LocalDate onDate, Long flightId, Pageable pageable)
        -FlightInstanceRepository flightInstanceRepository
        -FlightRepository flightRepository
    }

    class FlightScheduleService {
        <<interface>>
        +FlightScheduleResponse createFlightSchedule(FlightScheduleRequest flightScheduleRequest, Long userId)
        +FlightScheduleResponse getFlightScheduleById(Long id)
        +List~FlightScheduleResponse~ getAllFlightSchedulesByAirline(Long userId)
        +FlightScheduleResponse updateFlightSchedule(Long id, FlightScheduleRequest flightScheduleRequest)
        +void deleteFlightSchedule(Long id)
    }

    class FlightScheduleServiceImpl {
        +FlightScheduleResponse createFlightSchedule(FlightScheduleRequest flightScheduleRequest, Long userId)
        +FlightScheduleResponse getFlightScheduleById(Long id)
        +List~FlightScheduleResponse~ getAllFlightSchedulesByAirline(Long userId)
        +FlightScheduleResponse updateFlightSchedule(Long id, FlightScheduleRequest flightScheduleRequest)
        +void deleteFlightSchedule(Long id)
        -FlightScheduleRepository flightScheduleRepository
        -FlightRepository flightRepository
        -FlightInstanceService flightInstanceService
    }

    class FlightMapper {
        <<utility>>
        +FlightResponse toResponse(Flight flight, AirlineResponse airline, AircraftResponse aircraft, AirportResponse departureAirport, AirportResponse arrivalAirport, Double lowestPrice, Integer totalAvailableSeats)
        +FlightResponse toBasicResponse(Flight flight)
        +List~FlightResponse~ toResponseList(List~Flight~ flights)
        +Flight toEntity(FlightRequest request)
        +void updateEntity(Flight flight, FlightRequest request)
        +void updateStatus(Flight flight, FlightStatus newStatus)
    }

    class FlightInstanceMapper {
        <<utility>>
        +FlightInstance toEntity(FlightInstanceRequest request, Flight flight)
        +FlightInstanceResponse toResponse(FlightInstance instance, String flightNumber, AirlineResponse airline, AircraftResponse aircraft, AirportResponse departureAirport, AirportResponse arrivalAirport)
        +FlightInstanceResponse toBasicResponse(FlightInstance instance)
        +List~FlightInstanceResponse~ toResponseList(List~FlightInstance~ instances)
        +void updateEntity(FlightInstance instance, FlightInstanceRequest request)
        +void updateStatus(FlightInstance instance, FlightStatus newStatus)
    }

    class FlightScheduleMapper {
        <<utility>>
        +FlightSchedule toEntity(FlightScheduleRequest request, Flight flight)
        +FlightScheduleResponse toResponse(FlightSchedule schedule, AirportResponse departureAirport, AirportResponse arrivalAirport)
        +void updateEntity(FlightSchedule schedule, FlightScheduleRequest request)
    }

    class FlightRequest {
        +String flightNumber
        +Long airlineId
        +Long aircraftId
        +Long departureAirportId
        +Long arrivalAirportId
        +FlightStatus status
    }

    class FlightInstanceRequest {
        +Long flightId
        +Long airlineId
        +Long departureAirportId
        +Long arrivalAirportId
        +Long scheduleId
        +LocalDateTime departureTime
        +LocalDateTime arrivalTime
        +Integer totalSeats
        +Integer availableSeats
        +FlightStatus status
        +Integer minAdvanceBookingDays
        +Integer maxAdvanceBookingDays
        +Boolean isActive
    }

    class FlightScheduleRequest {
        +Long flightId
        +LocalTime departureTime
        +LocalTime arrivalTime
        +LocalDate startDate
        +LocalDate endDate
        +List~DayOfWeek~ operatingDays
        +Boolean isActive
        +boolean isTimesValid()
        +boolean isDatesValid()
        +boolean isStartDateNotInPast()
        +boolean isOperatingDaysUnique()
    }

    class FlightResponse {
        +Long id
        +String flightNumber
        +AirlineResponse airline
        +AircraftResponse aircraft
        +AirportResponse departureAirport
        +AirportResponse arrivalAirport
        +LocalDateTime departureTime
        +LocalDateTime arrivalTime
        +FlightStatus status
        +Double lowestPrice
        +Integer totalAvailableSeats
        +Instant createdAt
        +Instant updatedAt
    }

    class FlightInstanceResponse {
        +Long id
        +Long flightId
        +String flightNumber
        +Long airlineId
        +String airlineName
        +String airlineLogo
        +Long aircraftId
        +String aircraftModel
        +String aircraftCode
        +AirportResponse departureAirport
        +AirportResponse arrivalAirport
        +Instant departureTime
        +Instant arrivalTime
        +String formattedDuration
        +Integer totalSeats
        +Integer availableSeats
        +FlightStatus status
        +Integer minAdvanceBookingDays
        +Integer maxAdvanceBookingDays
        +Boolean isActive
        +String terminal
        +String gate
        +Long version
    }

    class FlightScheduleResponse {
        +Long id
        +Long flightId
        +String flightNumber
        +AirportResponse departureAirport
        +AirportResponse arrivalAirport
        +LocalDate departureTime
        +LocalDate arrivalTime
        +LocalDate startDate
        +LocalDate endDate
        +List~DayOfWeek~ operatingDays
        +Boolean isActive
    }

    class ApiResponse~T~ {
        +String message
        +T data
        +static ApiResponse~T~ success(T data)
        +static ApiResponse~T~ success(String message, T data)
    }

    class AirlineResponse
    class AircraftResponse
    class AirportResponse

    FlightController --> FlightService
    FlightInstanceController --> FlightInstanceService
    FlightScheduleController --> FlightScheduleService

    FlightServiceImpl ..|> FlightService
    FlightInstanceServiceImpl ..|> FlightInstanceService
    FlightScheduleServiceImpl ..|> FlightScheduleService

    FlightServiceImpl --> FlightRepository
    FlightInstanceServiceImpl --> FlightInstanceRepository
    FlightInstanceServiceImpl --> FlightRepository
    FlightScheduleServiceImpl --> FlightScheduleRepository
    FlightScheduleServiceImpl --> FlightRepository
    FlightScheduleServiceImpl --> FlightInstanceService

    FlightMapper ..> Flight
    FlightMapper ..> FlightRequest
    FlightMapper ..> FlightResponse

    FlightInstanceMapper ..> FlightInstance
    FlightInstanceMapper ..> FlightInstanceRequest
    FlightInstanceMapper ..> FlightInstanceResponse

    FlightScheduleMapper ..> FlightSchedule
    FlightScheduleMapper ..> FlightScheduleRequest
    FlightScheduleMapper ..> FlightScheduleResponse

    FlightResponse o--> AirlineResponse
    FlightResponse o--> AircraftResponse
    FlightResponse o--> AirportResponse

    FlightInstanceResponse o--> AirportResponse
    FlightScheduleResponse o--> AirportResponse

    FlightStatus <.. FlightRequest
    FlightStatus <.. FlightInstanceRequest
    FlightStatus <.. FlightScheduleRequest
    FlightStatus <.. FlightResponse
    FlightStatus <.. FlightInstanceResponse
Loading

File-Level Changes

Change Details Files
Add new flight-ops-service Spring Boot module with persistence, REST APIs, and build configuration.
  • Register flight-ops-service as a Maven submodule in services/pom.xml and add its own pom.xml with Spring Web, Spring Data JPA, MySQL, Lombok, and common-lib dependencies.
  • Add Spring Boot bootstrap class, basic application.yaml, Maven wrapper scripts, and ignore/attributes files to support building and running the new service.
  • Introduce readme documenting Flight, FlightInstance, and FlightSchedule entities and their fields.
services/pom.xml
services/flight-ops-service/pom.xml
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/FlightOpsServiceApplication.java
services/flight-ops-service/src/main/resources/application.yaml
services/flight-ops-service/mvnw
services/flight-ops-service/mvnw.cmd
services/flight-ops-service/.mvn/wrapper/maven-wrapper.properties
services/flight-ops-service/.gitignore
services/flight-ops-service/.gitattributes
services/flight-ops-service/readme.md
Define JPA domain model for flights, recurring schedules, and concrete flight instances with validation and derived helpers.
  • Add Flight entity with airline/aircraft/airport references, status field using FlightStatus enum, indices, and audit timestamps plus helper methods for active/in-progress checks.
  • Add FlightInstance entity linked to Flight with airline and airport IDs, scheduleId, UTC departure/arrival times, seat capacity and availability, booking window rules, status, auditing, and lifecycle validation to bound availableSeats, default status/isActive, and ensure different airports.
  • Add FlightSchedule entity linked to Flight with airline and airport IDs, departure/arrival times as Instants, validity date range, operatingDays collection, isActive flag, auditing, and lifecycle validation for airport difference, date ordering, time ordering, and default isActive, plus helper methods for validity, day-of-week checks, and formatted operating days (though implementation looks inconsistent with the List type).
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/model/Flight.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/model/FlightInstance.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/model/FlightSchedule.java
Introduce REST controllers and service layers for managing flights, flight instances, and flight schedules.
  • Implement FlightService and FlightServiceImpl for creating, updating, listing, fetching, deleting, and changing status of flights including flight-number uniqueness checks and simple in-memory filtering by departure/arrival airport for airline queries.
  • Expose FlightController with REST endpoints for CRUD, status change, and search operations over flights, wrapping responses in ApiResponse and leaving security/airline resolution TODOs via context helpers.
  • Implement FlightInstanceService/Impl and FlightInstanceController to create/update/delete/get/search flight instances, deriving initial seat counts from AircraftResponse and using repository-level filtering by airline, route, date window, and flightId.
  • Implement FlightScheduleService/Impl and FlightScheduleController to create/update/delete/get/list flight schedules, including logic to generate FlightInstance records for all days between start and end dates that match operatingDays and to map requests/responses; airline affiliation is currently inferred from user id placeholder.
  • Add a simple HomeController health-style endpoint under /api/v1/home for the new service.
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/service/FlightService.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/service/Impl/FlightServiceImpl.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/controller/FlightController.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/service/FlightInstanceService.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/service/Impl/FlightInstanceServiceImpl.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/controller/FlightInstanceController.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/service/FlightScheduleService.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/service/Impl/FlightScheduleServiceImpl.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/controller/FlightScheduleController.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/controller/HomeController.java
Add mapper classes to convert between entities and shared DTOs for flights, instances, and schedules.
  • Add FlightMapper for mapping Flight ↔ FlightResponse/FlightRequest, supporting enriched responses with airline/aircraft/airport objects and optional price/seat aggregation, plus helpers to update existing entities and change status.
  • Add FlightInstanceMapper to map FlightInstance ↔ FlightInstanceRequest/FlightInstanceResponse, including enriched mapping with external airline/aircraft/airport info, list mapping, partial updates, and status updates, with UTC conversion helpers.
  • Add FlightScheduleMapper to map FlightSchedule ↔ FlightScheduleRequest/FlightScheduleResponse, converting LocalTime to Instant, updating mutable fields, and providing duration helper methods (some currently unused).
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/mapper/FlightMapper.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/mapper/FlightInstanceMapper.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/mapper/FlightScheduleMapper.java
Extend common-lib with flight-specific DTOs and enum used across services.
  • Introduce FlightRequest with validation for core flight fields (numbers, airline/aircraft/airport IDs) and optional status field, leaving time fields commented out for now.
  • Introduce FlightInstanceRequest with core identifiers, schedule reference, departure/arrival times as LocalDateTime, seat counts, status, booking-window fields, and isActive flag, currently without Bean Validation annotations.
  • Introduce FlightScheduleRequest with validation on flightId, times, date range, operatingDays, and isActive plus @AssertTrue business rules for time ordering, date ordering, non-past start date, and uniqueness of operatingDays; airport fields are commented out.
  • Add FlightResponse, FlightInstanceResponse, and FlightScheduleResponse DTOs to represent enriched API responses for flights, instances, and schedules, including related airline/aircraft/airport objects and derived or configuration fields.
  • Add FlightStatus enum shared between services to represent lifecycle of flights/instances (SCHEDULED, DELAYED, CANCELLED, IN_AIR, LANDED, BOARDING, DEPARTED, ARRIVED, DIVERTED, COMPLETED).
common-lib/src/main/java/com/flynest/payload/request/FlightRequest.java
common-lib/src/main/java/com/flynest/payload/request/FlightInstanceRequest.java
common-lib/src/main/java/com/flynest/payload/request/FlightScheduleRequest.java
common-lib/src/main/java/com/flynest/payload/response/FlightResponse.java
common-lib/src/main/java/com/flynest/payload/response/FlightInstanceResponse.java
common-lib/src/main/java/com/flynest/payload/response/FlightScheduleResponse.java
common-lib/src/main/java/com/flynest/enums/FlightStatus.java
Add JPA repositories for the new entities with custom query methods.
  • Create FlightRepository with a paged finder by airlineId and an existence check by flightNumber used for uniqueness validation.
  • Create FlightInstanceRepository with a JPQL query filtering by airline, optional route, optional flightId, and optional dayStart/dayEnd to support paginated search.
  • Create FlightScheduleRepository with methods to find schedules by airline, by flight, active by airline, and to detect overlapping date ranges for a flight (note: some queries reference fields that do not exist on the entity and may need correction).
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/repository/FlightRepository.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/repository/FlightInstanceRepository.java
services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/repository/FlightScheduleRepository.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 7 issues, and left some high level feedback:

  • FlightSchedule.operatingDays is defined as List but business methods (operatesOn, getFormattedOperatingDays) still treat it as a comma‑separated String, which will not compile/work as written; align these methods to use the List representation (e.g., contains(DayOfWeek) and joining DayOfWeek values) or change the field type back to a String.
  • FlightScheduleRepository refers to non‑existent properties (e.g., fs.flightId in JPQL and derived methods like existsByFlightId...) while FlightSchedule only has a flight relation; update these queries/method names to use the mapped relationship (flight) or add a flightId field if that’s intended.
  • Several JPA entities use org.antlr.v4.runtime.misc.NotNull instead of Jakarta validation or JPA annotations (e.g., on FlightSchedule.arrivalTime); replace these with jakarta.validation.constraints.NotNull or JPA nullable=false to get proper validation and configuration.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- FlightSchedule.operatingDays is defined as List<DayOfWeek> but business methods (operatesOn, getFormattedOperatingDays) still treat it as a comma‑separated String, which will not compile/work as written; align these methods to use the List<DayOfWeek> representation (e.g., contains(DayOfWeek) and joining DayOfWeek values) or change the field type back to a String.
- FlightScheduleRepository refers to non‑existent properties (e.g., fs.flightId in JPQL and derived methods like existsByFlightId...) while FlightSchedule only has a flight relation; update these queries/method names to use the mapped relationship (flight) or add a flightId field if that’s intended.
- Several JPA entities use org.antlr.v4.runtime.misc.NotNull instead of Jakarta validation or JPA annotations (e.g., on FlightSchedule.arrivalTime); replace these with jakarta.validation.constraints.NotNull or JPA nullable=false to get proper validation and configuration.

## Individual Comments

### Comment 1
<location path="services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/model/FlightSchedule.java" line_range="129-138" />
<code_context>
+    @ElementCollection
</code_context>
<issue_to_address>
**issue (bug_risk):** operatingDays field type and helper methods are inconsistent and will not compile or work correctly.

`operatingDays` is declared as `List<DayOfWeek>`, but `operatesOn` and `getFormattedOperatingDays` treat it as `List<String>` and even call `operatingDays.split(",")`, which will not compile and is conceptually wrong. Instead, keep `List<DayOfWeek>` and implement:

- `operatesOn` as `return operatingDays.contains(dow);`
- `getFormattedOperatingDays` by streaming over `operatingDays` and mapping each `DayOfWeek` to its display name or a custom label.

This keeps types consistent and uses the enum correctly in both persistence and logic.
</issue_to_address>

### Comment 2
<location path="services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/mapper/FlightScheduleMapper.java" line_range="64-65" />
<code_context>
+
+                .departureAirport(departureAirport)
+                .arrivalAirport(arrivalAirport)
+                .departureTime(schedule.getDepartureTime() != null ? LocalDate.from(schedule.getDepartureTime()) : null)
+                .arrivalTime(schedule.getArrivalTime() != null ? LocalDate.from(schedule.getArrivalTime()) : null)
+
+                .startDate(schedule.getStartDate())
</code_context>
<issue_to_address>
**issue (bug_risk):** Converting Instant to LocalDate with LocalDate.from will throw at runtime and also loses time-of-day semantics.

Given that `FlightSchedule` stores UTC time-of-day in an `Instant`, mapping it to `LocalDate` drops the time component, and `LocalDate.from(Instant)` will fail at runtime.

If the API should expose the time-of-day, change the response field type to `LocalTime` (or `LocalDateTime` for a concrete date) and convert via a zone-aware call, e.g.:

```java
instant.atZone(ZoneOffset.UTC).toLocalTime()
```

If you truly intend a date derived from the epoch-based `Instant`, use:

```java
LocalDate.ofInstant(schedule.getDepartureTime(), ZoneOffset.UTC)
```

though that doesn’t match the current “time-of-day only” semantics of the entity.
</issue_to_address>

### Comment 3
<location path="services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/repository/FlightScheduleRepository.java" line_range="28-30" />
<code_context>
+    /**
+     * Find overlapping schedules (same flight, overlapping date ranges)
+     */
+    @Query("SELECT fs FROM FlightSchedule fs " +
+            "WHERE fs.flightId = :flightId " +
+            "AND fs.startDate <= :endDate " +
+            "AND fs.endDate >= :startDate")
+    List<FlightSchedule> findOverlappingSchedules(
</code_context>
<issue_to_address>
**issue (bug_risk):** JPQL uses nonexistent flightId field on FlightSchedule; it should traverse the flight association.

This will throw a runtime error because `flightId` is not a mapped attribute on `FlightSchedule`.

Use the association path in the query instead:

```java
@Query("SELECT fs FROM FlightSchedule fs " +
       "WHERE fs.flight.id = :flightId " +
       "AND fs.startDate <= :endDate " +
       "AND fs.endDate >= :startDate")
```

The repository method signature can stay the same; Spring Data will still bind `flightId` correctly.
</issue_to_address>

### Comment 4
<location path="services/flight-ops-service/src/main/java/com/flynest/flight_ops_service/model/FlightSchedule.java" line_range="104-106" />
<code_context>
+    /**
+     * Scheduled arrival time (UTC) - time of day only
+     */
+    @NotNull
+    @Column(name = "arrival_time", nullable = false)
+    private Instant arrivalTime;
+
+    // =========================================================
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The NotNull annotation used here is not the Jakarta validation one and will not participate in bean validation.

The imported `org.antlr.v4.runtime.misc.NotNull` won’t be picked up by Jakarta Bean Validation, so this field won’t be validated at the API layer. Since `nullable = false` already enforces the DB constraint, either switch to `jakarta.validation.constraints.NotNull` for bean validation or remove the annotation and rely solely on the column constraint.

Suggested implementation:

```java
    /**
     * Scheduled arrival time (UTC) - time of day only
     */
    @NotNull
    @Column(name = "arrival_time", nullable = false)
    private Instant arrivalTime;

    // PRIMARY KEY

```

1. Update the imports at the top of `FlightSchedule.java`:
   - Remove `import org.antlr.v4.runtime.misc.NotNull;` if present.
   - Add `import jakarta.validation.constraints.NotNull;`.
2. If other fields in this entity are using the old `org.antlr.v4.runtime.misc.NotNull`, update them to use `jakarta.validation.constraints.NotNull` as well so they participate in bean validation consistently.
</issue_to_address>

### Comment 5
<location path="services/flight-ops-service/readme.md" line_range="15" />
<code_context>
+6. arrivalAirportId
+7. FlightStatus - status [SCHEDULED, DELAYED, CANCELLED, IN_AIR, LANDED,BOARDING, DEPARTED, ARRIVED,DIVERTED, COMPLETED]
+8. createdAt
+9. updateAt
+
+### flightInstance
</code_context>
<issue_to_address>
**suggestion (typo):** Potential typo in field name "updateAt".

Consider renaming it to `updatedAt` to better reflect a last-update timestamp and align with common naming conventions.

```suggestion
9. updatedAt
```
</issue_to_address>

### Comment 6
<location path="services/flight-ops-service/readme.md" line_range="37-41" />
<code_context>
+
+isActive
+
+fu string getFormatedDuration() {
+    // gap between departure time and arrivaltime ---hrs ,mins
+}
</code_context>
<issue_to_address>
**suggestion (typo):** Multiple spelling/wording issues in the method signature line.

Since this is an example signature, please fix the typos: change `fu` to the intended keyword (e.g., `fun`) and rename `getFormatedDuration` to `getFormattedDuration`.

```suggestion
isActive

fun string getFormattedDuration() {
    // gap between departure time and arrivaltime ---hrs ,mins
}
```
</issue_to_address>

### Comment 7
<location path="services/flight-ops-service/readme.md" line_range="39" />
<code_context>
+isActive
+
+fu string getFormatedDuration() {
+    // gap between departure time and arrivaltime ---hrs ,mins
+}
+
</code_context>
<issue_to_address>
**nitpick (typo):** Minor spelling and spacing issues in the inline comment.

Consider updating the comment to fix the spelling and spacing, e.g.: `// gap between departure time and arrival time — hrs, mins`.

```suggestion
fu string getFormatedDuration() {
    // gap between departure time and arrival time — hrs, mins
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +129 to +138
@ElementCollection
@Enumerated(EnumType.STRING)
private List<DayOfWeek> operatingDays;
// =========================================================
// STATUS
// =========================================================

/**
* Whether this schedule is currently active/in-use
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): operatingDays field type and helper methods are inconsistent and will not compile or work correctly.

operatingDays is declared as List<DayOfWeek>, but operatesOn and getFormattedOperatingDays treat it as List<String> and even call operatingDays.split(","), which will not compile and is conceptually wrong. Instead, keep List<DayOfWeek> and implement:

  • operatesOn as return operatingDays.contains(dow);
  • getFormattedOperatingDays by streaming over operatingDays and mapping each DayOfWeek to its display name or a custom label.

This keeps types consistent and uses the enum correctly in both persistence and logic.

Comment on lines +64 to +65
.departureTime(schedule.getDepartureTime() != null ? LocalDate.from(schedule.getDepartureTime()) : null)
.arrivalTime(schedule.getArrivalTime() != null ? LocalDate.from(schedule.getArrivalTime()) : null)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Converting Instant to LocalDate with LocalDate.from will throw at runtime and also loses time-of-day semantics.

Given that FlightSchedule stores UTC time-of-day in an Instant, mapping it to LocalDate drops the time component, and LocalDate.from(Instant) will fail at runtime.

If the API should expose the time-of-day, change the response field type to LocalTime (or LocalDateTime for a concrete date) and convert via a zone-aware call, e.g.:

instant.atZone(ZoneOffset.UTC).toLocalTime()

If you truly intend a date derived from the epoch-based Instant, use:

LocalDate.ofInstant(schedule.getDepartureTime(), ZoneOffset.UTC)

though that doesn’t match the current “time-of-day only” semantics of the entity.

Comment on lines +28 to +30
@Query("SELECT fs FROM FlightSchedule fs " +
"WHERE fs.flightId = :flightId " +
"AND fs.startDate <= :endDate " +
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): JPQL uses nonexistent flightId field on FlightSchedule; it should traverse the flight association.

This will throw a runtime error because flightId is not a mapped attribute on FlightSchedule.

Use the association path in the query instead:

@Query("SELECT fs FROM FlightSchedule fs " +
       "WHERE fs.flight.id = :flightId " +
       "AND fs.startDate <= :endDate " +
       "AND fs.endDate >= :startDate")

The repository method signature can stay the same; Spring Data will still bind flightId correctly.

Comment on lines +104 to +106
@NotNull
@Column(name = "arrival_time", nullable = false)
private Instant arrivalTime;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): The NotNull annotation used here is not the Jakarta validation one and will not participate in bean validation.

The imported org.antlr.v4.runtime.misc.NotNull won’t be picked up by Jakarta Bean Validation, so this field won’t be validated at the API layer. Since nullable = false already enforces the DB constraint, either switch to jakarta.validation.constraints.NotNull for bean validation or remove the annotation and rely solely on the column constraint.

Suggested implementation:

    /**
     * Scheduled arrival time (UTC) - time of day only
     */
    @NotNull
    @Column(name = "arrival_time", nullable = false)
    private Instant arrivalTime;

    // PRIMARY KEY
  1. Update the imports at the top of FlightSchedule.java:
    • Remove import org.antlr.v4.runtime.misc.NotNull; if present.
    • Add import jakarta.validation.constraints.NotNull;.
  2. If other fields in this entity are using the old org.antlr.v4.runtime.misc.NotNull, update them to use jakarta.validation.constraints.NotNull as well so they participate in bean validation consistently.

6. arrivalAirportId
7. FlightStatus - status [SCHEDULED, DELAYED, CANCELLED, IN_AIR, LANDED,BOARDING, DEPARTED, ARRIVED,DIVERTED, COMPLETED]
8. createdAt
9. updateAt
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Potential typo in field name "updateAt".

Consider renaming it to updatedAt to better reflect a last-update timestamp and align with common naming conventions.

Suggested change
9. updateAt
9. updatedAt

Comment on lines +37 to +41
isActive

fu string getFormatedDuration() {
// gap between departure time and arrivaltime ---hrs ,mins
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Multiple spelling/wording issues in the method signature line.

Since this is an example signature, please fix the typos: change fu to the intended keyword (e.g., fun) and rename getFormatedDuration to getFormattedDuration.

Suggested change
isActive
fu string getFormatedDuration() {
// gap between departure time and arrivaltime ---hrs ,mins
}
isActive
fun string getFormattedDuration() {
// gap between departure time and arrivaltime ---hrs ,mins
}


isActive

fu string getFormatedDuration() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (typo): Minor spelling and spacing issues in the inline comment.

Consider updating the comment to fix the spelling and spacing, e.g.: // gap between departure time and arrival time — hrs, mins.

Suggested change
fu string getFormatedDuration() {
fu string getFormatedDuration() {
// gap between departure time and arrival time — hrs, mins

@vikasutf8 vikasutf8 merged commit ed4c3a9 into dev-work Apr 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant