mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
Refactor business logic for train,schedule,coach,seat and search modules
This commit is contained in:
@@ -9,24 +9,38 @@ export class SearchController {
|
||||
constructor(private service: SearchService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({
|
||||
summary: 'Search trips by origin, destination, and passenger counts',
|
||||
description: 'Returns available trips WITHOUT pricing. Requires adult count (mandatory) and optional child count. Pricing is shown only in fare quote endpoint.'
|
||||
@ApiOperation({
|
||||
summary: 'Search schedules by any origin–destination stop pair',
|
||||
description: `Finds all train schedules where both origin and destination appear as stops (not just terminals).
|
||||
|
||||
Example: A train running A→B→C→D will appear in results for A→B, A→C, A→D, B→C, B→D, and C→D searches.
|
||||
|
||||
Availability is computed per seat per segment — a seat booked A→B is still shown as available for B→D.
|
||||
|
||||
Returns departure/arrival times for the requested leg, the full stop list, and per-class seat counts.`
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'List of available trips with seat availability' })
|
||||
@ApiResponse({ status: 400, description: 'Invalid search parameters' })
|
||||
searchTrips(@Body() dto: SearchTripsDto) {
|
||||
return this.service.searchTrips(dto);
|
||||
@ApiResponse({ status: 200, description: 'Matching schedules with segment-accurate seat availability per class' })
|
||||
searchTrips(@Body() dto: SearchTripsDto) {
|
||||
return this.service.searchTrips(dto);
|
||||
}
|
||||
|
||||
@Post('fare-quote')
|
||||
@ApiOperation({
|
||||
summary: 'Get detailed fare quote with age-based pricing',
|
||||
description: 'Calculates fare based on adult/child counts. First child travels free, subsequent children pay full fare. Supports multi-currency display (ETB, DJF, USD).'
|
||||
@ApiOperation({
|
||||
summary: 'Get fare quote for a specific schedule leg',
|
||||
description: `Calculates fare for the requested origin→destination leg on a schedule.
|
||||
|
||||
Pricing rules (in priority order):
|
||||
1. Schedule-scoped FareRule (tripId = scheduleId)
|
||||
2. Segment route FareRule (e.g. ADD-DRE)
|
||||
3. Full-route FareRule (e.g. ADD-DJI)
|
||||
4. Default hardcoded fare
|
||||
|
||||
Age-based pricing: first child (age < 5) travels free, subsequent children pay full fare.
|
||||
Supports multi-currency display (ETB, DJF, USD).`
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Detailed fare breakdown with adult/child pricing and currency conversion' })
|
||||
@ApiResponse({ status: 404, description: 'Trip not found' })
|
||||
getFareQuote(@Body() dto: FareQuoteDto) {
|
||||
return this.service.getFareQuote(dto);
|
||||
@ApiResponse({ status: 200, description: 'Fare breakdown with adult/child pricing, discounts, taxes, and currency conversion' })
|
||||
@ApiResponse({ status: 404, description: 'Schedule not found or origin/destination not on schedule' })
|
||||
getFareQuote(@Body() dto: FareQuoteDto) {
|
||||
return this.service.getFareQuote(dto);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user