Skip to content

Commit

Permalink
feat: add rest-client
Browse files Browse the repository at this point in the history
  • Loading branch information
meysamhadeli committed Dec 12, 2023
1 parent 7feeb30 commit 8855f4f
Show file tree
Hide file tree
Showing 58 changed files with 746 additions and 278 deletions.
256 changes: 256 additions & 0 deletions booking.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
@identity-api=http://localhost:3333
@flight-api=http://localhost:3344
@passenger-api=http://localhost:3355
@booking-api=http://localhost:3366

################################# Identity API #################################

###
# @name ApiRoot_Identity
GET {{identity-api}}
###


###
# @name Login
POST {{identity-api}}/api/v1/identity/login
accept: application/json
Content-Type: application/json

{
"email": "[email protected]",
"password": "Admin@12345"
}
###


###
# @name Logout
POST {{identity-api}}/api/v1/identity/logout?accessToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjUsImlhdCI6MTcwMjMzMzM1NiwiZXhwIjoxNzAyMzM1MTU2LCJ0eXBlIjowfQ.A2uF3tg2Y0ZK7sK53Y7r-JWTs8s66A_2Jf8DY_qchDA
accept: application/json
Content-Type: application/json

###


###
# @name Refresh_Token
POST {{identity-api}}/api/v1/identity/refresh-token?refreshToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjUsImlhdCI6MTcwMjMzMzMzNSwiZXhwIjoxNzAyNDE5NzM1LCJ0eXBlIjoxfQ.T0z6lAQ4pxrKS6L6MutrwVbBGe96rq2wbIy0mCNs488
accept: application/json
Content-Type: application/json

###

###
# @name Create_User
POST {{identity-api}}/api/v1/user/create
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"email": "[email protected]",
"password": "Admin@12345",
"name": "John",
"role": 0,
"passportNumber": "12345678"
}
###


###
# @name Update_User
PUT {{identity-api}}/api/v1/user/update?id=3
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"email": "[email protected]",
"password": "Admin@12345",
"name": "John",
"role": 0,
"passportNumber": "12345678"
}
###


###
# @name Delete_User
DELETE {{identity-api}}/api/v1/user/delete?id=1
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

###

###
# @name Get_User_By_Id
GET {{identity-api}}/api/v1/user/get-by-id?id=1
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}
###

###
# @name Get_Users
GET {{identity-api}}/api/v1/user/get?pageSize=20&page=1&order=DESC
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}
###

################################# Flight API #################################

###
# @name ApiRoot_Flight
GET {{flight-api}}
###


###
# @name Create_Airport
POST {{flight-api}}/api/v1/airport/airport
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"name": "frankfurt",
"address": "frankfurt",
"code": "14FF"
}
###


###
# @name Create_Aircraft
POST {{flight-api}}/api/v1/aircraft/create
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"name": "airbus330",
"model": "330",
"manufacturingYear": 2014
}
###


###
# @name Create_Seat
Post {{flight-api}}/api/v1/seat/create
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"seatNumber": "1266",
"seatClass": 1,
"seatType": 1,
"flightId": 1
}
###


###
# @name Reserve_Seat
Post {{flight-api}}/api/v1/seat/reserve
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"seatNumber": "1266",
"flightId": 1
}
###


###
# @name Get_Available_Seats
GET {{flight-api}}/api/v1/seat/get-available-seats?flightId=1
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}
###


###
# @name Get_Flight_By_Id
GET {{flight-api}}/api/v1/flight/get-by-id?id=1
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}
###


###
# @name Create_Flights
POST {{flight-api}}/api/v1/flight/create
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"flightNumber": "1288",
"price": 800,
"flightStatus": 1,
"flightDate": "2023-12-12T13:12:42.515Z",
"departureDate": "2023-12-12T13:12:42.515Z",
"departureAirportId": 1,
"aircraftId": 1,
"arriveDate": "2023-12-12T13:12:42.515Z",
"arriveAirportId": 2,
"durationMinutes": 120
}
###


################################# Passenger API #################################

###
# @name ApiRoot_Passenger
GET {{passenger-api}}
###

###
# @name Get_All_Passenger
GET {{passenger-api}}/api/v1/passenger/get-all?pageSize=20&page=1&order=DESC
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}
###


###
# @name Get_Passenger_By_Id
GET {{passenger-api}}/api/v1/passenger/get-by-id?id=1
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}
###


################################# Booking API #################################

###
# @name ApiRoot_Booking
GET {{booking-api}}
###


###
# @name Create_Booking
POST {{booking-api}}/api/v1/booking/create
accept: application/json
Content-Type: application/json
authorization: bearer {{Login.response.body.access.token}}

{
"passengerId": 1,
"flightId": 1,
"description": "I want to fly to kish"
}
###
2 changes: 1 addition & 1 deletion src/booking/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PORT=3366
# JWT
JWT_SECRET=thisisafakesecretchangeit
JWT_ACCESS_EXPIRATION_MINUTES=30
JWT_REFRESH_EXPIRATION_DAYS=1 days
JWT_REFRESH_EXPIRATION_DAYS=1

# Postgress
POSTGRES_HOST=localhost
Expand Down
2 changes: 0 additions & 2 deletions src/booking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
"express": "4.18.2",
"express-http-context": "^1.2.4",
"http-problem-details": "^0.1.5",
"lodash": "^4.17.21",
"nest-shared": "^5.0.3",
Expand All @@ -64,7 +63,6 @@
"rxjs": "^7.8.1",
"swagger-ui-express": "^5.0.0",
"ts-mapper": "^1.2.4",
"tsyringe": "4.8.0",
"typeorm": "^0.3.17",
"yup": "1.3.2"
},
Expand Down
11 changes: 9 additions & 2 deletions src/booking/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Module, OnApplicationBootstrap} from '@nestjs/common';
import {RouterModule} from '@nestjs/core';
import {TypeOrmModule} from '@nestjs/typeorm';
import {postgresOptions} from './data/data-source';
Expand All @@ -8,6 +7,8 @@ import {OpenTelemetryModule} from "building-blocks/openTelemetry/open-telemetry.
import {JwtStrategy} from "building-blocks/passport/jwt.strategy";
import {BookingModule} from "./booking/booking.module";
import configs from "building-blocks/configs/configs";
import {MiddlewareConsumer, Module, NestModule} from "@nestjs/common";
import {ContextMiddleware} from "building-blocks/context/context";

@Module({
imports: [
Expand All @@ -28,4 +29,10 @@ import configs from "building-blocks/configs/configs";
],
providers: [JwtStrategy],
})
export class AppModule {}
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(ContextMiddleware)
.forRoutes('*');
}
}
2 changes: 1 addition & 1 deletion src/booking/src/booking/booking.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {CqrsModule} from '@nestjs/cqrs';
import {TypeOrmModule} from '@nestjs/typeorm';
import {RabbitmqModule} from "building-blocks/rabbitmq/rabbitmq.module";
import {Booking} from "./entities/booking.entity";
import {CreateBookingController, CreateBookingHandler} from "./features/v1/create-booking/create-booking";
import {BookingRepository} from "../data/repositories/booking.repository";
import {PassengerClient} from "./http-client/services/passenger/passenger-client";
import {FlightClient} from "./http-client/services/flight/flight.client";
import {CreateBookingController, CreateBookingHandler} from "./features/v1/create-booking/create-booking";



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class CreateBooking {
}
}


export class CreateBookingRequestDto {
@ApiProperty()
passengerId: number;
Expand Down Expand Up @@ -61,13 +62,7 @@ export class CreateBookingController {
@ApiResponse({status: 403, description: 'FORBIDDEN'})
@ApiResponse({status: 201, description: 'CREATED'})
public async createBooking(@Body() request: CreateBookingRequestDto, @Res() res: Response): Promise<BookingDto> {
const result = await this.commandBus.execute(
new CreateBooking({
flightId: request.flightId,
passengerId: request.passengerId,
description: request.description
})
);
const result = await this.commandBus.execute(new CreateBooking(request));

res.status(HttpStatus.CREATED).send(result);

Expand All @@ -77,21 +72,24 @@ export class CreateBookingController {

@CommandHandler(CreateBooking)
export class CreateBookingHandler implements ICommandHandler<CreateBooking> {

constructor(
private readonly commandBus: CommandBus,
@Inject('IBookingRepository') private bookingRepository: IBookingRepository,
@Inject('IFlightClient') private flightClient: IFlightClient,
@Inject('IPassengerClient') private passengerClient: IPassengerClient,
@Inject('IRabbitmqPublisher') private rabbitmqPublisher: IRabbitmqPublisher
) {}

async execute(request: CreateBooking): Promise<BookingDto> {
await createBookingValidations.validateAsync(request);
async execute(command: CreateBooking): Promise<BookingDto> {

const flightDto = await this.flightClient.getFlightById(request.flightId);
await createBookingValidations.validateAsync(command);

const passengerDto = await this.passengerClient.getPassengerById(request.passengerId);
const flightDto = await this.flightClient.getFlightById(command.flightId);

const avalibaleSeats = await this.flightClient.getAvalibaleSeats(request.flightId);
const passengerDto = await this.passengerClient.getPassengerById(command.passengerId);

const avalibaleSeats = await this.flightClient.getAvalibaleSeats(command.flightId);

if (avalibaleSeats.length == 0) {
throw new NotFoundException('No seat available!');
Expand All @@ -108,7 +106,7 @@ export class CreateBookingHandler implements ICommandHandler<CreateBooking> {
flightNumber: flightDto?.flightNumber,
price: flightDto?.price,
passengerName: passengerDto?.name,
description: request?.description,
description: command?.description,
flightDate: flightDto?.flightDate,
aircraftId: flightDto?.aircraftId,
departureAirportId: flightDto?.departureAirportId,
Expand All @@ -121,5 +119,6 @@ export class CreateBookingHandler implements ICommandHandler<CreateBooking> {
const result = mapper.map<Booking, BookingDto>(bookingEntity, new BookingDto());

return result;

}
}
}
Loading

0 comments on commit 8855f4f

Please sign in to comment.