mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-10 17:59:38 +08:00
refactor: refactor structure of project
This commit is contained in:
parent
c33eaf4d07
commit
2e02f1b3bf
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
@ -25,8 +25,8 @@ jobs:
|
||||
if: success()
|
||||
id: build-test-flight-step
|
||||
with:
|
||||
project-path: '3-microservices-architecture-style/src/Services/Flight/src/Flight.Api'
|
||||
tests-path: '3-microservices-architecture-style/src/Services/Flight/tests/'
|
||||
project-path: 'src/Services/Flight/src/Flight.Api'
|
||||
tests-path: 'src/Services/Flight/tests/'
|
||||
# wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory
|
||||
# https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/
|
||||
# https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not
|
||||
@ -40,8 +40,8 @@ jobs:
|
||||
if: success()
|
||||
id: build-test-identity-step
|
||||
with:
|
||||
project-path: '3-microservices-architecture-style/src/Services/Identity/src/Identity.Api'
|
||||
tests-path: '3-microservices-architecture-style/src/Services/Identity/tests/'
|
||||
project-path: 'src/Services/Identity/src/Identity.Api'
|
||||
tests-path: 'src/Services/Identity/tests/'
|
||||
# wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory
|
||||
# https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/
|
||||
# https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not
|
||||
@ -55,8 +55,8 @@ jobs:
|
||||
if: success()
|
||||
id: build-test-passenger-step
|
||||
with:
|
||||
project-path: '3-microservices-architecture-style/src/Services/Passenger/src/Passenger.Api'
|
||||
tests-path: '3-microservices-architecture-style/src/Services/Passenger/tests/'
|
||||
project-path: 'src/Services/Passenger/src/Passenger.Api'
|
||||
tests-path: 'src/Services/Passenger/tests/'
|
||||
# wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory
|
||||
# https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/
|
||||
# https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not
|
||||
@ -70,8 +70,8 @@ jobs:
|
||||
if: success()
|
||||
id: build-test-booking-step
|
||||
with:
|
||||
project-path: '3-microservices-architecture-style/src/Services/Booking/src/Booking.Api'
|
||||
tests-path: '3-microservices-architecture-style/src/Services/Booking/tests/'
|
||||
project-path: 'src/Services/Booking/src/Booking.Api'
|
||||
tests-path: 'src/Services/Booking/tests/'
|
||||
# wildcard search for files with the ".cobertura.xml" extension in all subdirectories of the current directory
|
||||
# https://www.jamescroft.co.uk/combining-multiple-code-coverage-results-in-azure-devops/
|
||||
# https://stackoverflow.com/questions/53255065/dotnet-unit-test-with-coverlet-how-to-get-coverage-for-entire-solution-and-not
|
||||
@ -98,7 +98,7 @@ jobs:
|
||||
tag-name: ${{ steps.last_release.outputs.tag_name }}
|
||||
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
registry-password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
dockerfile-path: '3-microservices-architecture-style/src/Services/Identity/Dockerfile'
|
||||
dockerfile-path: 'src/Services/Identity/Dockerfile'
|
||||
image-name: 'booking-microservices-identity'
|
||||
|
||||
- name: Build and Publish Flight Microservice to Docker
|
||||
@ -108,7 +108,7 @@ jobs:
|
||||
tag-name: ${{ steps.last_release.outputs.tag_name }}
|
||||
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
registry-password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
dockerfile-path: '3-microservices-architecture-style/src/Services/Flight/Dockerfile'
|
||||
dockerfile-path: 'src/Services/Flight/Dockerfile'
|
||||
image-name: 'booking-microservices-flight'
|
||||
|
||||
- name: Build and Publish Passenger Microservice to Docker
|
||||
@ -118,7 +118,7 @@ jobs:
|
||||
tag-name: ${{ steps.last_release.outputs.tag_name }}
|
||||
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
registry-password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
dockerfile-path: '3-microservices-architecture-style/src/Services/Passenger/Dockerfile'
|
||||
dockerfile-path: 'src/Services/Passenger/Dockerfile'
|
||||
image-name: 'booking-microservices-passenger'
|
||||
|
||||
- name: Build and Publish Booking Microservice to Docker
|
||||
@ -128,5 +128,5 @@ jobs:
|
||||
tag-name: ${{ steps.last_release.outputs.tag_name }}
|
||||
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
registry-password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
dockerfile-path: '3-microservices-architecture-style/src/Services/Booking/Dockerfile'
|
||||
dockerfile-path: 'src/Services/Booking/Dockerfile'
|
||||
image-name: 'booking-microservices-booking'
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
# 🪁 Monolith Architecture Style
|
||||
|
||||
> In **Monolith Architecture**, the entire application is built as a single, tightly coupled unit. All components (e.g., Api, business logic, and data access) are part of the same codebase and deployed together.
|
||||
|
||||
# Table of Contents
|
||||
|
||||
- [Key Features](#key-features)
|
||||
- [When to Use](#when-to-use)
|
||||
- [Challenges](#challenges)
|
||||
- [Monolith Architecture Design](#monolith-architecture-design)
|
||||
- [Development Setup](#development-setup)
|
||||
- [Dotnet Tools Packages](#dotnet-tools-packages)
|
||||
- [Husky](#husky)
|
||||
- [Upgrade Nuget Packages](#upgrade-nuget-packages)
|
||||
- [How to Run](#how-to-run)
|
||||
- [Docker Compose](#docker-compose)
|
||||
- [Build](#build)
|
||||
- [Run](#run)
|
||||
- [Test](#test)
|
||||
- [Documentation Apis](#documentation-apis)
|
||||
|
||||
|
||||
## Key Features
|
||||
1. **Single Codebase**: All components (UI, business logic, data access) are part of one project.
|
||||
2. **Tight Coupling**: Components are highly dependent on each other, making changes riskier.
|
||||
3. **Simple Deployment**: The entire application is deployed as a single unit.
|
||||
4. **Centralized Database**: Typically uses a single database for all data storage and access.
|
||||
|
||||
|
||||
## When to Use
|
||||
1. **Small to Medium Projects**: Ideal for applications with limited complexity and scope.
|
||||
2. **Rapid Development**: Suitable for projects requiring quick development and deployment.
|
||||
3. **Small Teams**: Works well for small teams with limited resources.
|
||||
4. **Low Scalability Needs**: Best for applications with predictable and low traffic.
|
||||
|
||||
|
||||
## Challenges
|
||||
- Harder to maintain as the codebase grows.
|
||||
- Limited scalability (scaling requires scaling the entire application).
|
||||
- Difficult to adopt new technologies incrementally.
|
||||
|
||||
## Monolith Architecture Design
|
||||
|
||||

|
||||
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Dotnet Tools Packages
|
||||
For installing our requirement packages with .NET cli tools, we need to install `dotnet tool manifest`.
|
||||
```bash
|
||||
dotnet new tool-manifest
|
||||
```
|
||||
And after that we can restore our dotnet tools packages with .NET cli tools from `.config` folder and `dotnet-tools.json` file.
|
||||
```
|
||||
dotnet tool restore
|
||||
```
|
||||
|
||||
### Husky
|
||||
Here we use `husky` to handel some pre commit rules and we used `conventional commits` rules and `formatting` as pre commit rules, here in [package.json](.././package.json). of course, we can add more rules for pre commit in future. (find more about husky in the [documentation](https://typicode.github.io/husky/get-started.html))
|
||||
We need to install `husky` package for `manage` `pre commits hooks` and also I add two packages `@commitlint/cli` and `@commitlint/config-conventional` for handling conventional commits rules in [package.json](.././package.json).
|
||||
Run the command bellow in the root of project to install all npm dependencies related to husky:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
> Note: In the root of project we have `.husky` folder and it has `commit-msg` file for handling conventional commits rules with provide user friendly message and `pre-commit` file that we can run our `scripts` as a `pre-commit` hooks. that here we call `format` script from [package.json](./package.json) for formatting purpose.
|
||||
|
||||
### Upgrade Nuget Packages
|
||||
For upgrading our nuget packages to last version, we use the great package [dotnet-outdated](https://github.com/dotnet-outdated/dotnet-outdated).
|
||||
Run the command below in the root of project to upgrade all of packages to last version:
|
||||
```bash
|
||||
dotnet outdated -u
|
||||
```
|
||||
|
||||
## How to Run
|
||||
|
||||
> ### Docker Compose
|
||||
|
||||
To run this app in `Docker`, use the [docker-compose.yaml](./deployments/docker-compose/docker-compose.yaml) and execute the below command at the `root` of the application:
|
||||
|
||||
```bash
|
||||
docker-compose -f ./deployments/docker-compose/docker-compose.yaml up -d
|
||||
```
|
||||
|
||||
> ### Build
|
||||
To `build` monolith app, run this command in the `root` of the project:
|
||||
```bash
|
||||
dotnet build
|
||||
```
|
||||
|
||||
> ### Run
|
||||
To `run` monolith app, run this command in the root of the `Api` folder where the `csproj` file is located:
|
||||
```bash
|
||||
dotnet run
|
||||
```
|
||||
|
||||
> ### Test
|
||||
|
||||
To `test` monolith app, run this command in the `root` of the project:
|
||||
```bash
|
||||
dotnet test
|
||||
```
|
||||
|
||||
> ### Documentation Apis
|
||||
|
||||
Each microservice provides `API documentation` and navigate to `/swagger` for `Swagger OpenAPI` or `/scalar/v1` for `Scalar OpenAPI` to visit list of endpoints.
|
||||
|
||||
As part of API testing, I created the [booking.rest](./booking.rest) file which can be run with the [REST Client](https://github.com/Huachao/vscode-restclient) `VSCode plugin`.
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 391 KiB |
@ -1,230 +0,0 @@
|
||||
|
||||
@booking-monolith-api=https://localhost:4000
|
||||
|
||||
@contentType = application/json
|
||||
@flightid = "3c5c0000-97c6-fc34-2eb9-08db322230c9"
|
||||
@passengerId = "8c9c0000-97c6-fc34-2eb9-66db322230c9"
|
||||
|
||||
################################# Identity API #################################
|
||||
|
||||
###
|
||||
# @name Authenticate
|
||||
POST {{booking-monolith-api}}/connect/token
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
grant_type=password
|
||||
&client_id=client
|
||||
&client_secret=secret
|
||||
&username=samh
|
||||
&password=Admin@123456
|
||||
&scope=booking-monolith role
|
||||
###
|
||||
|
||||
|
||||
|
||||
###
|
||||
# @name Register_New_User
|
||||
POST {{booking-monolith-api}}/api/v1/identity/register-user
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"firstName": "John",
|
||||
"lastName": "Do",
|
||||
"username": "admin",
|
||||
"passportNumber": "41290000",
|
||||
"email": "admin@admin.com",
|
||||
"password": "Admin@12345",
|
||||
"confirmPassword": "Admin@12345"
|
||||
}
|
||||
###
|
||||
|
||||
################################# Flight API #################################
|
||||
|
||||
###
|
||||
# @name Create_Seat
|
||||
Post {{booking-monolith-api}}/api/v1/flight/seat
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"seatNumber": "1255",
|
||||
"type": 1,
|
||||
"class": 1,
|
||||
"flightId": "3c5c0000-97c6-fc34-2eb9-08db322230c9"
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Reserve_Seat
|
||||
Post {{booking-monolith-api}}/api/v1/flight/reserve-seat
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"flightId": "3c5c0000-97c6-fc34-2eb9-08db322230c9",
|
||||
"seatNumber": "1255"
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Get_Available_Seats
|
||||
GET {{booking-monolith-api}}/api/v1/flight/get-available-seats/{{flightid}}
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Get_Flight_By_Id
|
||||
GET {{booking-monolith-api}}/api/v1/flight/{{flightid}}
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Get_Available_Flights
|
||||
GET {{booking-monolith-api}}/api/v1/flight/get-available-flights
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Create_Flights
|
||||
POST {{booking-monolith-api}}/api/v1/flight
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"flightNumber": "12BB",
|
||||
"aircraftId": "3c5c0000-97c6-fc34-fcd3-08db322230c8",
|
||||
"departureAirportId": "3c5c0000-97c6-fc34-a0cb-08db322230c8",
|
||||
"departureDate": "2022-03-01T14:55:41.255Z",
|
||||
"arriveDate": "2022-03-01T14:55:41.255Z",
|
||||
"arriveAirportId": "3c5c0000-97c6-fc34-fc3c-08db322230c8",
|
||||
"durationMinutes": 120,
|
||||
"flightDate": "2022-03-01T14:55:41.255Z",
|
||||
"status": 1,
|
||||
"price": 8000
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Update_Flights
|
||||
PUT {{booking-monolith-api}}/api/v1/flight
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"flightNumber": "BD467",
|
||||
"aircraftId": "3c5c0000-97c6-fc34-fcd3-08db322230c8",
|
||||
"departureAirportId": "3c5c0000-97c6-fc34-a0cb-08db322230c8",
|
||||
"departureDate": "2022-04-23T12:17:45.140Z",
|
||||
"arriveDate": "2022-04-23T12:17:45.140Z",
|
||||
"arriveAirportId": "3c5c0000-97c6-fc34-fc3c-08db322230c8",
|
||||
"durationMinutes": 120,
|
||||
"flightDate": "2022-04-23T12:17:45.140Z",
|
||||
"status": 4,
|
||||
"isDeleted": false,
|
||||
"price": 99000
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Delete_Flights
|
||||
DELETE {{booking-monolith-api}}/api/v1/flight/{{flightid}}
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Create_Airport
|
||||
POST {{booking-monolith-api}}/api/v1/flight/airport
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"name": "mehrabad",
|
||||
"address": "tehran",
|
||||
"code": "12YD"
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
|
||||
###
|
||||
# @name Create_Aircraft
|
||||
POST {{booking-monolith-api}}/api/v1/flight/aircraft
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"name": "airbus2",
|
||||
"model": "322",
|
||||
"manufacturingYear": 2012
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
################################# Passenger API #################################
|
||||
|
||||
|
||||
###
|
||||
# @name Complete_Registration_Passenger
|
||||
POST {{booking-monolith-api}}/api/v1/passenger/complete-registration
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"passportNumber": "41290000",
|
||||
"passengerType": 1,
|
||||
"age": 30
|
||||
}
|
||||
###
|
||||
|
||||
|
||||
###
|
||||
# @name Get_Passenger_By_Id
|
||||
GET {{booking-monolith-api}}/api/v1/passenger/{{passengerId}}
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
###
|
||||
|
||||
|
||||
################################# Booking API #################################
|
||||
|
||||
|
||||
###
|
||||
# @name Create_Booking
|
||||
POST {{booking-monolith-api}}/api/v1/booking
|
||||
accept: application/json
|
||||
Content-Type: application/json
|
||||
authorization: bearer {{Authenticate.response.body.access_token}}
|
||||
|
||||
{
|
||||
"passengerId": "8c9c0000-97c6-fc34-2eb9-66db322230c9",
|
||||
"flightId": "3c5c0000-97c6-fc34-2eb9-08db322230c9",
|
||||
"description": "I want to fly to iran"
|
||||
}
|
||||
###
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,892 +0,0 @@
|
||||
{
|
||||
"__inputs": [],
|
||||
"__requires": [
|
||||
{
|
||||
"type": "grafana",
|
||||
"id": "grafana",
|
||||
"name": "Grafana",
|
||||
"version": "7.4.3"
|
||||
},
|
||||
{
|
||||
"type": "panel",
|
||||
"id": "graph",
|
||||
"name": "Graph",
|
||||
"version": ""
|
||||
},
|
||||
{
|
||||
"type": "datasource",
|
||||
"id": "prometheus",
|
||||
"name": "Prometheus",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
],
|
||||
"annotations": {
|
||||
"list": []
|
||||
},
|
||||
"editable": false,
|
||||
"gnetId": 13978,
|
||||
"graphTooltip": 0,
|
||||
"hideControls": false,
|
||||
"id": null,
|
||||
"links": [],
|
||||
"refresh": "",
|
||||
"rows": [
|
||||
{
|
||||
"collapse": false,
|
||||
"collapsed": false,
|
||||
"panels": [
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 1,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 2,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"span": 6,
|
||||
"stack": true,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "(\n (1 - rate(node_cpu_seconds_total{job=\"node\", mode=\"idle\", instance=\"$instance\"}[$__interval]))\n/ ignoring(cpu) group_left\n count without (cpu)( node_cpu_seconds_total{job=\"node\", mode=\"idle\", instance=\"$instance\"})\n)\n",
|
||||
"format": "time_series",
|
||||
"interval": "1m",
|
||||
"intervalFactor": 5,
|
||||
"legendFormat": "{{cpu}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "CPU Usage",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "percentunit",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": 1,
|
||||
"min": 0,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "percentunit",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": 1,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 0,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 3,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"span": 6,
|
||||
"stack": false,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "node_load1{job=\"node\", instance=\"$instance\"}",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "1m load average",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "node_load5{job=\"node\", instance=\"$instance\"}",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "5m load average",
|
||||
"refId": "B"
|
||||
},
|
||||
{
|
||||
"expr": "node_load15{job=\"node\", instance=\"$instance\"}",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "15m load average",
|
||||
"refId": "C"
|
||||
},
|
||||
{
|
||||
"expr": "count(node_cpu_seconds_total{job=\"node\", instance=\"$instance\", mode=\"idle\"})",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "logical cores",
|
||||
"refId": "D"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "Load Average",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "short",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "short",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repeat": null,
|
||||
"repeatIteration": null,
|
||||
"repeatRowId": null,
|
||||
"showTitle": false,
|
||||
"title": "Dashboard Row",
|
||||
"titleSize": "h6",
|
||||
"type": "row"
|
||||
},
|
||||
{
|
||||
"collapse": false,
|
||||
"collapsed": false,
|
||||
"panels": [
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 1,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 4,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"span": 9,
|
||||
"stack": true,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "(\n node_memory_MemTotal_bytes{job=\"node\", instance=\"$instance\"}\n-\n node_memory_MemFree_bytes{job=\"node\", instance=\"$instance\"}\n-\n node_memory_Buffers_bytes{job=\"node\", instance=\"$instance\"}\n-\n node_memory_Cached_bytes{job=\"node\", instance=\"$instance\"}\n)\n",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "memory used",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "node_memory_Buffers_bytes{job=\"node\", instance=\"$instance\"}",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "memory buffers",
|
||||
"refId": "B"
|
||||
},
|
||||
{
|
||||
"expr": "node_memory_Cached_bytes{job=\"node\", instance=\"$instance\"}",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "memory cached",
|
||||
"refId": "C"
|
||||
},
|
||||
{
|
||||
"expr": "node_memory_MemFree_bytes{job=\"node\", instance=\"$instance\"}",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "memory free",
|
||||
"refId": "D"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "Memory Usage",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cacheTimeout": null,
|
||||
"colorBackground": false,
|
||||
"colorValue": false,
|
||||
"colors": [
|
||||
"rgba(50, 172, 45, 0.97)",
|
||||
"rgba(237, 129, 40, 0.89)",
|
||||
"rgba(245, 54, 54, 0.9)"
|
||||
],
|
||||
"datasource": "$datasource",
|
||||
"format": "percent",
|
||||
"gauge": {
|
||||
"maxValue": 100,
|
||||
"minValue": 0,
|
||||
"show": true,
|
||||
"thresholdLabels": false,
|
||||
"thresholdMarkers": true
|
||||
},
|
||||
"gridPos": {},
|
||||
"id": 5,
|
||||
"interval": null,
|
||||
"links": [],
|
||||
"mappingType": 1,
|
||||
"mappingTypes": [
|
||||
{
|
||||
"name": "value to text",
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"name": "range to text",
|
||||
"value": 2
|
||||
}
|
||||
],
|
||||
"maxDataPoints": 100,
|
||||
"nullPointMode": "connected",
|
||||
"nullText": null,
|
||||
"postfix": "",
|
||||
"postfixFontSize": "50%",
|
||||
"prefix": "",
|
||||
"prefixFontSize": "50%",
|
||||
"rangeMaps": [
|
||||
{
|
||||
"from": "null",
|
||||
"text": "N/A",
|
||||
"to": "null"
|
||||
}
|
||||
],
|
||||
"span": 3,
|
||||
"sparkline": {
|
||||
"fillColor": "rgba(31, 118, 189, 0.18)",
|
||||
"full": false,
|
||||
"lineColor": "rgb(31, 120, 193)",
|
||||
"show": false
|
||||
},
|
||||
"tableColumn": "",
|
||||
"targets": [
|
||||
{
|
||||
"expr": "100 -\n(\n avg(node_memory_MemAvailable_bytes{job=\"node\", instance=\"$instance\"})\n/\n avg(node_memory_MemTotal_bytes{job=\"node\", instance=\"$instance\"})\n* 100\n)\n",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"thresholds": "80, 90",
|
||||
"title": "Memory Usage",
|
||||
"type": "singlestat",
|
||||
"valueFontSize": "80%",
|
||||
"valueMaps": [
|
||||
{
|
||||
"op": "=",
|
||||
"text": "N/A",
|
||||
"value": "null"
|
||||
}
|
||||
],
|
||||
"valueName": "current"
|
||||
}
|
||||
],
|
||||
"repeat": null,
|
||||
"repeatIteration": null,
|
||||
"repeatRowId": null,
|
||||
"showTitle": false,
|
||||
"title": "Dashboard Row",
|
||||
"titleSize": "h6",
|
||||
"type": "row"
|
||||
},
|
||||
{
|
||||
"collapse": false,
|
||||
"collapsed": false,
|
||||
"panels": [
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 0,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 6,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [
|
||||
{
|
||||
"alias": "/ read| written/",
|
||||
"yaxis": 1
|
||||
},
|
||||
{
|
||||
"alias": "/ io time/",
|
||||
"yaxis": 2
|
||||
}
|
||||
],
|
||||
"spaceLength": 10,
|
||||
"span": 6,
|
||||
"stack": false,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(node_disk_read_bytes_total{job=\"node\", instance=\"$instance\", device!=\"\"}[$__interval])",
|
||||
"format": "time_series",
|
||||
"interval": "1m",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "{{device}} read",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "rate(node_disk_written_bytes_total{job=\"node\", instance=\"$instance\", device!=\"\"}[$__interval])",
|
||||
"format": "time_series",
|
||||
"interval": "1m",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "{{device}} written",
|
||||
"refId": "B"
|
||||
},
|
||||
{
|
||||
"expr": "rate(node_disk_io_time_seconds_total{job=\"node\", instance=\"$instance\", device!=\"\"}[$__interval])",
|
||||
"format": "time_series",
|
||||
"interval": "1m",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "{{device}} io time",
|
||||
"refId": "C"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "Disk I/O",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": null,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "s",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": null,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 1,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 7,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [
|
||||
{
|
||||
"alias": "used",
|
||||
"color": "#E0B400"
|
||||
},
|
||||
{
|
||||
"alias": "available",
|
||||
"color": "#73BF69"
|
||||
}
|
||||
],
|
||||
"spaceLength": 10,
|
||||
"span": 6,
|
||||
"stack": true,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "sum(\n max by (device) (\n node_filesystem_size_bytes{job=\"node\", instance=\"$instance\", fstype!=\"\"}\n -\n node_filesystem_avail_bytes{job=\"node\", instance=\"$instance\", fstype!=\"\"}\n )\n)\n",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "used",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"expr": "sum(\n max by (device) (\n node_filesystem_avail_bytes{job=\"node\", instance=\"$instance\", fstype!=\"\"}\n )\n)\n",
|
||||
"format": "time_series",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "available",
|
||||
"refId": "B"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "Disk Space Usage",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repeat": null,
|
||||
"repeatIteration": null,
|
||||
"repeatRowId": null,
|
||||
"showTitle": false,
|
||||
"title": "Dashboard Row",
|
||||
"titleSize": "h6",
|
||||
"type": "row"
|
||||
},
|
||||
{
|
||||
"collapse": false,
|
||||
"collapsed": false,
|
||||
"panels": [
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 0,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 8,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"span": 6,
|
||||
"stack": false,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(node_network_receive_bytes_total{job=\"node\", instance=\"$instance\", device!=\"lo\"}[$__interval])",
|
||||
"format": "time_series",
|
||||
"interval": "1m",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "{{device}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "Network Received",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"aliasColors": {},
|
||||
"bars": false,
|
||||
"dashLength": 10,
|
||||
"dashes": false,
|
||||
"datasource": "$datasource",
|
||||
"fill": 0,
|
||||
"fillGradient": 0,
|
||||
"gridPos": {},
|
||||
"id": 9,
|
||||
"legend": {
|
||||
"alignAsTable": false,
|
||||
"avg": false,
|
||||
"current": false,
|
||||
"max": false,
|
||||
"min": false,
|
||||
"rightSide": false,
|
||||
"show": true,
|
||||
"sideWidth": null,
|
||||
"total": false,
|
||||
"values": false
|
||||
},
|
||||
"lines": true,
|
||||
"linewidth": 1,
|
||||
"links": [],
|
||||
"nullPointMode": "null",
|
||||
"percentage": false,
|
||||
"pointradius": 5,
|
||||
"points": false,
|
||||
"renderer": "flot",
|
||||
"repeat": null,
|
||||
"seriesOverrides": [],
|
||||
"spaceLength": 10,
|
||||
"span": 6,
|
||||
"stack": false,
|
||||
"steppedLine": false,
|
||||
"targets": [
|
||||
{
|
||||
"expr": "rate(node_network_transmit_bytes_total{job=\"node\", instance=\"$instance\", device!=\"lo\"}[$__interval])",
|
||||
"format": "time_series",
|
||||
"interval": "1m",
|
||||
"intervalFactor": 2,
|
||||
"legendFormat": "{{device}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"thresholds": [],
|
||||
"timeFrom": null,
|
||||
"timeShift": null,
|
||||
"title": "Network Transmitted",
|
||||
"tooltip": {
|
||||
"shared": true,
|
||||
"sort": 0,
|
||||
"value_type": "individual"
|
||||
},
|
||||
"type": "graph",
|
||||
"xaxis": {
|
||||
"buckets": null,
|
||||
"mode": "time",
|
||||
"name": null,
|
||||
"show": true,
|
||||
"values": []
|
||||
},
|
||||
"yaxes": [
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"format": "bytes",
|
||||
"label": null,
|
||||
"logBase": 1,
|
||||
"max": null,
|
||||
"min": 0,
|
||||
"show": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"repeat": null,
|
||||
"repeatIteration": null,
|
||||
"repeatRowId": null,
|
||||
"showTitle": false,
|
||||
"title": "Dashboard Row",
|
||||
"titleSize": "h6",
|
||||
"type": "row"
|
||||
}
|
||||
],
|
||||
"schemaVersion": 14,
|
||||
"style": "dark",
|
||||
"tags": [],
|
||||
"templating": {
|
||||
"list": [
|
||||
{
|
||||
"current": {
|
||||
"text": "Prometheus",
|
||||
"value": "Prometheus"
|
||||
},
|
||||
"hide": 0,
|
||||
"label": null,
|
||||
"name": "datasource",
|
||||
"options": [],
|
||||
"query": "prometheus",
|
||||
"refresh": 1,
|
||||
"regex": "",
|
||||
"type": "datasource"
|
||||
},
|
||||
{
|
||||
"allValue": null,
|
||||
"current": {},
|
||||
"datasource": "$datasource",
|
||||
"hide": 0,
|
||||
"includeAll": false,
|
||||
"label": null,
|
||||
"multi": false,
|
||||
"name": "instance",
|
||||
"options": [],
|
||||
"query": "label_values(node_exporter_build_info{job=\"node\"}, instance)",
|
||||
"refresh": 2,
|
||||
"regex": "",
|
||||
"sort": 0,
|
||||
"tagValuesQuery": "",
|
||||
"tags": [],
|
||||
"tagsQuery": "",
|
||||
"type": "query",
|
||||
"useTags": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"time": {
|
||||
"from": "now-1h",
|
||||
"to": "now"
|
||||
},
|
||||
"timepicker": {
|
||||
"refresh_intervals": [
|
||||
"5s",
|
||||
"10s",
|
||||
"30s",
|
||||
"1m",
|
||||
"5m",
|
||||
"15m",
|
||||
"30m",
|
||||
"1h",
|
||||
"2h",
|
||||
"1d"
|
||||
],
|
||||
"time_options": [
|
||||
"5m",
|
||||
"15m",
|
||||
"1h",
|
||||
"6h",
|
||||
"12h",
|
||||
"24h",
|
||||
"2d",
|
||||
"7d",
|
||||
"30d"
|
||||
]
|
||||
},
|
||||
"timezone": "browser",
|
||||
"title": "Node Exporter Quickstart and Dashboard",
|
||||
"version": 0,
|
||||
"description": "A quickstart to setup Prometheus Node Exporter with preconfigured dashboards, alerting rules, and recording rules."
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
||||
# https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards
|
||||
apiVersion: 1
|
||||
|
||||
providers:
|
||||
- name: "default"
|
||||
orgId: 1
|
||||
folder: ""
|
||||
type: file
|
||||
disableDeletion: false
|
||||
editable: true
|
||||
allowUiUpdates: true
|
||||
updateIntervalSeconds: 5 # how often Grafana will scan for changed dashboards
|
||||
options:
|
||||
path: /var/lib/grafana/dashboards # path to dashboards on disk
|
||||
@ -1,88 +0,0 @@
|
||||
# https://grafana.com/docs/grafana/latest/administration/provisioning/
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/shared/grafana-datasources.yaml
|
||||
# https://github.com/grafana/intro-to-mltp/blob/main/grafana/provisioning/datasources/datasources.yaml
|
||||
|
||||
apiVersion: 1
|
||||
|
||||
datasources:
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/shared/grafana-datasources.yaml
|
||||
- name: Prometheus
|
||||
type: prometheus
|
||||
typeName: Prometheus
|
||||
uid: prometheus-uid
|
||||
access: proxy
|
||||
orgId: 1
|
||||
url: http://prometheus:9090
|
||||
basicAuth: false
|
||||
isDefault: true
|
||||
readOnly: false
|
||||
user: ''
|
||||
database: ''
|
||||
version: 1
|
||||
editable: false
|
||||
jsonData:
|
||||
httpMethod: GET
|
||||
|
||||
- name: Jaeger
|
||||
type: jaeger
|
||||
access: proxy
|
||||
url: http://jaeger-all-in-one:16686
|
||||
editable: false
|
||||
uid: jaeger-uid
|
||||
|
||||
- name: Zipkin
|
||||
type: zipkin
|
||||
access: proxy
|
||||
url: http://zipkin-all-in-one:9411
|
||||
editable: false
|
||||
uid: zipkin-uid
|
||||
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/shared/grafana-datasources.yaml
|
||||
- name: Tempo
|
||||
type: tempo
|
||||
access: proxy
|
||||
orgId: 1
|
||||
url: http://tempo:3200
|
||||
basicAuth: false
|
||||
isDefault: false
|
||||
version: 1
|
||||
editable: false
|
||||
apiVersion: 1
|
||||
uid: tempo-uid
|
||||
jsonData:
|
||||
httpMethod: GET
|
||||
serviceMap:
|
||||
datasourceUid: prometheus-uid
|
||||
streamingEnabled:
|
||||
search: true
|
||||
|
||||
#https://github.com/grafana/intro-to-mltp/blob/main/grafana/provisioning/datasources/datasources.yaml
|
||||
- name: Loki
|
||||
type: loki
|
||||
access: proxy
|
||||
uid: loki-uid
|
||||
url: http://loki:3100
|
||||
user: ''
|
||||
database: ''
|
||||
readOnly: false
|
||||
jsonData:
|
||||
derivedFields:
|
||||
- datasourceUid: tempo-uid
|
||||
matcherRegex: "^.*?traceI[d|D]=(\\w+).*$"
|
||||
name: traceId
|
||||
url: '$${__value.raw}'
|
||||
|
||||
- name: Kibana
|
||||
type: elasticsearch
|
||||
url: http://elasticsearch:9200
|
||||
access: proxy
|
||||
isDefault: false
|
||||
uid: kibana-uid
|
||||
jsonData:
|
||||
esVersion: 7
|
||||
timeField: "@timestamp"
|
||||
maxConcurrentShardRequests: 256
|
||||
interval: Daily
|
||||
logMessageField: "message" # Optional: Field for log messages
|
||||
logLevelField: "level" # Optional: Field for log levels
|
||||
editable: true
|
||||
@ -1,131 +0,0 @@
|
||||
# ref: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/examples/demo/otel-collector-config.yaml
|
||||
# https://opentelemetry.io/docs/collector/configuration/
|
||||
# https://opentelemetry.io/docs/collector/architecture/
|
||||
# https://betterstack.com/community/guides/observability/opentelemetry-collector/
|
||||
# https://signoz.io/blog/opentelemetry-collector-complete-guide/
|
||||
|
||||
# This configuration sets up an OpenTelemetry Collector that receives trace data via the OTLP protocol over HTTP on port 4318, applies batch processing, and then exports the processed traces
|
||||
# to exporter components like `Jaeger` endpoint located at `jaeger-all-in-one:4317`. It also includes a health_check extension for monitoring the collector's status.
|
||||
|
||||
# Receivers in the OpenTelemetry Collector are components that collect telemetry data (traces, metrics, and logs) from various sources, such as instrumented applications or agents.
|
||||
# They act as entry points, converting incoming data into OpenTelemetry's internal format for processing and export.
|
||||
# https://betterstack.com/community/guides/observability/opentelemetry-collector/#exploring-the-opentelemetry-collector-components
|
||||
# https://opentelemetry.io/docs/collector/architecture/#receivers
|
||||
# https://github.com/open-telemetry/opentelemetry-collector/blob/main/receiver/README.md
|
||||
# https://opentelemetry.io/docs/collector/configuration/#receivers
|
||||
receivers:
|
||||
# supported receivers
|
||||
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver
|
||||
# instead of specifying details explicitly we can just use `otlp` and it uses both grpc and http
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: 0.0.0.0:4317
|
||||
http:
|
||||
endpoint: 0.0.0.0:4318
|
||||
# prometheus:
|
||||
# config:
|
||||
# scrape_configs:
|
||||
# - job_name: 'node-exporter'
|
||||
# scrape_interval: 10s
|
||||
# static_configs:
|
||||
# - targets: [ 'node-exporter:9100' ]
|
||||
|
||||
|
||||
# Processors in the OpenTelemetry Collector modify and enhance telemetry data by filtering, transforming, enriching, or batching it to prepare it for export.
|
||||
# https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor
|
||||
processors:
|
||||
batch: # Batches logs for better performance
|
||||
|
||||
# - Exporters in the OpenTelemetry Collector send processed telemetry data to backend systems like observability platforms, databases, or cloud services for storage, visualization, and analysis.
|
||||
# - The `key` follows the `type/name` format, where `type` specifies the exporter `type` (e.g., otlp, kafka, prometheus), and `name` (optional) can be appended to provide a unique name for multiple instance of the same type
|
||||
# https://betterstack.com/community/guides/observability/opentelemetry-collector/#exploring-the-opentelemetry-collector-components
|
||||
# https://opentelemetry.io/docs/collector/architecture/#exporters
|
||||
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter
|
||||
# https://github.com/open-telemetry/opentelemetry-collector/tree/main/exporter
|
||||
# https://opentelemetry.io/docs/collector/configuration/#exporters
|
||||
exporters:
|
||||
|
||||
# valid values: [prometheusremotewrite zipkin otlphttp file kafka prometheus debug nop otlp opencensus]
|
||||
|
||||
# Prometheus exporter metrics
|
||||
prometheus:
|
||||
endpoint: "0.0.0.0:8889"
|
||||
|
||||
prometheusremotewrite:
|
||||
endpoint: "http://prometheus:9090/api/v1/write"
|
||||
|
||||
# https://grafana.com/docs/loki/latest/send-data/otel/
|
||||
# https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/lokiexporter/README.md
|
||||
otlphttp/loki:
|
||||
endpoint: "http://loki:3100/otlp"
|
||||
tls:
|
||||
insecure: true
|
||||
|
||||
# # we can also use `loki component` from `opentelemetry-collector-contrib` if we don't want to use builtin `otlphttp` exporter type and `http://loki:3100/otlp` loki endpoint
|
||||
# loki:
|
||||
# endpoint: "http://loki:3100/loki/api/v1/push"
|
||||
# tls:
|
||||
# insecure: true
|
||||
|
||||
debug:
|
||||
|
||||
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/elasticsearchexporter
|
||||
# using `elasticsearch` from `opentelemetry-collector-contrib` components because it doesn't exist in `opentelemetry-collector`
|
||||
elasticsearch:
|
||||
endpoint: "http://elasticsearch:9200"
|
||||
|
||||
zipkin:
|
||||
endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
|
||||
format: proto
|
||||
|
||||
# export collected telemetry traces to jaeger OTLP grpc port, we can send data to other available endpoints and ports on jaeger as well
|
||||
otlp/jaeger:
|
||||
endpoint: "http://jaeger-all-in-one:4317"
|
||||
tls:
|
||||
insecure: true
|
||||
|
||||
otlp/tempo:
|
||||
endpoint: "http://tempo:4317"
|
||||
tls:
|
||||
insecure: true
|
||||
|
||||
# seq-otlp:
|
||||
# endpoint: "http://seq:5341/ingest/otlp"
|
||||
|
||||
# https://opentelemetry.io/docs/collector/configuration/#extensions
|
||||
# https://github.com/open-telemetry/opentelemetry-collector/blob/main/extension/README.md
|
||||
extensions:
|
||||
pprof:
|
||||
endpoint: 0.0.0.0:1888
|
||||
zpages:
|
||||
endpoint: 0.0.0.0:55679
|
||||
health_check:
|
||||
endpoint: 0.0.0.0:13133
|
||||
|
||||
# - The service section is used to configure what components are enabled in the Collector based on the configuration found in the receivers, processors, exporters, and extensions sections.
|
||||
# - If a component is configured, but not defined within the service section, then it’s not enabled.
|
||||
# https://betterstack.com/community/guides/observability/opentelemetry-collector/#exploring-the-opentelemetry-collector-components
|
||||
# https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/README.md
|
||||
# https://opentelemetry.io/docs/collector/architecture/
|
||||
# https://opentelemetry.io/docs/collector/configuration/#service
|
||||
service:
|
||||
# The `service.extensions` subsection determines which of the configured extensions will be enabled
|
||||
extensions: [pprof, zpages, health_check]
|
||||
# The `service.pipeline` Each pipeline starts with one or more receivers collecting data, which is then processed sequentially by processors (applying transformations, filtering, or sampling).
|
||||
# The processed data is finally sent to all configured exporters, ensuring each receives a copy. Components must be pre-configured in their respective sections before being used in a pipeline.
|
||||
# pipeline activate predefined components, defined components are disabled by default
|
||||
pipelines:
|
||||
traces:
|
||||
receivers: [otlp]
|
||||
processors: [batch]
|
||||
# https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#exporter-selection
|
||||
exporters: [debug, zipkin, otlp/jaeger, otlp/tempo]
|
||||
metrics:
|
||||
receivers: [otlp]
|
||||
processors: [batch]
|
||||
exporters: [debug, prometheusremotewrite, prometheus]
|
||||
logs:
|
||||
receivers: [otlp]
|
||||
processors: [batch]
|
||||
exporters: [otlphttp/loki, elasticsearch]
|
||||
@ -1,48 +0,0 @@
|
||||
# ref: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/examples/demo/prometheus.yaml
|
||||
# https://prometheus.io/docs/introduction/first_steps/
|
||||
# https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/prometheus-config-examples/docker-compose-linux/
|
||||
|
||||
global:
|
||||
scrape_interval: 5s
|
||||
|
||||
scrape_configs:
|
||||
# when we use otel-collector we should comment other jobs in prometheus config, and we read configs from `otel-collector-config`
|
||||
- job_name: "otel-collector"
|
||||
scrape_interval: 10s
|
||||
static_configs:
|
||||
# otel-collector Prometheus exporter metrics
|
||||
- targets: [ 'otel-collector:8889' ]
|
||||
- targets: [ 'otel-collector:8888' ]
|
||||
|
||||
- job_name: "prometheus"
|
||||
static_configs:
|
||||
- targets: ["prometheus:9090"]
|
||||
|
||||
# # https://prometheus.io/docs/guides/node-exporter/
|
||||
# # https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/prometheus-config-examples/docker-compose-linux/
|
||||
# - job_name: "node-exporter"
|
||||
# static_configs:
|
||||
# - targets: [ 'node-exporter:9100' ]
|
||||
|
||||
# # if we don't use otel collector we should uncomment this
|
||||
# # scrap application metrics
|
||||
# # http://localhost:4000/metrics by AddPrometheusExporter()
|
||||
# - job_name: vertical-slice-template-api
|
||||
# scrape_interval: 10s
|
||||
# metrics_path: /metrics
|
||||
# static_configs:
|
||||
# - targets: ['host.docker.internal:4000']
|
||||
#
|
||||
# # if we don't use otel collector we should uncomment this
|
||||
# # scrap application health metrics
|
||||
# # http://localhost:4000/health/metrics by AddPrometheusExporter()
|
||||
# - job_name: vertical-slice-template-api-healthchecks
|
||||
# scrape_interval: 10s
|
||||
# metrics_path: /health/metrics
|
||||
# static_configs:
|
||||
# - targets: ['host.docker.internal:4000']
|
||||
|
||||
## https://github.com/grafana/tempo/blob/main/example/docker-compose/shared/prometheus.yaml
|
||||
# - job_name: 'tempo'
|
||||
# static_configs:
|
||||
# - targets: [ 'tempo:3200' ]
|
||||
@ -1,49 +0,0 @@
|
||||
# https://grafana.com/docs/tempo/latest/configuration/
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/local/tempo.yaml
|
||||
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/shared/tempo.yaml
|
||||
stream_over_http_enabled: true
|
||||
server:
|
||||
http_listen_port: 3200
|
||||
log_level: info
|
||||
|
||||
distributor:
|
||||
receivers:
|
||||
otlp:
|
||||
protocols:
|
||||
grpc:
|
||||
endpoint: "tempo:4317"
|
||||
|
||||
ingester:
|
||||
max_block_duration: 5m # cut the headblock when this much time passes. this is being set for demo purposes and should probably be left alone normally
|
||||
|
||||
compactor:
|
||||
compaction:
|
||||
block_retention: 1h # overall Tempo trace retention. set for demo purposes
|
||||
|
||||
metrics_generator:
|
||||
registry:
|
||||
external_labels:
|
||||
source: tempo
|
||||
cluster: docker-compose
|
||||
storage:
|
||||
path: /var/tempo/generator/wal
|
||||
remote_write:
|
||||
- url: http://prometheus:9090/api/v1/write
|
||||
send_exemplars: true
|
||||
traces_storage:
|
||||
path: /var/tempo/generator/traces
|
||||
|
||||
storage:
|
||||
trace:
|
||||
backend: local # backend configuration to use
|
||||
wal:
|
||||
path: /var/tempo/wal # where to store the wal locally
|
||||
local:
|
||||
path: /var/tempo/blocks
|
||||
|
||||
overrides:
|
||||
defaults:
|
||||
metrics_generator:
|
||||
processors: [service-graphs, span-metrics, local-blocks] # enables metrics generator
|
||||
generate_native_histograms: both
|
||||
@ -1,361 +0,0 @@
|
||||
# ref: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/examples/demo/docker-compose.yaml
|
||||
# ref: https://github.com/joaofbantunes/DotNetMicroservicesObservabilitySample/blob/main/docker-compose.yml
|
||||
# ref: https://github.com/oskardudycz/EventSourcing.NetCore/blob/main/docker-compose.yml
|
||||
# https://github.com/grafana/intro-to-mltp
|
||||
# https://stackoverflow.com/questions/65272764/ports-are-not-available-listen-tcp-0-0-0-0-50070-bind-an-attempt-was-made-to
|
||||
|
||||
|
||||
name: booking-monolith-infrastructure
|
||||
|
||||
services:
|
||||
#######################################################
|
||||
# rabbitmq
|
||||
#######################################################
|
||||
rabbitmq:
|
||||
image: rabbitmq:management
|
||||
container_name: rabbitmq
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5672:5672"
|
||||
- "15672:15672"
|
||||
# volumes:
|
||||
# - rabbitmq:/var/lib/rabbitmq
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
#######################################################
|
||||
# postgres
|
||||
#######################################################
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
container_name: postgres
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- '5432:5432'
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
command:
|
||||
- "postgres"
|
||||
- "-c"
|
||||
- "wal_level=logical"
|
||||
- "-c"
|
||||
- "max_prepared_transactions=10"
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
#######################################################
|
||||
# EventStoreDB
|
||||
#######################################################
|
||||
eventstore:
|
||||
container_name: eventstore
|
||||
image: eventstore/eventstore:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- EVENTSTORE_CLUSTER_SIZE=1
|
||||
- EVENTSTORE_RUN_PROJECTIONS=All
|
||||
- EVENTSTORE_START_STANDARD_PROJECTIONS=True
|
||||
- EVENTSTORE_HTTP_PORT=2113
|
||||
- EVENTSTORE_INSECURE=True
|
||||
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=True
|
||||
ports:
|
||||
- "2113:2113"
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # Mongo
|
||||
# #######################################################
|
||||
mongo:
|
||||
image: mongo:latest
|
||||
container_name: mongo
|
||||
restart: unless-stopped
|
||||
# environment:
|
||||
# - MONGO_INITDB_ROOT_USERNAME=root
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=secret
|
||||
ports:
|
||||
- 27017:27017
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # Redis
|
||||
# #######################################################
|
||||
redis:
|
||||
image: redis
|
||||
container_name: redis
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 6379:6379
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # jaeger
|
||||
# # https://www.jaegertracing.io/docs/1.64/deployment/
|
||||
# # https://www.jaegertracing.io/docs/1.6/deployment/
|
||||
# #######################################################
|
||||
jaeger-all-in-one:
|
||||
image: jaegertracing/all-in-one:latest
|
||||
container_name: jaeger-all-in-one
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "6831:6831/udp" # UDP port for Jaeger agent
|
||||
- "16686:16686" # endpoints and Jaeger UI
|
||||
- "14268:14268" # HTTP port for accept trace spans directly from clients
|
||||
- "14317:4317" # OTLP gRPC receiver for jaeger
|
||||
- "14318:4318" # OTLP http receiver for jaeger
|
||||
# - "9411" # Accepts Zipkin spans - /api/v2/spans
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # zipkin
|
||||
# # https://zipkin.io/pages/quickstart
|
||||
# #######################################################
|
||||
zipkin-all-in-one:
|
||||
image: openzipkin/zipkin:latest
|
||||
container_name: zipkin-all-in-one
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "9411:9411"
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # otel-collector
|
||||
# # https://opentelemetry.io/docs/collector/installation/
|
||||
# # https://github.com/open-telemetry/opentelemetry-collector
|
||||
# # https://github.com/open-telemetry/opentelemetry-collector-contrib
|
||||
# # we can use none contrib docker `otel/opentelemetry-collector` version from `https://github.com/open-telemetry/opentelemetry-collector` repository but,
|
||||
# # if we need more components like `elasticsearch` we should use `otel/opentelemetry-collector-contrib` image of `https://github.com/open-telemetry/opentelemetry-collector-contrib` repository.
|
||||
# #######################################################
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:latest
|
||||
container_name: otel-collector
|
||||
restart: unless-stopped
|
||||
command: ["--config=/etc/otelcol-contrib/config.yaml"]
|
||||
volumes:
|
||||
- ./../configs/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
|
||||
ports:
|
||||
- "11888:1888" # pprof extension
|
||||
- "8888:8888" # Prometheus metrics exposed by the Collector
|
||||
- "8889:8889" # Prometheus exporter metrics
|
||||
- "13133:13133" # health_check extension
|
||||
- "4317:4317" # OTLP gRPC receiver
|
||||
- "4318:4318" # OTLP http receiver
|
||||
- "55679:55679" # zpages extension
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # prometheus
|
||||
# # https://prometheus.io/docs/introduction/first_steps/
|
||||
# # https://prometheus.io/docs/prometheus/3.1/installation/
|
||||
# # https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/prometheus-config-examples/docker-compose-linux/
|
||||
# #######################################################
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- ./../configs/prometheus.yaml:/etc/prometheus/prometheus.yml
|
||||
# to passe one flag, such as "--log.level=debug" or "--web.enable-remote-write-receiver", we need to override the whole command, as we can't just pass one extra argument
|
||||
command:
|
||||
- "--config.file=/etc/prometheus/prometheus.yml"
|
||||
- "--storage.tsdb.path=/prometheus"
|
||||
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
|
||||
- "--web.console.templates=/usr/share/prometheus/consoles"
|
||||
# need this for the OpenTelemetry collector to be able to put metrics into Prometheus
|
||||
- "--web.enable-remote-write-receiver"
|
||||
# - "--log.level=debug"
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # node-exporter
|
||||
# # https://prometheus.io/docs/guides/node-exporter/
|
||||
# # https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/prometheus-config-examples/docker-compose-linux/
|
||||
# #######################################################
|
||||
node-exporter:
|
||||
image: prom/node-exporter:latest
|
||||
container_name: node-exporter
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /proc:/host/proc:ro
|
||||
- /sys:/host/sys:ro
|
||||
- /:/rootfs:ro
|
||||
command:
|
||||
- '--path.procfs=/host/proc'
|
||||
- '--path.rootfs=/rootfs'
|
||||
- '--path.sysfs=/host/sys'
|
||||
ports:
|
||||
- "9101:9100"
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # grafana
|
||||
# # https://grafana.com/docs/grafana/latest/administration/provisioning/
|
||||
# # https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/
|
||||
# # https://grafana.com/docs/grafana/latest/setup-grafana/configure-docker/
|
||||
# # https://github.com/grafana/intro-to-mltp/blob/main/grafana/provisioning/datasources/datasources.yaml
|
||||
# #######################################################
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
container_name: grafana
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor
|
||||
# - GF_AUTH_ANONYMOUS_ENABLED=true
|
||||
# - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
|
||||
# - GF_AUTH_DISABLE_LOGIN_FORM=true
|
||||
depends_on:
|
||||
- prometheus
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./../configs/grafana/provisioning:/etc/grafana/provisioning
|
||||
- ./../configs/grafana/dashboards:/var/lib/grafana/dashboards
|
||||
## https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/
|
||||
# - ./../configs/grafana/grafana.ini:/etc/grafana/grafana.ini
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # tempo
|
||||
# # https://github.com/grafana/tempo/blob/main/example/docker-compose/otel-collector/docker-compose.yaml
|
||||
# # https://github.com/grafana/tempo/blob/main/example/docker-compose/shared
|
||||
# # https://github.com/grafana/tempo/blob/main/example/docker-compose/local
|
||||
# # https://github.com/grafana/tempo/tree/main/example/docker-compose
|
||||
# #######################################################
|
||||
tempo:
|
||||
image: grafana/tempo:latest
|
||||
container_name: tempo
|
||||
restart: unless-stopped
|
||||
command: [ "-config.file=/etc/tempo.yaml" ]
|
||||
volumes:
|
||||
- ./../configs/tempo.yaml:/etc/tempo.yaml
|
||||
ports:
|
||||
- "3200" # tempo
|
||||
- "24317:4317" # otlp grpc
|
||||
- "24318:4318" # otlp http
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # loki
|
||||
# # https://grafana.com/docs/opentelemetry/collector/send-logs-to-loki/
|
||||
# # https://github.com/grafana/loki/blob/main/production/docker-compose.yaml
|
||||
# # https://github.com/grafana/loki/blob/main/examples/getting-started/docker-compose.yaml
|
||||
# #######################################################
|
||||
loki:
|
||||
image: grafana/loki:latest
|
||||
hostname: loki
|
||||
container_name: loki
|
||||
ports:
|
||||
- "3100:3100"
|
||||
command: -config.file=/etc/loki/local-config.yaml
|
||||
volumes:
|
||||
- ./../configs/loki-config.yaml:/etc/loki/local-config.yaml
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # elasticsearch
|
||||
# # https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docker.html#docker-compose-file
|
||||
# #######################################################
|
||||
elasticsearch:
|
||||
container_name: elasticsearch
|
||||
restart: unless-stopped
|
||||
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
|
||||
environment:
|
||||
- discovery.type=single-node
|
||||
- cluster.name=docker-cluster
|
||||
- node.name=docker-node
|
||||
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
||||
- xpack.security.enabled=false
|
||||
- xpack.security.http.ssl.enabled=false
|
||||
- xpack.security.transport.ssl.enabled=false
|
||||
- network.host=0.0.0.0
|
||||
- http.port=9200
|
||||
- transport.host=localhost
|
||||
- bootstrap.memory_lock=true
|
||||
- cluster.routing.allocation.disk.threshold_enabled=false
|
||||
ulimits:
|
||||
memlock:
|
||||
soft: -1
|
||||
hard: -1
|
||||
volumes:
|
||||
- elastic-data:/usr/share/elasticsearch/data
|
||||
ports:
|
||||
- ${ELASTIC_HOST_PORT:-9200}:${ELASTIC_PORT:-9200}
|
||||
- 9300:9300
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # kibana
|
||||
# # https://www.elastic.co/guide/en/kibana/current/docker.html
|
||||
# #######################################################
|
||||
kibana:
|
||||
image: docker.elastic.co/kibana/kibana:8.17.0
|
||||
container_name: kibana
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
|
||||
ports:
|
||||
- ${KIBANA_HOST_PORT:-5601}:${KIBANA_PORT:-5601}
|
||||
depends_on:
|
||||
- elasticsearch
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
# #######################################################
|
||||
# # cadvisor
|
||||
# #######################################################
|
||||
cadvisor:
|
||||
image: gcr.io/cadvisor/cadvisor:latest
|
||||
container_name: cadvisor
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- /:/rootfs:ro
|
||||
- /var/run:/var/run:ro
|
||||
- /sys:/sys:ro
|
||||
- /var/lib/docker/:/var/lib/docker:ro
|
||||
- /dev/disk/:/dev/disk:ro
|
||||
devices:
|
||||
- /dev/kmsg
|
||||
networks:
|
||||
- infrastructure
|
||||
|
||||
|
||||
networks:
|
||||
infrastructure:
|
||||
name: infrastructure
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres-data:
|
||||
@ -1,365 +0,0 @@
|
||||
name: booking-monolith
|
||||
|
||||
services:
|
||||
|
||||
#######################################################
|
||||
# EventStoreDB
|
||||
#######################################################
|
||||
eventstore:
|
||||
container_name: eventstore
|
||||
image: eventstore/eventstore:latest
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- EVENTSTORE_CLUSTER_SIZE=1
|
||||
- EVENTSTORE_RUN_PROJECTIONS=All
|
||||
- EVENTSTORE_START_STANDARD_PROJECTIONS=True
|
||||
- EVENTSTORE_HTTP_PORT=2113
|
||||
- EVENTSTORE_INSECURE=True
|
||||
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=True
|
||||
ports:
|
||||
- "2113:2113"
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# postgres
|
||||
#######################################################
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
container_name: postgres
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- '5432:5432'
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
command:
|
||||
- "postgres"
|
||||
- "-c"
|
||||
- "wal_level=logical"
|
||||
- "-c"
|
||||
- "max_prepared_transactions=10"
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# Mongo
|
||||
#######################################################
|
||||
mongo:
|
||||
image: mongo:latest
|
||||
container_name: mongo
|
||||
restart: unless-stopped
|
||||
# environment:
|
||||
# - MONGO_INITDB_ROOT_USERNAME=root
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=secret
|
||||
ports:
|
||||
- 27017:27017
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# jaeger
|
||||
# https://www.jaegertracing.io/docs/1.64/deployment/
|
||||
# https://www.jaegertracing.io/docs/1.6/deployment/
|
||||
#######################################################
|
||||
jaeger-all-in-one:
|
||||
image: jaegertracing/all-in-one:latest
|
||||
container_name: jaeger-all-in-one
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "6831:6831/udp" # UDP port for Jaeger agent
|
||||
- "16686:16686" # endpoints and Jaeger UI
|
||||
- "14268:14268" # HTTP port for accept trace spans directly from clients
|
||||
- "14317:4317" # OTLP gRPC receiver for jaeger
|
||||
- "14318:4318" # OTLP http receiver for jaeger
|
||||
# - "9411" # Accepts Zipkin spans - /api/v2/spans
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# zipkin
|
||||
# https://zipkin.io/pages/quickstart
|
||||
#######################################################
|
||||
zipkin-all-in-one:
|
||||
image: openzipkin/zipkin:latest
|
||||
container_name: zipkin-all-in-one
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "9411:9411"
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# prometheus
|
||||
# https://prometheus.io/docs/introduction/first_steps/
|
||||
# https://prometheus.io/docs/prometheus/3.1/installation/
|
||||
# https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/prometheus-config-examples/docker-compose-linux/
|
||||
#######################################################
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- ./../configs/prometheus.yaml:/etc/prometheus/prometheus.yml
|
||||
# to passe one flag, such as "--log.level=debug" or "--web.enable-remote-write-receiver", we need to override the whole command, as we can't just pass one extra argument
|
||||
command:
|
||||
- "--config.file=/etc/prometheus/prometheus.yml"
|
||||
- "--storage.tsdb.path=/prometheus"
|
||||
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
|
||||
- "--web.console.templates=/usr/share/prometheus/consoles"
|
||||
# need this for the OpenTelemetry collector to be able to put metrics into Prometheus
|
||||
- "--web.enable-remote-write-receiver"
|
||||
# - "--log.level=debug"
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# otel-collector
|
||||
# https://opentelemetry.io/docs/collector/installation/
|
||||
# https://github.com/open-telemetry/opentelemetry-collector
|
||||
# https://github.com/open-telemetry/opentelemetry-collector-contrib
|
||||
# we can use none contrib docker `otel/opentelemetry-collector` version from `https://github.com/open-telemetry/opentelemetry-collector` repository but,
|
||||
# if we need more components like `elasticsearch` we should use `otel/opentelemetry-collector-contrib` image of `https://github.com/open-telemetry/opentelemetry-collector-contrib` repository.
|
||||
#######################################################
|
||||
otel-collector:
|
||||
image: otel/opentelemetry-collector-contrib:latest
|
||||
container_name: otel-collector
|
||||
restart: unless-stopped
|
||||
command: ["--config=/etc/otelcol-contrib/config.yaml"]
|
||||
volumes:
|
||||
- ./../configs/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
|
||||
ports:
|
||||
- "11888:1888" # pprof extension
|
||||
- "8888:8888" # Prometheus metrics exposed by the Collector
|
||||
- "8889:8889" # Prometheus exporter metrics
|
||||
- "13133:13133" # health_check extension
|
||||
- "4317:4317" # OTLP gRPC receiver
|
||||
- "4318:4318" # OTLP http receiver
|
||||
- "55679:55679" # zpages extension
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# rabbitmq
|
||||
#######################################################
|
||||
rabbitmq:
|
||||
image: rabbitmq:management
|
||||
container_name: rabbitmq
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "5672:5672"
|
||||
- "15672:15672"
|
||||
# volumes:
|
||||
# - rabbitmq:/var/lib/rabbitmq
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# Redis
|
||||
#######################################################
|
||||
redis:
|
||||
image: redis
|
||||
container_name: redis
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 6379:6379
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# node-exporter
|
||||
# https://prometheus.io/docs/guides/node-exporter/
|
||||
# https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/prometheus-config-examples/docker-compose-linux/
|
||||
#######################################################
|
||||
node-exporter:
|
||||
image: prom/node-exporter:latest
|
||||
container_name: node-exporter
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- /proc:/host/proc:ro
|
||||
- /sys:/host/sys:ro
|
||||
- /:/rootfs:ro
|
||||
command:
|
||||
- '--path.procfs=/host/proc'
|
||||
- '--path.rootfs=/rootfs'
|
||||
- '--path.sysfs=/host/sys'
|
||||
ports:
|
||||
- "9101:9100"
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# grafana
|
||||
# https://grafana.com/docs/grafana/latest/administration/provisioning/
|
||||
# https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/
|
||||
# https://grafana.com/docs/grafana/latest/setup-grafana/configure-docker/
|
||||
# https://github.com/grafana/intro-to-mltp/blob/main/grafana/provisioning/datasources/datasources.yaml
|
||||
#######################################################
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
container_name: grafana
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor
|
||||
# - GF_AUTH_ANONYMOUS_ENABLED=true
|
||||
# - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
|
||||
# - GF_AUTH_DISABLE_LOGIN_FORM=true
|
||||
depends_on:
|
||||
- prometheus
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./../configs/grafana/provisioning:/etc/grafana/provisioning
|
||||
- ./../configs/grafana/dashboards:/var/lib/grafana/dashboards
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# tempo
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/otel-collector/docker-compose.yaml
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/shared
|
||||
# https://github.com/grafana/tempo/blob/main/example/docker-compose/local
|
||||
# https://github.com/grafana/tempo/tree/main/example/docker-compose
|
||||
#######################################################
|
||||
tempo:
|
||||
image: grafana/tempo:latest
|
||||
container_name: tempo
|
||||
restart: unless-stopped
|
||||
command: [ "-config.file=/etc/tempo.yaml" ]
|
||||
volumes:
|
||||
- ./../configs/tempo.yaml:/etc/tempo.yaml
|
||||
ports:
|
||||
- "3200" # tempo
|
||||
- "24317:4317" # otlp grpc
|
||||
- "24318:4318" # otlp http
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# loki
|
||||
# https://grafana.com/docs/opentelemetry/collector/send-logs-to-loki/
|
||||
# https://github.com/grafana/loki/blob/main/production/docker-compose.yaml
|
||||
# https://github.com/grafana/loki/blob/main/examples/getting-started/docker-compose.yaml
|
||||
#######################################################
|
||||
loki:
|
||||
image: grafana/loki:latest
|
||||
hostname: loki
|
||||
container_name: loki
|
||||
ports:
|
||||
- "3100:3100"
|
||||
command: -config.file=/etc/loki/local-config.yaml
|
||||
volumes:
|
||||
- ./../configs/loki-config.yaml:/etc/loki/local-config.yaml
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# elasticsearch
|
||||
# https://www.elastic.co/guide/en/elasticsearch/reference/7.17/docker.html#docker-compose-file
|
||||
#######################################################
|
||||
elasticsearch:
|
||||
container_name: elasticsearch
|
||||
restart: unless-stopped
|
||||
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
|
||||
environment:
|
||||
- discovery.type=single-node
|
||||
- cluster.name=docker-cluster
|
||||
- node.name=docker-node
|
||||
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
|
||||
- xpack.security.enabled=false
|
||||
- xpack.security.http.ssl.enabled=false
|
||||
- xpack.security.transport.ssl.enabled=false
|
||||
- network.host=0.0.0.0
|
||||
- http.port=9200
|
||||
- transport.host=localhost
|
||||
- bootstrap.memory_lock=true
|
||||
- cluster.routing.allocation.disk.threshold_enabled=false
|
||||
ulimits:
|
||||
memlock:
|
||||
soft: -1
|
||||
hard: -1
|
||||
volumes:
|
||||
- elastic-data:/usr/share/elasticsearch/data
|
||||
ports:
|
||||
- ${ELASTIC_HOST_PORT:-9200}:${ELASTIC_PORT:-9200}
|
||||
- 9300:9300
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# kibana
|
||||
# https://www.elastic.co/guide/en/kibana/current/docker.html
|
||||
#######################################################
|
||||
kibana:
|
||||
image: docker.elastic.co/kibana/kibana:8.17.0
|
||||
container_name: kibana
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
|
||||
ports:
|
||||
- ${KIBANA_HOST_PORT:-5601}:${KIBANA_PORT:-5601}
|
||||
depends_on:
|
||||
- elasticsearch
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# cadvisor
|
||||
#######################################################
|
||||
cadvisor:
|
||||
image: gcr.io/cadvisor/cadvisor:latest
|
||||
container_name: cadvisor
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- /:/rootfs:ro
|
||||
- /var/run:/var/run:ro
|
||||
- /sys:/sys:ro
|
||||
- /var/lib/docker/:/var/lib/docker:ro
|
||||
- /dev/disk/:/dev/disk:ro
|
||||
devices:
|
||||
- /dev/kmsg
|
||||
networks:
|
||||
- booking
|
||||
|
||||
#######################################################
|
||||
# booking-monolith
|
||||
#######################################################
|
||||
bookingmonolith:
|
||||
image: booking-monolith
|
||||
build:
|
||||
args:
|
||||
Version: "1"
|
||||
context: ../../../
|
||||
dockerfile: 1-monolith-architecture-style/src/BookingMonolith/dev.Dockerfile
|
||||
container_name: bookingmonolith
|
||||
ports:
|
||||
- 4001:80
|
||||
- 4000:443
|
||||
volumes:
|
||||
- ~/.aspnet/https:/https:ro
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=docker
|
||||
- ASPNETCORE_URLS=https://+;http://+
|
||||
- ASPNETCORE_HTTPS_PORT=4000
|
||||
- ASPNETCORE_HTTP_PORT=4001
|
||||
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
|
||||
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
|
||||
networks:
|
||||
- booking
|
||||
|
||||
networks:
|
||||
booking:
|
||||
name: booking
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
elastic-data:
|
||||
postgres-data:
|
||||
@ -1,11 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Api</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BookingMonolith\src\BookingMonolith.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -1,23 +0,0 @@
|
||||
using BookingMonolith;
|
||||
using BuildingBlocks.Caching;
|
||||
using BuildingBlocks.EFCore;
|
||||
using BuildingBlocks.Logging;
|
||||
using BuildingBlocks.Validation;
|
||||
using MediatR;
|
||||
|
||||
namespace Api.Extensions;
|
||||
|
||||
public static class MediatRExtensions
|
||||
{
|
||||
public static IServiceCollection AddCustomMediatR(this IServiceCollection services)
|
||||
{
|
||||
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(AppDomain.CurrentDomain.GetAssemblies()));
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
|
||||
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(EfTxBehavior<,>));
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>));
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(InvalidateCachingBehavior<,>));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@ -1,171 +0,0 @@
|
||||
using System.Threading.RateLimiting;
|
||||
using BookingMonolith;
|
||||
using BookingMonolith.Booking.Data;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using BookingMonolith.Flight.Data.Seed;
|
||||
using BookingMonolith.Identity.Data;
|
||||
using BookingMonolith.Identity.Data.Seed;
|
||||
using BookingMonolith.Identity.Extensions.Infrastructure;
|
||||
using BookingMonolith.Passenger.Data;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.EFCore;
|
||||
using BuildingBlocks.EventStoreDB;
|
||||
using BuildingBlocks.HealthCheck;
|
||||
using BuildingBlocks.Jwt;
|
||||
using BuildingBlocks.Logging;
|
||||
using BuildingBlocks.Mapster;
|
||||
using BuildingBlocks.MassTransit;
|
||||
using BuildingBlocks.Mongo;
|
||||
using BuildingBlocks.OpenApi;
|
||||
using BuildingBlocks.OpenTelemetryCollector;
|
||||
using BuildingBlocks.PersistMessageProcessor;
|
||||
using BuildingBlocks.ProblemDetails;
|
||||
using BuildingBlocks.Web;
|
||||
using Figgle;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Serilog;
|
||||
|
||||
namespace Api.Extensions;
|
||||
|
||||
public static class SharedInfrastructureExtensions
|
||||
{
|
||||
public static WebApplicationBuilder AddSharedInfrastructure(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Host.UseDefaultServiceProvider(
|
||||
(context, options) =>
|
||||
{
|
||||
// Service provider validation
|
||||
// ref: https://andrewlock.net/new-in-asp-net-core-3-service-provider-validation/
|
||||
options.ValidateScopes = context.HostingEnvironment.IsDevelopment() ||
|
||||
context.HostingEnvironment.IsStaging() ||
|
||||
context.HostingEnvironment.IsEnvironment("tests");
|
||||
|
||||
options.ValidateOnBuild = true;
|
||||
});
|
||||
|
||||
var appOptions = builder.Services.GetOptions<AppOptions>(nameof(AppOptions));
|
||||
Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
|
||||
|
||||
builder.AddCustomSerilog(builder.Environment);
|
||||
builder.Services.AddJwt();
|
||||
builder.Services.AddScoped<ICurrentUserProvider, CurrentUserProvider>();
|
||||
builder.Services.AddTransient<AuthHeaderHandler>();
|
||||
builder.Services.AddPersistMessageProcessor();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddAspnetOpenApi();
|
||||
builder.Services.AddCustomVersioning();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddScoped<IEventDispatcher, EventDispatcher>();
|
||||
builder.Services.AddCustomMediatR();
|
||||
|
||||
builder.Services.AddCustomMassTransit(
|
||||
builder.Environment,
|
||||
TransportType.InMemory,
|
||||
AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
||||
|
||||
builder.Services.Scan(
|
||||
scan => scan
|
||||
.FromAssemblyOf<BookingMonolithRoot>()
|
||||
.AddClasses(classes => classes.AssignableTo<IEventMapper>())
|
||||
.AsImplementedInterfaces()
|
||||
.WithScopedLifetime());
|
||||
|
||||
|
||||
builder.AddMinimalEndpoints(assemblies: typeof(BookingMonolithRoot).Assembly);
|
||||
builder.Services.AddValidatorsFromAssembly(typeof(BookingMonolithRoot).Assembly);
|
||||
builder.Services.AddCustomMapster(typeof(BookingMonolithRoot).Assembly);
|
||||
|
||||
builder.AddMongoDbContext<FlightReadDbContext>();
|
||||
builder.AddMongoDbContext<PassengerReadDbContext>();
|
||||
builder.AddMongoDbContext<BookingReadDbContext>();
|
||||
|
||||
builder.AddCustomDbContext<IdentityContext>();
|
||||
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
||||
builder.AddCustomIdentityServer();
|
||||
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(
|
||||
options =>
|
||||
{
|
||||
options.ForwardedHeaders =
|
||||
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||
});
|
||||
|
||||
builder.AddCustomDbContext<FlightDbContext>();
|
||||
builder.Services.AddScoped<IDataSeeder, FlightDataSeeder>();
|
||||
|
||||
builder.AddCustomDbContext<PassengerDbContext>();
|
||||
|
||||
// ref: https://github.com/oskardudycz/EventSourcing.NetCore/tree/main/Sample/EventStoreDB/ECommerce
|
||||
builder.Services.AddEventStore(builder.Configuration, typeof(BookingMonolithRoot).Assembly)
|
||||
.AddEventStoreDBSubscriptionToAll();
|
||||
|
||||
builder.Services.Configure<ApiBehaviorOptions>(
|
||||
options => options.SuppressModelStateInvalidFilter = true);
|
||||
|
||||
builder.Services.AddRateLimiter(
|
||||
options =>
|
||||
{
|
||||
options.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(
|
||||
httpContext =>
|
||||
RateLimitPartition.GetFixedWindowLimiter(
|
||||
partitionKey: httpContext.User.Identity?.Name ??
|
||||
httpContext.Request.Headers.Host.ToString(),
|
||||
factory: partition => new FixedWindowRateLimiterOptions
|
||||
{
|
||||
AutoReplenishment = true,
|
||||
PermitLimit = 10,
|
||||
QueueLimit = 0,
|
||||
Window = TimeSpan.FromMinutes(1)
|
||||
}));
|
||||
});
|
||||
|
||||
builder.AddCustomObservability();
|
||||
builder.Services.AddCustomHealthCheck();
|
||||
|
||||
builder.Services.AddEasyCaching(
|
||||
options => { options.UseInMemory(builder.Configuration, "mem"); });
|
||||
|
||||
builder.Services.AddProblemDetails();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
public static WebApplication UserSharedInfrastructure(this WebApplication app)
|
||||
{
|
||||
var appOptions = app.Configuration.GetOptions<AppOptions>(nameof(AppOptions));
|
||||
|
||||
app.UseCustomProblemDetails();
|
||||
app.UseCustomObservability();
|
||||
app.UseCustomHealthCheck();
|
||||
|
||||
app.UseSerilogRequestLogging(
|
||||
options =>
|
||||
{
|
||||
options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest;
|
||||
});
|
||||
|
||||
app.UseCorrelationId();
|
||||
app.UseRateLimiter();
|
||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseAspnetOpenApi();
|
||||
}
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
app.UseMigration<IdentityContext>();
|
||||
app.UseMigration<FlightDbContext>();
|
||||
app.UseMigration<PassengerDbContext>();
|
||||
|
||||
app.UseIdentityServer();
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
using Api.Extensions;
|
||||
using BuildingBlocks.Web;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddSharedInfrastructure();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// ref: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-7.0#routing-basics
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UserSharedInfrastructure();
|
||||
app.MapMinimalEndpoints();
|
||||
|
||||
app.Run();
|
||||
|
||||
namespace Api
|
||||
{
|
||||
public partial class Program
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"Monolith.Api": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchUrl": "swagger",
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:4000;http://localhost:4001",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
{
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
{
|
||||
"AppOptions": {
|
||||
"Name": "Booking-Monolith"
|
||||
},
|
||||
"LogOptions": {
|
||||
"Level": "information",
|
||||
"LogTemplate": "{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
|
||||
"File": {
|
||||
"Enabled": false,
|
||||
"Path": "logs/logs.txt",
|
||||
"Interval": "day"
|
||||
}
|
||||
},
|
||||
"PostgresOptions": {
|
||||
"ConnectionString": "Server=localhost;Port=5432;Database=booking_monolith;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||
},
|
||||
"MongoOptions": {
|
||||
"ConnectionString": "mongodb://localhost:27017",
|
||||
"DatabaseName": "booking_modular_monolith_read"
|
||||
},
|
||||
"EventStoreOptions": {
|
||||
"ConnectionString": "esdb://localhost:2113?tls=false"
|
||||
},
|
||||
"PersistMessageOptions": {
|
||||
"Interval": 30,
|
||||
"Enabled": true,
|
||||
"ConnectionString": "Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true"
|
||||
},
|
||||
"Jwt": {
|
||||
"Authority": "https://localhost:4000",
|
||||
"Audience": "booking-monolith"
|
||||
},
|
||||
"HealthOptions": {
|
||||
"Enabled": false
|
||||
},
|
||||
"ObservabilityOptions": {
|
||||
"InstrumentationName": "booking_monolith_service",
|
||||
"OTLPOptions": {
|
||||
"OTLPGrpExporterEndpoint": "http://localhost:4317"
|
||||
},
|
||||
"AspireDashboardOTLPOptions": {
|
||||
"OTLPGrpExporterEndpoint": "http://localhost:4319"
|
||||
},
|
||||
"ZipkinOptions": {
|
||||
"HttpExporterEndpoint": "http://localhost:9411/api/v2/spans"
|
||||
},
|
||||
"JaegerOptions": {
|
||||
"OTLPGrpcExporterEndpoint": "http://localhost:14317",
|
||||
"HttpExporterEndpoint": "http://localhost:14268/api/traces"
|
||||
},
|
||||
"UsePrometheusExporter": true,
|
||||
"UseOTLPExporter": true,
|
||||
"UseAspireOTLPExporter": true,
|
||||
"UseGrafanaExporter": false,
|
||||
"ServiceName": "Booking Monolith Service"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
{
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
{"Version":1,"Id":"296345BF73910ADD1DAC302B848E47E7","Created":"2025-04-06T20:57:25.1670058Z","Algorithm":"RS256","IsX509Certificate":false,"Data":"CfDJ8KNpFTgHKl5Nl-o13RQ8rseNpYdUTB-_FLsIGbeu6jM5x9l_rDfygUsYH6TAnyqXDFeW4U7xf8kJXDDvH1V0jkKcQaHFWYcZnKAirRBnuReu2OcaGWcn0vDccI5liTTRfp_Dknwhf3jgrU-LOBlPDoVGWwTwOQHXa4iHQjfOCG77Ey6CmJZ0w6JMi802tSMbpc2G2376b05GuzpoKwfgG_F8ZJcAtl1cql4KD11CcynPTNqK0fXOcIeGCQKgJDkJp_cHlk-sv4xJTFl5nqRx62v9auoB3AeKxqRqKqserGT-ZFYDeSxOlgmDSreVFezZ4tYd80Iq-ZpQXK5e3uz8gJ1B37_ySzgF_Rkscf67FivIqcpcV-WZzvnKXeQP0Wo7B7Qt8sKwCAW-vh3X5iMdDi-tecOWaRqeNrffbjd4efP1FK5wqmNrZirrcuCZDgPyYUiB1bSUE1HSj5vW4kFy_NF-3k0EVcQf5KqJpJ9QkTQgmTPkFCwwEcyX-P2hA21G64_M_7EjZXnjw29xjnkI7zO3mx3sA5bwPf6sCmxgE6joaI6P7G4u8JB5pbSHynOWWNTWRZm8YHngZCfK1DZa6Y-uAnrNzVQdcbB-uVGwszavP3Ohqtu7NBCaIkIhyT9N783n5-J8KAbSKu2FBF-qwNaUcmSAhbnRLyQwou-F0sxgM9iLwNcCo6jcgqz5g3MBEIcWa5IKdbtYXQQzbj3NlKmYg1l-x0SrxZD9403gNIS-zCEWLPEgpLr-NU06_Y5Vkbvn8jHKAr45nDFvY_osVvCPQ8qFuq_P-z3HMqFrfuPNlLrf_ZoJCpIKYNdXPJwHQXzGpz41QiN2omk52K5N8UCiGnDog66tJZAqGjtWWHpFCF2O4LXA9uEwnlD06N_i1T9umOtLnlGsF5SM0G3YjG_G8APqd6GDnJsM1wBoVXzzldGvS8GEwwxvVRGvLrSljPdR_l-8JifzUzhIOxMdlZUE8D9tQJhqZJovm34kfgx8AA0j4FQxAKPUhz99dapc5rmP1pgkuv7b9ZgtWa9js16GUJUYV3Dd6HC3lWU4zdXnQIsJPBUdgsiKptAXayc1KevAzw7o2PB7_auENui4cj1MuDxbaf9yrq9ZIol_tPw5rdN440vhHPIPzVi-1Wv0YyvyPD0fj2GAU5fL97lVlCprWuM71-rjVtARrn0pbf4ENBYk4ABWWke8ZHppbdFQQbjBv-yKCeiGA7qbRAeb_NMK2wmWUGz9DTVWtb04kmitXvg1-aj6ZwY-uIDSY5uaHPz7b8mxFywlSQ9plQzIkb-EfZk6RWxW1-NqyHMEAryM4QxwdDX9LjSo37CPdHCdOSRsMzH6zGH0_SgeN4W25Lk0RhoBHMMQk_gF5FCXjDteFlAdPFw9K5qmVVohHfEnAMDUZ4xYYgDx0Z254jsbSIFOuqEmUvmb5WvbKFtlcLrpFAuoqcNLfI61JM0LLxZNjpktGOMX5q1E_tYm5Y-bxd6W_2r-UUkCTKWJMp7_wr2CJPyegVshEBuUaO4_GyndCTY9_jh4OEYgyFQliEg66g3CUVy7ZBERrfz1CiHmpTqoKbs3toPsHMrB6yaQe9UtcYzLBRP3OVku3WmE1IylfUsZ64YA2DBU399JjYckXlWU3PxH9GAxcnIW8cU_29XZZ0ueGLFeSRP0mBb8TqVIcqd3xoAUbZGPnleme-D44yco8ZSGFVhQqt5qstzIA2DQALjVf2E5vg-yL8Gj9s5q-xjPjBgZgyW23gbBEO6PynDK3jfnucHXcLsHMpvZwyV1yaU3314mNLUpu241_7ukMuWC5FmxaVWqe4n9h-W479YlK5WmI5TDmWcc12DQI92eIAYCSYA60SOJhnuGsyFHwedfxIjVjouZeAWWHj1QOM3uZ1rwYOB0DZSlqI6C2kecv4D2CFq7gYosBxQX9fSnJ2MyUiGOxbdlRtwGB_dtRtlqWpt-acu-l9i5jNwdM6QnNejoPthvWPCcvfaaqFjWjnZQQKSBBfWV9Coe7mnaJYhyqWFUQ4AKcDuboQ3k3jj2p-5LTnbFlTQ3SzLfsgjLjpD5hqIY1ND5NWOT3D0pQumfh5tJxgSa0g-HhW7XBSGs2783OFdgAMuxCkZUgisdu0MRyQzdqWEY30trlpnpsAGOO3E8MMxQ2COy7Y-WrUykioag1qkJTbT-1FgHgw9Qj4dnQ136_tC3BvVrmO6pId26PzdPDpV_4T5vNLoyuiyyUqnHcKOETFrHpbj2cXmi-sYuqrwfNZKfcPIsAkekmcWlLd9s4glvD3xJ0SB0s6gJURjvupdD96l2kfdHw8qieB0ovlGISrpjnAKGn6F81_32rYULB-NDN8H4aTdiVmhvwf6KkpXHA9Euuyyir4BqHmIknr8WWuugIMxRw3ysCS4OIV5ocsjzIfQ9r_15bNWsoyWPDkVnKcS1ffbURzYPNIqTO6Ik5iC7rk705WAxaojy","DataProtected":true}
|
||||
@ -1 +0,0 @@
|
||||
{"Version":1,"Id":"73D9025BDA857BF270C99C6594EE4246","Created":"2024-09-02T18:34:53.8631045Z","Algorithm":"RS256","IsX509Certificate":false,"Data":"CfDJ8MEQ06y_es9CrKY4Ou9Uc7Hf97ujXcMcuawi9V5VrBvxWbAqbdjBlk5zKK_NzrDURTwaFvgOfLUQ__0r-sMvtTXBZLhWhNWJnLn1-KWhtnpvPt5jFTAf2f5mvrjVTTN8E-NTGMGk2yLOYm2TVE3QL7DuLRrazydXLJvIB71O2d_OrAfB7Pq62xrnwLgp4BErb_HphYUExsAEp7jn6uL34QJ5HI6zsb_ct2SHvOl0CzUH2yIjjrY_u-5GAgmqqpUyysGwUh8RpR_CDPCd8ZxgSOiKAlBkp3kQXxf86MF0C-kfBKU-iflrJRSJ1-5R8F5nNPK8FL29I4i7SYCugIkLvqez3wTewPUFv00bTpcfs3V_tmfqBFLyNWm4sppzpU9HGB3elZ0z5bBa_IGbtIrlHC_o4SDSxKKdD4OUZHGLE5X--xWBw5uV9GSgrSH6bcnHZ6rLd3qrt7b82BMr-rVIGyFzGIE6OTLVGkXSL6FdpJ9Lezp06qnZ6DtLFI86lVJGsYIuXR_AIVrz9U8uqCrK6jLwGCk9nR0adPtAUJfgcXGVVTQlvt_YgZv5k5_rYcVl0yLNdgd-BoidXeoqLPJxIJOCohwumVcqTPkf-gB_hjgNk6IEqXZxm0Tzl0d2jpyERDHdHxIvS5o1h4YUfkiMcliRfQMNkLoDxf0H2hFNXRYQKkQ1y6cwS9juq66Uj_-v-vN1etE-hK45ULFCfyppBvb2aTYfTuce5S0ps1t0ZIjvpm7Kvjg3doHEi97N-IqxYaf8r6n8gBcaUwlrfcHaYNPLRyWywX_varEmLm9qGK5KJj2itGNfw0wU0EygIeoV6V_PzqyAkf0JcVTC7lcog37TPdNU2AGzH0S8oXiAQEd49wPs2ZApjiOaiz26efr03I-hD5N91-R2_9ACGjENGPVHMyUtMVV5RPs3-pQMv9f_zweOuLQo7ZfhScqu4HmxGW70amuV4anMxGCQzbi3JWnkTmspptzClJyvE_MJVSTQ6SX04DaS4buSG3wZEc9Qy9SqTj-9CJ7XFGFs8XYmKUj_cIoQF1XuoSnWblsnnEC7EbNRF7y9fG8ZG-Sk3TEEYnalxRrcS-i26wVNdnuUBEmidz_HfsxFxCDKKmx7GHTvHxy72kI84ucMeQeVFjJI3ZDynGn--cL9xBiUbUKM8WDhJ-AgZ76wwh0qAPw5xJ6yHi-15moxySUkvFLjlNkP2Ad5j3_3ab_r6VIunM6zhsq7pSBWIg5povuV5ZwNVZQX0IeLqV9bHug443LaK5a57dTK8wy346AFftV-wc71i4Nt5MIFcOs3lxRPqYij1enbrPYvIV4-N8Sy6aaYj25Qn7VHrGeW72aZPAYY5W-czoPw_Oo6xYGjaPYFFsUSZVg6IQwCzwwAxUoc2gAL33FJQTNvNSnrYBJ5HN-Tqan23Pw_bEus7HHZu2N1daFjqtrl4-oOco46phsppUjH3LGhOPJnFSChr-W8tlk80coJ8IK_AsGludKB09WzId9JBtI5cp3Yu1J7N6nSL7nVTrT6Gw_0hitSoeu5ZLPSS9ooAynAXrvB_s0l0L9aFTRuc5IEhgt4bLzbeqimfQemRlBsNz09JGe04gmOOCmjWD52JHWUiVJQNMavrSGtW9Dy1-Z5h0D_BHzhpTia1S7wx7dSdItJ0-Pm1Au_TNkQGm4ffNFsVDQmNkCYyc8yFnYmZMYYEaPmbw7DvQTs1MHoe7aUzMM0DKcaqboSaxqQK9sxymgElvdoYqOMRWzS7s39UQ1O4TfPngfrWdtN2DogGUtyS-vPfNJpdS6jZvJAj8czgl7PU8buwWyPApE1-FVL32wC6a8dkHvJi4p7fbBjmTfFCnuW8G1KBX3VuToctJvidSjzoSUTX3vgKVni2QW-55Sh7DUYy91FGXGB_ui1yuxEnLmymtbWokcWYkIwcAsl8im70V4oK63ypNSYWea_gaDWMFXT_vANB1iAkr-_zE_ECocOXo93QqSR5UdLmfQFvLiDwjUeovkjFS5C2Z8AjEvHvFkedGWOIK5Bpam-0IEFip3Fvg6RgxwTinFXXa8PiRkcLSlt0J81b85ybrKsDj5WtUA-MFuK2Silyofn9BgD_lh9RU4HPFhVoqey7AuEJjHtGvqz4EnE_05y4A_mKgvJBAs4QiYjCopWtheeOGeeoUa636Ewmu30P66C5mimdAIx36-55xlyJBIM7DFFM6RAGvfAmpyNphjwT0y84B4pOhFEZeOQ2me2sfG-xRJbjjgDhP2SwBBEQ-hCLGeqOD-Xo74FZC4lCTvtn2Sbu1kIw0kz2P_vrq6d6SZwEIrhWYhfRVKTrT8nXj8i48Jdc1d1fyKdRL15USgLhAT-QSNcgVYHRLsVlQx5-b51tGg6Atx6vGCxtXBRSaTwZ3IxbdJs0T62H14K5U81EFu-2Vvf-cMwCm4gCQATxvvAsqToxElou9ZjIVMPt_FQUyAMtJke","DataProtected":true}
|
||||
@ -1,26 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Features.CreatingBook.V1;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.Core.Event;
|
||||
|
||||
namespace BookingMonolith.Booking;
|
||||
|
||||
public sealed class BookingEventMapper : IEventMapper
|
||||
{
|
||||
public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event)
|
||||
{
|
||||
return @event switch
|
||||
{
|
||||
BookingCreatedDomainEvent e => new BookingCreated(e.Id),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public IInternalCommand? MapToInternalCommand(IDomainEvent @event)
|
||||
{
|
||||
return @event switch
|
||||
{
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Features.CreatingBook.V1;
|
||||
using BookingMonolith.Booking.Bookings.Models;
|
||||
using BookingMonolith.Booking.Data;
|
||||
using BuildingBlocks.EventStoreDB.Events;
|
||||
using BuildingBlocks.EventStoreDB.Projections;
|
||||
using MassTransit;
|
||||
using MediatR;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
|
||||
namespace BookingMonolith.Booking;
|
||||
|
||||
public class BookingProjection : IProjectionProcessor
|
||||
{
|
||||
private readonly BookingReadDbContext _bookingReadDbContext;
|
||||
|
||||
public BookingProjection(BookingReadDbContext bookingReadDbContext)
|
||||
{
|
||||
_bookingReadDbContext = bookingReadDbContext;
|
||||
}
|
||||
|
||||
public async Task ProcessEventAsync<T>(StreamEvent<T> streamEvent, CancellationToken cancellationToken = default)
|
||||
where T : INotification
|
||||
{
|
||||
switch (streamEvent.Data)
|
||||
{
|
||||
case BookingCreatedDomainEvent bookingCreatedDomainEvent:
|
||||
await Apply(bookingCreatedDomainEvent, cancellationToken);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Apply(BookingCreatedDomainEvent @event, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var reservation =
|
||||
await _bookingReadDbContext.Booking.AsQueryable().SingleOrDefaultAsync(x => x.Id == @event.Id && !x.IsDeleted,
|
||||
cancellationToken);
|
||||
|
||||
if (reservation == null)
|
||||
{
|
||||
var bookingReadModel = new BookingReadModel
|
||||
{
|
||||
Id = NewId.NextGuid(),
|
||||
Trip = @event.Trip,
|
||||
BookId = @event.Id,
|
||||
PassengerInfo = @event.PassengerInfo,
|
||||
IsDeleted = @event.IsDeleted
|
||||
};
|
||||
|
||||
await _bookingReadDbContext.Booking.InsertOneAsync(bookingReadModel, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
namespace BookingMonolith.Booking;
|
||||
|
||||
public class BookingRoot
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
namespace BookingMonolith.Booking.Bookings.Dtos;
|
||||
|
||||
public record BookingResponseDto(Guid Id, string Name, string FlightNumber, Guid AircraftId, decimal Price,
|
||||
DateTime FlightDate, string SeatNumber, Guid DepartureAirportId, Guid ArriveAirportId, string Description);
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Net;
|
||||
using BuildingBlocks.Exception;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class BookingAlreadyExistException : AppException
|
||||
{
|
||||
public BookingAlreadyExistException(int? code = default) : base("Booking already exist!", HttpStatusCode.Conflict, code)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Net;
|
||||
using BuildingBlocks.Exception;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class FlightNotFoundException : AppException
|
||||
{
|
||||
public FlightNotFoundException() : base("Flight doesn't exist!", HttpStatusCode.NotFound)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidAircraftIdException : DomainException
|
||||
{
|
||||
public InvalidAircraftIdException(Guid aircraftId)
|
||||
: base($"aircraftId: '{aircraftId}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidArriveAirportIdException : DomainException
|
||||
{
|
||||
public InvalidArriveAirportIdException(Guid arriveAirportId)
|
||||
: base($"arriveAirportId: '{arriveAirportId}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidDepartureAirportIdException : DomainException
|
||||
{
|
||||
public InvalidDepartureAirportIdException(Guid departureAirportId)
|
||||
: base($"departureAirportId: '{departureAirportId}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidFlightDateException : DomainException
|
||||
{
|
||||
public InvalidFlightDateException(DateTime flightDate)
|
||||
: base($"Flight Date: '{flightDate}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidFlightNumberException : DomainException
|
||||
{
|
||||
public InvalidFlightNumberException(string flightNumber)
|
||||
: base($"Flight Number: '{flightNumber}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidPassengerNameException : DomainException
|
||||
{
|
||||
public InvalidPassengerNameException(string passengerName)
|
||||
: base($"Passenger Name: '{passengerName}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class InvalidPriceException : DomainException
|
||||
{
|
||||
public InvalidPriceException(decimal price)
|
||||
: base($"Price: '{price}' must be grater than or equal 0.")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
public class SeatNumberException : DomainException
|
||||
{
|
||||
public SeatNumberException(string seatNumber)
|
||||
: base($"Seat Number: '{seatNumber}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Dtos;
|
||||
using BookingMonolith.Booking.Bookings.Features.CreatingBook.V1;
|
||||
using Mapster;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Features;
|
||||
|
||||
public class BookingMappings : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.Default.NameMatchingStrategy(NameMatchingStrategy.Flexible);
|
||||
|
||||
config.NewConfig<Models.Booking, BookingResponseDto>()
|
||||
.ConstructUsing(x => new BookingResponseDto(x.Id, x.PassengerInfo.Name, x.Trip.FlightNumber,
|
||||
x.Trip.AircraftId, x.Trip.Price, x.Trip.FlightDate, x.Trip.SeatNumber, x.Trip.DepartureAirportId, x.Trip.ArriveAirportId,
|
||||
x.Trip.Description));
|
||||
|
||||
|
||||
config.NewConfig<CreateBookingRequestDto, CreateBooking>()
|
||||
.ConstructUsing(x => new CreateBooking(x.PassengerId, x.FlightId, x.Description));
|
||||
}
|
||||
}
|
||||
@ -1,137 +0,0 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using BookingMonolith.Booking.Bookings.Exceptions;
|
||||
using BookingMonolith.Booking.Bookings.ValueObjects;
|
||||
using BookingMonolith.Flight.Flights.Features.GettingFlightById.V1;
|
||||
using BookingMonolith.Flight.Seats.Features.GettingAvailableSeats.V1;
|
||||
using BookingMonolith.Flight.Seats.Features.ReservingSeat.V1;
|
||||
using BookingMonolith.Passenger.Passengers.Features.GettingPassengerById.V1;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.Core.CQRS;
|
||||
using BuildingBlocks.Core.Event;
|
||||
using BuildingBlocks.Core.Model;
|
||||
using BuildingBlocks.EventStoreDB.Repository;
|
||||
using BuildingBlocks.Web;
|
||||
using Duende.IdentityServer.EntityFramework.Entities;
|
||||
using FluentValidation;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using MassTransit;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Features.CreatingBook.V1;
|
||||
|
||||
public record CreateBooking(Guid PassengerId, Guid FlightId, string Description) : ICommand<CreateBookingResult>
|
||||
{
|
||||
public Guid Id { get; init; } = NewId.NextGuid();
|
||||
}
|
||||
|
||||
public record CreateBookingResult(ulong Id);
|
||||
|
||||
public record BookingCreatedDomainEvent(Guid Id, PassengerInfo PassengerInfo, Trip Trip) : Entity<Guid>, IDomainEvent;
|
||||
|
||||
public record CreateBookingRequestDto(Guid PassengerId, Guid FlightId, string Description);
|
||||
|
||||
public record CreateBookingResponseDto(ulong Id);
|
||||
|
||||
public class CreateBookingEndpoint : IMinimalEndpoint
|
||||
{
|
||||
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapPost($"{EndpointConfig.BaseApiPath}/booking", async (CreateBookingRequestDto request,
|
||||
IMediator mediator, IMapper mapper,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var command = mapper.Map<CreateBooking>(request);
|
||||
|
||||
var result = await mediator.Send(command, cancellationToken);
|
||||
|
||||
var response = result.Adapt<CreateBookingResponseDto>();
|
||||
|
||||
return Results.Ok(response);
|
||||
})
|
||||
.RequireAuthorization(nameof(ApiScope))
|
||||
.WithName("CreateBooking")
|
||||
.WithApiVersionSet(builder.NewApiVersionSet("Booking").Build())
|
||||
.Produces<CreateBookingResponseDto>()
|
||||
.ProducesProblem(StatusCodes.Status400BadRequest)
|
||||
.WithSummary("Create Booking")
|
||||
.WithDescription("Create Booking")
|
||||
.WithOpenApi()
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateBookingValidator : AbstractValidator<CreateBooking>
|
||||
{
|
||||
public CreateBookingValidator()
|
||||
{
|
||||
RuleFor(x => x.FlightId).NotNull().WithMessage("FlightId is required!");
|
||||
RuleFor(x => x.PassengerId).NotNull().WithMessage("PassengerId is required!");
|
||||
}
|
||||
}
|
||||
|
||||
internal class CreateBookingCommandHandler : ICommandHandler<CreateBooking, CreateBookingResult>
|
||||
{
|
||||
private readonly IEventStoreDBRepository<Models.Booking> _eventStoreDbRepository;
|
||||
private readonly ICurrentUserProvider _currentUserProvider;
|
||||
private readonly IEventDispatcher _eventDispatcher;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public CreateBookingCommandHandler(IEventStoreDBRepository<Models.Booking> eventStoreDbRepository,
|
||||
ICurrentUserProvider currentUserProvider,
|
||||
IEventDispatcher eventDispatcher,
|
||||
IMediator mediator)
|
||||
{
|
||||
_eventStoreDbRepository = eventStoreDbRepository;
|
||||
_currentUserProvider = currentUserProvider;
|
||||
_eventDispatcher = eventDispatcher;
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task<CreateBookingResult> Handle(CreateBooking command, CancellationToken cancellationToken)
|
||||
{
|
||||
Guard.Against.Null(command, nameof(command));
|
||||
|
||||
// Directly call the GetFlightById handler instead of gRPC
|
||||
var flight = await _mediator.Send(new GetFlightById(command.FlightId), cancellationToken);
|
||||
|
||||
if (flight is null)
|
||||
{
|
||||
throw new FlightNotFoundException();
|
||||
}
|
||||
|
||||
var passenger = await _mediator.Send(new GetPassengerById(command.PassengerId), cancellationToken);
|
||||
|
||||
var emptySeat = (await _mediator.Send(new GetAvailableSeats(command.FlightId), cancellationToken))?.SeatDtos?.FirstOrDefault();
|
||||
|
||||
var reservation = await _eventStoreDbRepository.Find(command.Id, cancellationToken);
|
||||
|
||||
if (reservation is not null && !reservation.IsDeleted)
|
||||
{
|
||||
throw new BookingAlreadyExistException();
|
||||
}
|
||||
|
||||
var aggrigate = Models.Booking.Create(command.Id, PassengerInfo.Of(passenger.PassengerDto?.Name), Trip.Of(
|
||||
flight.FlightDto.FlightNumber, flight.FlightDto.AircraftId,
|
||||
flight.FlightDto.DepartureAirportId,
|
||||
flight.FlightDto.ArriveAirportId, flight.FlightDto.FlightDate,
|
||||
flight.FlightDto.Price, command.Description,
|
||||
emptySeat?.SeatNumber),
|
||||
false, _currentUserProvider.GetCurrentUserId());
|
||||
|
||||
await _eventDispatcher.SendAsync(aggrigate.DomainEvents, cancellationToken: cancellationToken);
|
||||
|
||||
await _mediator.Send(new ReserveSeat(flight.FlightDto.Id, emptySeat?.SeatNumber), cancellationToken);
|
||||
|
||||
var result = await _eventStoreDbRepository.Add(
|
||||
aggrigate,
|
||||
cancellationToken);
|
||||
|
||||
return new CreateBookingResult(result);
|
||||
}
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Features.CreatingBook.V1;
|
||||
using BookingMonolith.Booking.Bookings.ValueObjects;
|
||||
using BuildingBlocks.EventStoreDB.Events;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Models;
|
||||
|
||||
public record Booking : AggregateEventSourcing<Guid>
|
||||
{
|
||||
public Trip Trip { get; private set; }
|
||||
public PassengerInfo PassengerInfo { get; private set; }
|
||||
|
||||
public static Booking Create(Guid id, PassengerInfo passengerInfo, Trip trip, bool isDeleted = false, long? userId = null)
|
||||
{
|
||||
var booking = new Booking { Id = id, Trip = trip, PassengerInfo = passengerInfo, IsDeleted = isDeleted };
|
||||
|
||||
var @event = new BookingCreatedDomainEvent(booking.Id, booking.PassengerInfo, booking.Trip)
|
||||
{
|
||||
IsDeleted = booking.IsDeleted,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedBy = userId
|
||||
};
|
||||
|
||||
booking.AddDomainEvent(@event);
|
||||
booking.Apply(@event);
|
||||
|
||||
return booking;
|
||||
}
|
||||
|
||||
public override void When(object @event)
|
||||
{
|
||||
switch (@event)
|
||||
{
|
||||
case BookingCreatedDomainEvent bookingCreated:
|
||||
{
|
||||
Apply(bookingCreated);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Apply(BookingCreatedDomainEvent @event)
|
||||
{
|
||||
Id = @event.Id;
|
||||
Trip = @event.Trip;
|
||||
PassengerInfo = @event.PassengerInfo;
|
||||
IsDeleted = @event.IsDeleted;
|
||||
Version++;
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.ValueObjects;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.Models;
|
||||
|
||||
public class BookingReadModel
|
||||
{
|
||||
public required Guid Id { get; init; }
|
||||
public required Guid BookId { get; init; }
|
||||
public required Trip Trip { get; init; }
|
||||
public required PassengerInfo PassengerInfo { get; init; }
|
||||
public required bool IsDeleted { get; init; }
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.ValueObjects;
|
||||
|
||||
public record PassengerInfo
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
private PassengerInfo(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public static PassengerInfo Of(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
throw new InvalidPassengerNameException(name);
|
||||
}
|
||||
|
||||
return new PassengerInfo(name);
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Booking.Bookings.ValueObjects;
|
||||
|
||||
public record Trip
|
||||
{
|
||||
public string FlightNumber { get; }
|
||||
public Guid AircraftId { get; }
|
||||
public Guid DepartureAirportId { get; }
|
||||
public Guid ArriveAirportId { get; }
|
||||
public DateTime FlightDate { get; }
|
||||
public decimal Price { get; }
|
||||
public string Description { get; }
|
||||
public string SeatNumber { get; }
|
||||
|
||||
private Trip(string flightNumber, Guid aircraftId, Guid departureAirportId, Guid arriveAirportId,
|
||||
DateTime flightDate, decimal price, string description, string seatNumber)
|
||||
{
|
||||
FlightNumber = flightNumber;
|
||||
AircraftId = aircraftId;
|
||||
DepartureAirportId = departureAirportId;
|
||||
ArriveAirportId = arriveAirportId;
|
||||
FlightDate = flightDate;
|
||||
Price = price;
|
||||
Description = description;
|
||||
SeatNumber = seatNumber;
|
||||
}
|
||||
|
||||
public static Trip Of(string flightNumber, Guid aircraftId, Guid departureAirportId, Guid arriveAirportId,
|
||||
DateTime flightDate, decimal price, string description, string seatNumber)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(flightNumber))
|
||||
{
|
||||
throw new InvalidFlightNumberException(flightNumber);
|
||||
}
|
||||
|
||||
if (aircraftId == Guid.Empty)
|
||||
{
|
||||
throw new InvalidAircraftIdException(aircraftId);
|
||||
}
|
||||
|
||||
if (departureAirportId == Guid.Empty)
|
||||
{
|
||||
throw new InvalidDepartureAirportIdException(departureAirportId);
|
||||
}
|
||||
|
||||
if (arriveAirportId == Guid.Empty)
|
||||
{
|
||||
throw new InvalidArriveAirportIdException(departureAirportId);
|
||||
}
|
||||
|
||||
if (flightDate == default)
|
||||
{
|
||||
throw new InvalidFlightDateException(flightDate);
|
||||
}
|
||||
|
||||
if (price < 0)
|
||||
{
|
||||
throw new InvalidPriceException(price);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(seatNumber))
|
||||
{
|
||||
throw new SeatNumberException(seatNumber);
|
||||
}
|
||||
|
||||
return new Trip(flightNumber, aircraftId, departureAirportId, arriveAirportId, flightDate, price, description, seatNumber);
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
using BookingMonolith.Booking.Bookings.Models;
|
||||
using BuildingBlocks.Mongo;
|
||||
using Humanizer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace BookingMonolith.Booking.Data;
|
||||
|
||||
|
||||
public class BookingReadDbContext : MongoDbContext
|
||||
{
|
||||
public BookingReadDbContext(IOptions<MongoOptions> options) : base(options)
|
||||
{
|
||||
Booking = GetCollection<BookingReadModel>(nameof(Booking).Underscore());
|
||||
}
|
||||
|
||||
public IMongoCollection<BookingReadModel> Booking { get; }
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\building-blocks\BuildingBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -1,6 +0,0 @@
|
||||
namespace BookingMonolith;
|
||||
|
||||
public class BookingMonolithRoot
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Aircrafts.Dtos;
|
||||
|
||||
public record AircraftDto(long Id, string Name, string Model, int ManufacturingYear);
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Net;
|
||||
using BuildingBlocks.Exception;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
public class AircraftAlreadyExistException : AppException
|
||||
{
|
||||
public AircraftAlreadyExistException() : base("Aircraft already exist!", HttpStatusCode.Conflict)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
public class InvalidAircraftIdException : DomainException
|
||||
{
|
||||
public InvalidAircraftIdException(Guid aircraftId)
|
||||
: base($"AircraftId: '{aircraftId}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
public class InvalidManufacturingYearException : DomainException
|
||||
{
|
||||
public InvalidManufacturingYearException() : base("ManufacturingYear must be greater than 1900")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
public class InvalidModelException : DomainException
|
||||
{
|
||||
public InvalidModelException() : base("Model cannot be empty or whitespace.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
public class InvalidNameException : DomainException
|
||||
{
|
||||
public InvalidNameException() : base("Name cannot be empty or whitespace.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Features.CreatingAircraft.V1;
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
using Mapster;
|
||||
using MassTransit;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Features;
|
||||
|
||||
public class AircraftMappings : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.NewConfig<CreateAircraftMongo, AircraftReadModel>()
|
||||
.Map(d => d.Id, s => NewId.NextGuid())
|
||||
.Map(d => d.AircraftId, s => AircraftId.Of(s.Id));
|
||||
|
||||
config.NewConfig<Aircraft, AircraftReadModel>()
|
||||
.Map(d => d.Id, s => NewId.NextGuid())
|
||||
.Map(d => d.AircraftId, s => AircraftId.Of(s.Id.Value));
|
||||
|
||||
config.NewConfig<CreateAircraftRequestDto, CreatingAircraft.V1.CreateAircraft>()
|
||||
.ConstructUsing(x => new CreatingAircraft.V1.CreateAircraft(x.Name, x.Model, x.ManufacturingYear));
|
||||
}
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using BuildingBlocks.Core.CQRS;
|
||||
using BuildingBlocks.Core.Event;
|
||||
using BuildingBlocks.Web;
|
||||
using Duende.IdentityServer.EntityFramework.Entities;
|
||||
using FluentValidation;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using MassTransit;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Features.CreatingAircraft.V1;
|
||||
|
||||
public record CreateAircraft(string Name, string Model, int ManufacturingYear) : ICommand<CreateAircraftResult>,
|
||||
IInternalCommand
|
||||
{
|
||||
public Guid Id { get; init; } = NewId.NextGuid();
|
||||
}
|
||||
|
||||
public record CreateAircraftResult(AircraftId Id);
|
||||
|
||||
public record AircraftCreatedDomainEvent
|
||||
(Guid Id, string Name, string Model, int ManufacturingYear, bool IsDeleted) : IDomainEvent;
|
||||
|
||||
public record CreateAircraftRequestDto(string Name, string Model, int ManufacturingYear);
|
||||
|
||||
public record CreateAircraftResponseDto(Guid Id);
|
||||
|
||||
public class CreateAircraftEndpoint : IMinimalEndpoint
|
||||
{
|
||||
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapPost($"{EndpointConfig.BaseApiPath}/flight/aircraft", async (CreateAircraftRequestDto request,
|
||||
IMediator mediator, IMapper mapper,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var command = mapper.Map<CreateAircraft>(request);
|
||||
|
||||
var result = await mediator.Send(command, cancellationToken);
|
||||
|
||||
var response = result.Adapt<CreateAircraftResponseDto>();
|
||||
|
||||
return Results.Ok(response);
|
||||
})
|
||||
.RequireAuthorization(nameof(ApiScope))
|
||||
.WithName("CreateAircraft")
|
||||
.WithApiVersionSet(builder.NewApiVersionSet("Flight").Build())
|
||||
.Produces<CreateAircraftResponseDto>()
|
||||
.ProducesProblem(StatusCodes.Status400BadRequest)
|
||||
.WithSummary("Create Aircraft")
|
||||
.WithDescription("Create Aircraft")
|
||||
.WithOpenApi()
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateAircraftValidator : AbstractValidator<CreateAircraft>
|
||||
{
|
||||
public CreateAircraftValidator()
|
||||
{
|
||||
RuleFor(x => x.Model).NotEmpty().WithMessage("Model is required");
|
||||
RuleFor(x => x.Name).NotEmpty().WithMessage("Name is required");
|
||||
RuleFor(x => x.ManufacturingYear).NotEmpty().WithMessage("ManufacturingYear is required");
|
||||
}
|
||||
}
|
||||
|
||||
internal class CreateAircraftHandler : IRequestHandler<CreateAircraft, CreateAircraftResult>
|
||||
{
|
||||
private readonly FlightDbContext _flightDbContext;
|
||||
|
||||
public CreateAircraftHandler(FlightDbContext flightDbContext)
|
||||
{
|
||||
_flightDbContext = flightDbContext;
|
||||
}
|
||||
|
||||
public async Task<CreateAircraftResult> Handle(CreateAircraft request, CancellationToken cancellationToken)
|
||||
{
|
||||
Guard.Against.Null(request, nameof(request));
|
||||
|
||||
var aircraft = await _flightDbContext.Aircraft.SingleOrDefaultAsync(
|
||||
a => a.Model.Value == request.Model, cancellationToken);
|
||||
|
||||
if (aircraft is not null)
|
||||
{
|
||||
throw new AircraftAlreadyExistException();
|
||||
}
|
||||
|
||||
var aircraftEntity = Aircraft.Create(AircraftId.Of(request.Id), Name.Of(request.Name), Model.Of(request.Model), ManufacturingYear.Of(request.ManufacturingYear));
|
||||
|
||||
var newAircraft = (await _flightDbContext.Aircraft.AddAsync(aircraftEntity, cancellationToken)).Entity;
|
||||
|
||||
return new CreateAircraftResult(newAircraft.Id);
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using BuildingBlocks.Core.CQRS;
|
||||
using BuildingBlocks.Core.Event;
|
||||
using MapsterMapper;
|
||||
using MediatR;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Features.CreatingAircraft.V1;
|
||||
|
||||
public record CreateAircraftMongo(Guid Id, string Name, string Model, int ManufacturingYear, bool IsDeleted = false) : InternalCommand;
|
||||
|
||||
internal class CreateAircraftMongoHandler : ICommandHandler<CreateAircraftMongo>
|
||||
{
|
||||
private readonly FlightReadDbContext _flightReadDbContext;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CreateAircraftMongoHandler(
|
||||
FlightReadDbContext flightReadDbContext,
|
||||
IMapper mapper)
|
||||
{
|
||||
_flightReadDbContext = flightReadDbContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(CreateAircraftMongo request, CancellationToken cancellationToken)
|
||||
{
|
||||
Guard.Against.Null(request, nameof(request));
|
||||
|
||||
var aircraftReadModel = _mapper.Map<AircraftReadModel>(request);
|
||||
|
||||
var aircraft = await _flightReadDbContext.Aircraft.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.AircraftId == aircraftReadModel.AircraftId &&
|
||||
!x.IsDeleted, cancellationToken);
|
||||
|
||||
if (aircraft is not null)
|
||||
{
|
||||
throw new AircraftAlreadyExistException();
|
||||
}
|
||||
|
||||
await _flightReadDbContext.Aircraft.InsertOneAsync(aircraftReadModel, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Features.CreatingAircraft.V1;
|
||||
using BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
using BuildingBlocks.Core.Model;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.Models;
|
||||
|
||||
public record Aircraft : Aggregate<AircraftId>
|
||||
{
|
||||
public Name Name { get; private set; } = default!;
|
||||
public Model Model { get; private set; } = default!;
|
||||
public ManufacturingYear ManufacturingYear { get; private set; } = default!;
|
||||
|
||||
public static Aircraft Create(AircraftId id, Name name, Model model, ManufacturingYear manufacturingYear, bool isDeleted = false)
|
||||
{
|
||||
var aircraft = new Aircraft
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Model = model,
|
||||
ManufacturingYear = manufacturingYear
|
||||
};
|
||||
|
||||
var @event = new AircraftCreatedDomainEvent(
|
||||
aircraft.Id,
|
||||
aircraft.Name,
|
||||
aircraft.Model,
|
||||
aircraft.ManufacturingYear,
|
||||
isDeleted);
|
||||
|
||||
aircraft.AddDomainEvent(@event);
|
||||
|
||||
return aircraft;
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Aircrafts.Models;
|
||||
|
||||
public class AircraftReadModel
|
||||
{
|
||||
public required Guid Id { get; init; }
|
||||
public required Guid AircraftId { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required string Model { get; init; }
|
||||
public required int ManufacturingYear { get; init; }
|
||||
public required bool IsDeleted { get; init; }
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
|
||||
public record AircraftId
|
||||
{
|
||||
public Guid Value { get; }
|
||||
|
||||
private AircraftId(Guid value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static AircraftId Of(Guid value)
|
||||
{
|
||||
if (value == Guid.Empty)
|
||||
{
|
||||
throw new InvalidAircraftIdException(value);
|
||||
}
|
||||
|
||||
return new AircraftId(value);
|
||||
}
|
||||
|
||||
public static implicit operator Guid(AircraftId aircraftId)
|
||||
{
|
||||
return aircraftId.Value;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
|
||||
public record ManufacturingYear
|
||||
{
|
||||
public int Value { get; }
|
||||
|
||||
private ManufacturingYear(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static ManufacturingYear Of(int value)
|
||||
{
|
||||
if (value < 1900)
|
||||
{
|
||||
throw new InvalidManufacturingYearException();
|
||||
}
|
||||
|
||||
return new ManufacturingYear(value);
|
||||
}
|
||||
|
||||
public static implicit operator int(ManufacturingYear manufacturingYear)
|
||||
{
|
||||
return manufacturingYear.Value;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
|
||||
public record Model
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private Model(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Model Of(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new InvalidModelException();
|
||||
}
|
||||
|
||||
return new Model(value);
|
||||
}
|
||||
|
||||
public static implicit operator string(Model model)
|
||||
{
|
||||
return model.Value;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
|
||||
public record Name
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private Name(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Name Of(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new InvalidNameException();
|
||||
}
|
||||
|
||||
return new Name(value);
|
||||
}
|
||||
|
||||
public static implicit operator string(Name name)
|
||||
{
|
||||
return name.Value;
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Airports.Dtos;
|
||||
|
||||
public record AirportDto(long Id, string Name, string Address, string Code);
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Net;
|
||||
using BuildingBlocks.Exception;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
public class AirportAlreadyExistException : AppException
|
||||
{
|
||||
public AirportAlreadyExistException(int? code = default) : base("Airport already exist!", HttpStatusCode.Conflict, code)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
public class InvalidAddressException : DomainException
|
||||
{
|
||||
public InvalidAddressException() : base("Address cannot be empty or whitespace.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
public class InvalidAirportIdException : DomainException
|
||||
{
|
||||
public InvalidAirportIdException(Guid airportId)
|
||||
: base($"airportId: '{airportId}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
public class InvalidCodeException : DomainException
|
||||
{
|
||||
public InvalidCodeException() : base("Code cannot be empty or whitespace.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
public class InvalidNameException : DomainException
|
||||
{
|
||||
public InvalidNameException() : base("Name cannot be empty or whitespace.")
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Features.CreatingAirport.V1;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using Mapster;
|
||||
using MassTransit;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Features;
|
||||
|
||||
public class AirportMappings : IRegister
|
||||
{
|
||||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.NewConfig<CreateAirportMongo, AirportReadModel>()
|
||||
.Map(d => d.Id, s => NewId.NextGuid())
|
||||
.Map(d => d.AirportId, s => s.Id);
|
||||
|
||||
config.NewConfig<Airport, AirportReadModel>()
|
||||
.Map(d => d.Id, s => NewId.NextGuid())
|
||||
.Map(d => d.AirportId, s => s.Id.Value);
|
||||
|
||||
config.NewConfig<CreateAirportRequestDto, CreateAirport>()
|
||||
.ConstructUsing(x => new CreateAirport(x.Name, x.Address, x.Code));
|
||||
}
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using BookingMonolith.Flight.Airports.Exceptions;
|
||||
using BookingMonolith.Flight.Airports.ValueObjects;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using BuildingBlocks.Core.CQRS;
|
||||
using BuildingBlocks.Core.Event;
|
||||
using BuildingBlocks.Web;
|
||||
using Duende.IdentityServer.EntityFramework.Entities;
|
||||
using FluentValidation;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using MassTransit;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Features.CreatingAirport.V1;
|
||||
|
||||
public record CreateAirport(string Name, string Address, string Code) : ICommand<CreateAirportResult>, IInternalCommand
|
||||
{
|
||||
public Guid Id { get; init; } = NewId.NextGuid();
|
||||
}
|
||||
|
||||
public record CreateAirportResult(Guid Id);
|
||||
|
||||
public record AirportCreatedDomainEvent
|
||||
(Guid Id, string Name, string Address, string Code, bool IsDeleted) : IDomainEvent;
|
||||
|
||||
public record CreateAirportRequestDto(string Name, string Address, string Code);
|
||||
|
||||
public record CreateAirportResponseDto(Guid Id);
|
||||
|
||||
public class CreateAirportEndpoint : IMinimalEndpoint
|
||||
{
|
||||
public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder builder)
|
||||
{
|
||||
builder.MapPost($"{EndpointConfig.BaseApiPath}/flight/airport", async (CreateAirportRequestDto request,
|
||||
IMediator mediator, IMapper mapper,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var command = mapper.Map<CreateAirport>(request);
|
||||
|
||||
var result = await mediator.Send(command, cancellationToken);
|
||||
|
||||
var response = result.Adapt<CreateAirportResponseDto>();
|
||||
|
||||
return Results.Ok(response);
|
||||
})
|
||||
.RequireAuthorization(nameof(ApiScope))
|
||||
.WithName("CreateAirport")
|
||||
.WithApiVersionSet(builder.NewApiVersionSet("Flight").Build())
|
||||
.Produces<CreateAirportResponseDto>()
|
||||
.ProducesProblem(StatusCodes.Status400BadRequest)
|
||||
.WithSummary("Create Airport")
|
||||
.WithDescription("Create Airport")
|
||||
.WithOpenApi()
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateAirportValidator : AbstractValidator<CreateAirport>
|
||||
{
|
||||
public CreateAirportValidator()
|
||||
{
|
||||
RuleFor(x => x.Code).NotEmpty().WithMessage("Code is required");
|
||||
RuleFor(x => x.Name).NotEmpty().WithMessage("Name is required");
|
||||
RuleFor(x => x.Address).NotEmpty().WithMessage("Address is required");
|
||||
}
|
||||
}
|
||||
|
||||
internal class CreateAirportHandler : IRequestHandler<CreateAirport, CreateAirportResult>
|
||||
{
|
||||
private readonly FlightDbContext _flightDbContext;
|
||||
|
||||
public CreateAirportHandler(FlightDbContext flightDbContext)
|
||||
{
|
||||
_flightDbContext = flightDbContext;
|
||||
}
|
||||
|
||||
public async Task<CreateAirportResult> Handle(CreateAirport request, CancellationToken cancellationToken)
|
||||
{
|
||||
Guard.Against.Null(request, nameof(request));
|
||||
|
||||
var airport =
|
||||
await _flightDbContext.Airports.SingleOrDefaultAsync(x => x.Code.Value == request.Code, cancellationToken);
|
||||
|
||||
if (airport is not null)
|
||||
{
|
||||
throw new AirportAlreadyExistException();
|
||||
}
|
||||
|
||||
var airportEntity = Models.Airport.Create(AirportId.Of(request.Id), Name.Of(request.Name), Address.Of(request.Address), Code.Of(request.Code));
|
||||
|
||||
var newAirport = (await _flightDbContext.Airports.AddAsync(airportEntity, cancellationToken)).Entity;
|
||||
|
||||
return new CreateAirportResult(newAirport.Id);
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using BookingMonolith.Flight.Airports.Exceptions;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using BuildingBlocks.Core.CQRS;
|
||||
using BuildingBlocks.Core.Event;
|
||||
using MapsterMapper;
|
||||
using MediatR;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Features.CreatingAirport.V1;
|
||||
|
||||
public record CreateAirportMongo(Guid Id, string Name, string Address, string Code, bool IsDeleted = false) : InternalCommand;
|
||||
|
||||
internal class CreateAirportMongoHandler : ICommandHandler<CreateAirportMongo>
|
||||
{
|
||||
private readonly FlightReadDbContext _flightReadDbContext;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CreateAirportMongoHandler(
|
||||
FlightReadDbContext flightReadDbContext,
|
||||
IMapper mapper)
|
||||
{
|
||||
_flightReadDbContext = flightReadDbContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(CreateAirportMongo request, CancellationToken cancellationToken)
|
||||
{
|
||||
Guard.Against.Null(request, nameof(request));
|
||||
|
||||
var airportReadModel = _mapper.Map<AirportReadModel>(request);
|
||||
|
||||
var aircraft = await _flightReadDbContext.Airport.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.AirportId == airportReadModel.AirportId &&
|
||||
!x.IsDeleted, cancellationToken);
|
||||
|
||||
if (aircraft is not null)
|
||||
{
|
||||
throw new AirportAlreadyExistException();
|
||||
}
|
||||
|
||||
await _flightReadDbContext.Airport.InsertOneAsync(airportReadModel, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Features.CreatingAirport.V1;
|
||||
using BookingMonolith.Flight.Airports.ValueObjects;
|
||||
using BuildingBlocks.Core.Model;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.Models;
|
||||
|
||||
public record Airport : Aggregate<AirportId>
|
||||
{
|
||||
public Name Name { get; private set; } = default!;
|
||||
public Address Address { get; private set; } = default!;
|
||||
public Code Code { get; private set; } = default!;
|
||||
|
||||
public static Airport Create(AirportId id, Name name, Address address, Code code, bool isDeleted = false)
|
||||
{
|
||||
var airport = new Airport
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Address = address,
|
||||
Code = code
|
||||
};
|
||||
|
||||
var @event = new AirportCreatedDomainEvent(
|
||||
airport.Id,
|
||||
airport.Name,
|
||||
airport.Address,
|
||||
airport.Code,
|
||||
isDeleted);
|
||||
|
||||
airport.AddDomainEvent(@event);
|
||||
|
||||
return airport;
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Airports.Models;
|
||||
|
||||
public class AirportReadModel
|
||||
{
|
||||
public required Guid Id { get; init; }
|
||||
public required Guid AirportId { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public string Address { get; init; }
|
||||
public required string Code { get; init; }
|
||||
public required bool IsDeleted { get; init; }
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.ValueObjects;
|
||||
|
||||
public class Address
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private Address(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Address Of(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new InvalidAddressException();
|
||||
}
|
||||
|
||||
return new Address(value);
|
||||
}
|
||||
|
||||
public static implicit operator string(Address address)
|
||||
{
|
||||
return address.Value;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.ValueObjects;
|
||||
|
||||
public record AirportId
|
||||
{
|
||||
public Guid Value { get; }
|
||||
|
||||
private AirportId(Guid value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static AirportId Of(Guid value)
|
||||
{
|
||||
if (value == Guid.Empty)
|
||||
{
|
||||
throw new InvalidAirportIdException(value);
|
||||
}
|
||||
|
||||
return new AirportId(value);
|
||||
}
|
||||
|
||||
public static implicit operator Guid(AirportId airportId)
|
||||
{
|
||||
return airportId.Value;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.ValueObjects;
|
||||
|
||||
public record Code
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private Code(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Code Of(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new InvalidCodeException();
|
||||
}
|
||||
|
||||
return new Code(value);
|
||||
}
|
||||
|
||||
public static implicit operator string(Code code)
|
||||
{
|
||||
return code.Value;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Airports.ValueObjects;
|
||||
|
||||
public record Name
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private Name(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static Name Of(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new InvalidNameException();
|
||||
}
|
||||
|
||||
return new Name(value);
|
||||
}
|
||||
|
||||
public static implicit operator string(Name name)
|
||||
{
|
||||
return name.Value;
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Configurations;
|
||||
|
||||
[RegisterFlightConfiguration]
|
||||
public class AircraftConfiguration : IEntityTypeConfiguration<Aircraft>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Aircraft> builder)
|
||||
{
|
||||
|
||||
builder.ToTable(nameof(Aircraft));
|
||||
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever()
|
||||
.HasConversion<Guid>(aircraftId => aircraftId.Value, dbId => AircraftId.Of(dbId));
|
||||
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.Name,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Aircraft.Name))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.Model,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Aircraft.Model))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.ManufacturingYear,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Aircraft.ManufacturingYear))
|
||||
.HasMaxLength(5)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Airports.ValueObjects;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Configurations;
|
||||
|
||||
[RegisterFlightConfiguration]
|
||||
public class AirportConfiguration : IEntityTypeConfiguration<Airport>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Airport> builder)
|
||||
{
|
||||
|
||||
builder.ToTable(nameof(Airport));
|
||||
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever()
|
||||
.HasConversion<Guid>(airportId => airportId.Value, dbId => AirportId.Of(dbId));
|
||||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.Name,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Airport.Name))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.Address,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Airport.Address))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.Code,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Airport.Code))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Flights.ValueObjects;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Configurations;
|
||||
|
||||
[RegisterFlightConfiguration]
|
||||
public class FlightConfiguration : IEntityTypeConfiguration<Flights.Models.Flight>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Flights.Models.Flight> builder)
|
||||
{
|
||||
RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, nameof(Flight));
|
||||
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever()
|
||||
.HasConversion<Guid>(flight => flight.Value, dbId => FlightId.Of(dbId));
|
||||
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.FlightNumber,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Flights.Models.Flight.FlightNumber))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder
|
||||
.HasOne<Aircraft>()
|
||||
.WithMany()
|
||||
.HasForeignKey(p => p.AircraftId)
|
||||
.IsRequired();
|
||||
|
||||
builder
|
||||
.HasOne<Airport>()
|
||||
.WithMany()
|
||||
.HasForeignKey(d => d.DepartureAirportId)
|
||||
.IsRequired();
|
||||
|
||||
builder
|
||||
.HasOne<Airport>()
|
||||
.WithMany()
|
||||
.HasForeignKey(d => d.ArriveAirportId)
|
||||
.IsRequired();
|
||||
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.DurationMinutes,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Flights.Models.Flight.DurationMinutes))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.Property(x => x.Status)
|
||||
.HasDefaultValue(Flights.Enums.FlightStatus.Unknown)
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => (Flights.Enums.FlightStatus)Enum.Parse(typeof(Flights.Enums.FlightStatus), x));
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.Price,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Flights.Models.Flight.Price))
|
||||
.HasMaxLength(10)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.ArriveDate,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Flights.Models.Flight.ArriveDate))
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.DepartureDate,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Flights.Models.Flight.DepartureDate))
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.FlightDate,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Flights.Models.Flight.FlightDate))
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
using BookingMonolith.Flight.Seats.Models;
|
||||
using BookingMonolith.Flight.Seats.ValueObjects;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Configurations;
|
||||
|
||||
[RegisterFlightConfiguration]
|
||||
public class SeatConfiguration : IEntityTypeConfiguration<Seat>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Seat> builder)
|
||||
{
|
||||
builder.ToTable(nameof(Seat));
|
||||
|
||||
builder.HasKey(r => r.Id);
|
||||
builder.Property(r => r.Id).ValueGeneratedNever()
|
||||
.HasConversion<Guid>(seatId => seatId.Value, dbId => SeatId.Of(dbId));
|
||||
|
||||
builder.Property(r => r.Version).IsConcurrencyToken();
|
||||
|
||||
builder.OwnsOne(
|
||||
x => x.SeatNumber,
|
||||
a =>
|
||||
{
|
||||
a.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Seat.SeatNumber))
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
}
|
||||
);
|
||||
|
||||
builder
|
||||
.HasOne<Flights.Models.Flight>()
|
||||
.WithMany()
|
||||
.HasForeignKey(p => p.FlightId);
|
||||
|
||||
builder.Property(x => x.Class)
|
||||
.HasDefaultValue(Seats.Enums.SeatClass.Unknown)
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => (Seats.Enums.SeatClass)Enum.Parse(typeof(Seats.Enums.SeatClass), x));
|
||||
|
||||
builder.Property(x => x.Type)
|
||||
.HasDefaultValue(Seats.Enums.SeatType.Unknown)
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => (Seats.Enums.SeatType)Enum.Parse(typeof(Seats.Enums.SeatType), x));
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace BookingMonolith.Flight.Data
|
||||
{
|
||||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<FlightDbContext>
|
||||
{
|
||||
public FlightDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var builder = new DbContextOptionsBuilder<FlightDbContext>();
|
||||
|
||||
builder.UseNpgsql("Server=localhost;Port=5432;Database=booking_monolith;User Id=postgres;Password=postgres;Include Error Detail=true")
|
||||
.UseSnakeCaseNamingConvention();
|
||||
return new FlightDbContext(builder.Options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,100 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using System.Transactions;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.PersistMessageProcessor;
|
||||
using BuildingBlocks.Polly;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BookingMonolith.Flight.Data;
|
||||
|
||||
public class EfTxFlightBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
|
||||
where TRequest : notnull, IRequest<TResponse>
|
||||
where TResponse : notnull
|
||||
{
|
||||
private readonly ILogger<EfTxFlightBehavior<TRequest, TResponse>> _logger;
|
||||
private readonly FlightDbContext _flightDbContext;
|
||||
private readonly IPersistMessageDbContext _persistMessageDbContext;
|
||||
private readonly IEventDispatcher _eventDispatcher;
|
||||
|
||||
public EfTxFlightBehavior(
|
||||
ILogger<EfTxFlightBehavior<TRequest, TResponse>> logger,
|
||||
FlightDbContext flightDbContext,
|
||||
IPersistMessageDbContext persistMessageDbContext,
|
||||
IEventDispatcher eventDispatcher
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_flightDbContext = flightDbContext;
|
||||
_persistMessageDbContext = persistMessageDbContext;
|
||||
_eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
public async Task<TResponse> Handle(
|
||||
TRequest request,
|
||||
RequestHandlerDelegate<TResponse> next,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"{Prefix} Handled command {MediatrRequest}",
|
||||
GetType().Name,
|
||||
typeof(TRequest).FullName);
|
||||
|
||||
_logger.LogDebug(
|
||||
"{Prefix} Handled command {MediatrRequest} with content {RequestContent}",
|
||||
GetType().Name,
|
||||
typeof(TRequest).FullName,
|
||||
JsonSerializer.Serialize(request));
|
||||
|
||||
var response = await next();
|
||||
|
||||
_logger.LogInformation(
|
||||
"{Prefix} Executed the {MediatrRequest} request",
|
||||
GetType().Name,
|
||||
typeof(TRequest).FullName);
|
||||
|
||||
while (true)
|
||||
{
|
||||
var domainEvents = _flightDbContext.GetDomainEvents();
|
||||
|
||||
if (domainEvents is null || !domainEvents.Any())
|
||||
{
|
||||
return response;
|
||||
}
|
||||
|
||||
_logger.LogInformation(
|
||||
"{Prefix} Open the transaction for {MediatrRequest}",
|
||||
GetType().Name,
|
||||
typeof(TRequest).FullName);
|
||||
|
||||
using var scope = new TransactionScope(
|
||||
TransactionScopeOption.Required,
|
||||
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted },
|
||||
TransactionScopeAsyncFlowOption.Enabled);
|
||||
|
||||
await _eventDispatcher.SendAsync(
|
||||
domainEvents.ToArray(),
|
||||
typeof(TRequest),
|
||||
cancellationToken);
|
||||
|
||||
// Save data to database with some retry policy in distributed transaction
|
||||
await _flightDbContext.RetryOnFailure(
|
||||
async () =>
|
||||
{
|
||||
await _flightDbContext.SaveChangesAsync(cancellationToken);
|
||||
});
|
||||
|
||||
// Save data to database with some retry policy in distributed transaction
|
||||
await _persistMessageDbContext.RetryOnFailure(
|
||||
async () =>
|
||||
{
|
||||
await _persistMessageDbContext.SaveChangesAsync(cancellationToken);
|
||||
});
|
||||
|
||||
scope.Complete();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
using System.Reflection;
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Seats.Models;
|
||||
using BuildingBlocks.EFCore;
|
||||
using BuildingBlocks.Web;
|
||||
using Humanizer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BookingMonolith.Flight.Data;
|
||||
|
||||
public sealed class FlightDbContext : AppDbContextBase
|
||||
{
|
||||
public FlightDbContext(DbContextOptions<FlightDbContext> options, ICurrentUserProvider? currentUserProvider = null,
|
||||
ILogger<FlightDbContext>? logger = null) : base(
|
||||
options, currentUserProvider, logger)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Flights.Models.Flight> Flights => Set<Flights.Models.Flight>();
|
||||
public DbSet<Airport> Airports => Set<Airport>();
|
||||
public DbSet<Aircraft> Aircraft => Set<Aircraft>();
|
||||
public DbSet<Seat> Seats => Set<Seat>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
var types = typeof(FlightRoot).Assembly.GetTypes()
|
||||
.Where(t => t.GetCustomAttribute<RegisterFlightConfigurationAttribute>() != null)
|
||||
.ToList();
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
dynamic configuration = Activator.CreateInstance(type)!;
|
||||
builder.ApplyConfiguration(configuration);
|
||||
}
|
||||
|
||||
builder.HasDefaultSchema(nameof(Flight).Underscore());
|
||||
builder.FilterSoftDeletedProperties();
|
||||
builder.ToSnakeCaseTables();
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Flights.Models;
|
||||
using BookingMonolith.Flight.Seats.Models;
|
||||
using BuildingBlocks.Mongo;
|
||||
using Humanizer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace BookingMonolith.Flight.Data;
|
||||
|
||||
public class FlightReadDbContext : MongoDbContext
|
||||
{
|
||||
public FlightReadDbContext(IOptions<MongoOptions> options) : base(options)
|
||||
{
|
||||
Flight = GetCollection<FlightReadModel>(nameof(Flight).Underscore());
|
||||
Aircraft = GetCollection<AircraftReadModel>(nameof(Aircraft).Underscore());
|
||||
Airport = GetCollection<AirportReadModel>(nameof(Airport).Underscore());
|
||||
Seat = GetCollection<SeatReadModel>(nameof(Seat).Underscore());
|
||||
}
|
||||
|
||||
public IMongoCollection<FlightReadModel> Flight { get; }
|
||||
public IMongoCollection<AircraftReadModel> Aircraft { get; }
|
||||
public IMongoCollection<AirportReadModel> Airport { get; }
|
||||
public IMongoCollection<SeatReadModel> Seat { get; }
|
||||
}
|
||||
@ -1,584 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlightDbContext))]
|
||||
[Migration("20250407215512_initial")]
|
||||
partial class initial
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("flight")
|
||||
.HasAnnotation("ProductVersion", "9.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Aircrafts.Models.Aircraft", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b.ToTable("aircraft", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Airports.Models.Airport", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b.ToTable("airport", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Flights.Models.Flight", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("aircraft_id");
|
||||
|
||||
b.Property<Guid>("ArriveAirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("arrive_airport_id");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<Guid>("DepartureAirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("departure_airport_id");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("Unknown")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b.HasIndex("AircraftId")
|
||||
.HasDatabaseName("ix_flight_aircraft_id");
|
||||
|
||||
b.HasIndex("ArriveAirportId")
|
||||
.HasDatabaseName("ix_flight_arrive_airport_id");
|
||||
|
||||
b.HasIndex("DepartureAirportId")
|
||||
.HasDatabaseName("ix_flight_departure_airport_id");
|
||||
|
||||
b.ToTable("flight", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Seats.Models.Seat", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Class")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("Unknown")
|
||||
.HasColumnName("class");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("flight_id");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("Unknown")
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_seat");
|
||||
|
||||
b.HasIndex("FlightId")
|
||||
.HasDatabaseName("ix_seat_flight_id");
|
||||
|
||||
b.ToTable("seat", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Aircrafts.Models.Aircraft", b =>
|
||||
{
|
||||
b.OwnsOne("BookingMonolith.Flight.Aircrafts.ValueObjects.ManufacturingYear", "ManufacturingYear", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<int>("Value")
|
||||
.HasMaxLength(5)
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("manufacturing_year");
|
||||
|
||||
b1.HasKey("AircraftId")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b1.ToTable("aircraft", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AircraftId")
|
||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Aircrafts.ValueObjects.Model", "Model", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("model");
|
||||
|
||||
b1.HasKey("AircraftId")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b1.ToTable("aircraft", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AircraftId")
|
||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Aircrafts.ValueObjects.Name", "Name", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b1.HasKey("AircraftId")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b1.ToTable("aircraft", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AircraftId")
|
||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
||||
});
|
||||
|
||||
b.Navigation("ManufacturingYear")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Model")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Airports.Models.Airport", b =>
|
||||
{
|
||||
b.OwnsOne("BookingMonolith.Flight.Airports.ValueObjects.Address", "Address", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("address");
|
||||
|
||||
b1.HasKey("AirportId")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b1.ToTable("airport", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AirportId")
|
||||
.HasConstraintName("fk_airport_airport_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Airports.ValueObjects.Code", "Code", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("code");
|
||||
|
||||
b1.HasKey("AirportId")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b1.ToTable("airport", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AirportId")
|
||||
.HasConstraintName("fk_airport_airport_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Airports.ValueObjects.Name", "Name", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b1.HasKey("AirportId")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b1.ToTable("airport", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AirportId")
|
||||
.HasConstraintName("fk_airport_airport_id");
|
||||
});
|
||||
|
||||
b.Navigation("Address")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Code")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Flights.Models.Flight", b =>
|
||||
{
|
||||
b.HasOne("BookingMonolith.Flight.Aircrafts.Models.Aircraft", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("AircraftId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_flight_aircraft_aircraft_id");
|
||||
|
||||
b.HasOne("BookingMonolith.Flight.Airports.Models.Airport", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ArriveAirportId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_flight_airport_arrive_airport_id");
|
||||
|
||||
b.HasOne("BookingMonolith.Flight.Airports.Models.Airport", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("DepartureAirportId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_flight_airport_departure_airport_id");
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.ArriveDate", "ArriveDate", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<DateTime>("Value")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("arrive_date");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.DepartureDate", "DepartureDate", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<DateTime>("Value")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("departure_date");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.DurationMinutes", "DurationMinutes", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("duration_minutes");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.FlightDate", "FlightDate", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<DateTime>("Value")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("flight_date");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.FlightNumber", "FlightNumber", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("flight_number");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.Price", "Price", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("price");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.Navigation("ArriveDate")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("DepartureDate")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("DurationMinutes")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FlightDate")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FlightNumber")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Price")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Seats.Models.Seat", b =>
|
||||
{
|
||||
b.HasOne("BookingMonolith.Flight.Flights.Models.Flight", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("FlightId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_seat_flight_flight_id");
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Seats.ValueObjects.SeatNumber", "SeatNumber", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("SeatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("seat_number");
|
||||
|
||||
b1.HasKey("SeatId")
|
||||
.HasName("pk_seat");
|
||||
|
||||
b1.ToTable("seat", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("SeatId")
|
||||
.HasConstraintName("fk_seat_seat_id");
|
||||
});
|
||||
|
||||
b.Navigation("SeatNumber")
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,182 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class initial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.EnsureSchema(
|
||||
name: "flight");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "aircraft",
|
||||
schema: "flight",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
model = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
manufacturing_year = table.Column<int>(type: "integer", maxLength: 5, nullable: false),
|
||||
created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
created_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
last_modified = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
last_modified_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
is_deleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
version = table.Column<long>(type: "bigint", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_aircraft", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "airport",
|
||||
schema: "flight",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
address = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
created_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
last_modified = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
last_modified_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
is_deleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
version = table.Column<long>(type: "bigint", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_airport", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "flight",
|
||||
schema: "flight",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
flight_number = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
aircraft_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
departure_airport_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
arrive_airport_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
duration_minutes = table.Column<decimal>(type: "numeric", maxLength: 50, nullable: false),
|
||||
status = table.Column<string>(type: "text", nullable: false, defaultValue: "Unknown"),
|
||||
price = table.Column<decimal>(type: "numeric", maxLength: 10, nullable: false),
|
||||
arrive_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
departure_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
flight_date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
created_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
last_modified = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
last_modified_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
is_deleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
version = table.Column<long>(type: "bigint", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_flight", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "fk_flight_aircraft_aircraft_id",
|
||||
column: x => x.aircraft_id,
|
||||
principalSchema: "flight",
|
||||
principalTable: "aircraft",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_flight_airport_arrive_airport_id",
|
||||
column: x => x.arrive_airport_id,
|
||||
principalSchema: "flight",
|
||||
principalTable: "airport",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_flight_airport_departure_airport_id",
|
||||
column: x => x.departure_airport_id,
|
||||
principalSchema: "flight",
|
||||
principalTable: "airport",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "seat",
|
||||
schema: "flight",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
seat_number = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
type = table.Column<string>(type: "text", nullable: false, defaultValue: "Unknown"),
|
||||
@class = table.Column<string>(name: "class", type: "text", nullable: false, defaultValue: "Unknown"),
|
||||
flight_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
created_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
last_modified = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
last_modified_by = table.Column<long>(type: "bigint", nullable: true),
|
||||
is_deleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
version = table.Column<long>(type: "bigint", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_seat", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "fk_seat_flight_flight_id",
|
||||
column: x => x.flight_id,
|
||||
principalSchema: "flight",
|
||||
principalTable: "flight",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_flight_aircraft_id",
|
||||
schema: "flight",
|
||||
table: "flight",
|
||||
column: "aircraft_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_flight_arrive_airport_id",
|
||||
schema: "flight",
|
||||
table: "flight",
|
||||
column: "arrive_airport_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_flight_departure_airport_id",
|
||||
schema: "flight",
|
||||
table: "flight",
|
||||
column: "departure_airport_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_seat_flight_id",
|
||||
schema: "flight",
|
||||
table: "seat",
|
||||
column: "flight_id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "seat",
|
||||
schema: "flight");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "flight",
|
||||
schema: "flight");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "aircraft",
|
||||
schema: "flight");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "airport",
|
||||
schema: "flight");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,581 +0,0 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using BookingMonolith.Flight.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlightDbContext))]
|
||||
partial class FlightDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("flight")
|
||||
.HasAnnotation("ProductVersion", "9.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Aircrafts.Models.Aircraft", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b.ToTable("aircraft", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Airports.Models.Airport", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b.ToTable("airport", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Flights.Models.Flight", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("aircraft_id");
|
||||
|
||||
b.Property<Guid>("ArriveAirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("arrive_airport_id");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<Guid>("DepartureAirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("departure_airport_id");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("Unknown")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b.HasIndex("AircraftId")
|
||||
.HasDatabaseName("ix_flight_aircraft_id");
|
||||
|
||||
b.HasIndex("ArriveAirportId")
|
||||
.HasDatabaseName("ix_flight_arrive_airport_id");
|
||||
|
||||
b.HasIndex("DepartureAirportId")
|
||||
.HasDatabaseName("ix_flight_departure_airport_id");
|
||||
|
||||
b.ToTable("flight", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Seats.Models.Seat", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Class")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("Unknown")
|
||||
.HasColumnName("class");
|
||||
|
||||
b.Property<DateTime?>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long?>("CreatedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("created_by");
|
||||
|
||||
b.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("flight_id");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_deleted");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_modified");
|
||||
|
||||
b.Property<long?>("LastModifiedBy")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_modified_by");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("text")
|
||||
.HasDefaultValue("Unknown")
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<long>("Version")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_seat");
|
||||
|
||||
b.HasIndex("FlightId")
|
||||
.HasDatabaseName("ix_seat_flight_id");
|
||||
|
||||
b.ToTable("seat", "flight");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Aircrafts.Models.Aircraft", b =>
|
||||
{
|
||||
b.OwnsOne("BookingMonolith.Flight.Aircrafts.ValueObjects.ManufacturingYear", "ManufacturingYear", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<int>("Value")
|
||||
.HasMaxLength(5)
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("manufacturing_year");
|
||||
|
||||
b1.HasKey("AircraftId")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b1.ToTable("aircraft", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AircraftId")
|
||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Aircrafts.ValueObjects.Model", "Model", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("model");
|
||||
|
||||
b1.HasKey("AircraftId")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b1.ToTable("aircraft", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AircraftId")
|
||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Aircrafts.ValueObjects.Name", "Name", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AircraftId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b1.HasKey("AircraftId")
|
||||
.HasName("pk_aircraft");
|
||||
|
||||
b1.ToTable("aircraft", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AircraftId")
|
||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
||||
});
|
||||
|
||||
b.Navigation("ManufacturingYear")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Model")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Airports.Models.Airport", b =>
|
||||
{
|
||||
b.OwnsOne("BookingMonolith.Flight.Airports.ValueObjects.Address", "Address", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("address");
|
||||
|
||||
b1.HasKey("AirportId")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b1.ToTable("airport", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AirportId")
|
||||
.HasConstraintName("fk_airport_airport_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Airports.ValueObjects.Code", "Code", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("code");
|
||||
|
||||
b1.HasKey("AirportId")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b1.ToTable("airport", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AirportId")
|
||||
.HasConstraintName("fk_airport_airport_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Airports.ValueObjects.Name", "Name", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("AirportId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b1.HasKey("AirportId")
|
||||
.HasName("pk_airport");
|
||||
|
||||
b1.ToTable("airport", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("AirportId")
|
||||
.HasConstraintName("fk_airport_airport_id");
|
||||
});
|
||||
|
||||
b.Navigation("Address")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Code")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Flights.Models.Flight", b =>
|
||||
{
|
||||
b.HasOne("BookingMonolith.Flight.Aircrafts.Models.Aircraft", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("AircraftId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_flight_aircraft_aircraft_id");
|
||||
|
||||
b.HasOne("BookingMonolith.Flight.Airports.Models.Airport", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ArriveAirportId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_flight_airport_arrive_airport_id");
|
||||
|
||||
b.HasOne("BookingMonolith.Flight.Airports.Models.Airport", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("DepartureAirportId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_flight_airport_departure_airport_id");
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.ArriveDate", "ArriveDate", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<DateTime>("Value")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("arrive_date");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.DepartureDate", "DepartureDate", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<DateTime>("Value")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("departure_date");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.DurationMinutes", "DurationMinutes", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("duration_minutes");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.FlightDate", "FlightDate", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<DateTime>("Value")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("flight_date");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.FlightNumber", "FlightNumber", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("flight_number");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Flights.ValueObjects.Price", "Price", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("FlightId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("price");
|
||||
|
||||
b1.HasKey("FlightId")
|
||||
.HasName("pk_flight");
|
||||
|
||||
b1.ToTable("flight", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("FlightId")
|
||||
.HasConstraintName("fk_flight_flight_id");
|
||||
});
|
||||
|
||||
b.Navigation("ArriveDate")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("DepartureDate")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("DurationMinutes")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FlightDate")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("FlightNumber")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Price")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookingMonolith.Flight.Seats.Models.Seat", b =>
|
||||
{
|
||||
b.HasOne("BookingMonolith.Flight.Flights.Models.Flight", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("FlightId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_seat_flight_flight_id");
|
||||
|
||||
b.OwnsOne("BookingMonolith.Flight.Seats.ValueObjects.SeatNumber", "SeatNumber", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("SeatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("seat_number");
|
||||
|
||||
b1.HasKey("SeatId")
|
||||
.HasName("pk_seat");
|
||||
|
||||
b1.ToTable("seat", "flight");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("SeatId")
|
||||
.HasConstraintName("fk_seat_seat_id");
|
||||
});
|
||||
|
||||
b.Navigation("SeatNumber")
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Data;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterFlightConfigurationAttribute : Attribute { }
|
||||
@ -1,88 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Flights.Models;
|
||||
using BookingMonolith.Flight.Seats.Models;
|
||||
using BuildingBlocks.EFCore;
|
||||
using MapsterMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Seed;
|
||||
|
||||
public class FlightDataSeeder(
|
||||
FlightDbContext flightDbContext,
|
||||
FlightReadDbContext flightReadDbContext,
|
||||
IMapper mapper
|
||||
) : IDataSeeder
|
||||
{
|
||||
public async Task SeedAllAsync()
|
||||
{
|
||||
var pendingMigrations = await flightDbContext.Database.GetPendingMigrationsAsync();
|
||||
|
||||
if (!pendingMigrations.Any())
|
||||
{
|
||||
await SeedAirportAsync();
|
||||
await SeedAircraftAsync();
|
||||
await SeedFlightAsync();
|
||||
await SeedSeatAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SeedAirportAsync()
|
||||
{
|
||||
if (!await EntityFrameworkQueryableExtensions.AnyAsync(flightDbContext.Airports))
|
||||
{
|
||||
await flightDbContext.Airports.AddRangeAsync(InitialData.Airports);
|
||||
await flightDbContext.SaveChangesAsync();
|
||||
|
||||
if (!await MongoQueryable.AnyAsync(flightReadDbContext.Airport.AsQueryable()))
|
||||
{
|
||||
await flightReadDbContext.Airport.InsertManyAsync(mapper.Map<List<AirportReadModel>>(InitialData.Airports));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SeedAircraftAsync()
|
||||
{
|
||||
if (!await EntityFrameworkQueryableExtensions.AnyAsync(flightDbContext.Aircraft))
|
||||
{
|
||||
await flightDbContext.Aircraft.AddRangeAsync(InitialData.Aircrafts);
|
||||
await flightDbContext.SaveChangesAsync();
|
||||
|
||||
if (!await MongoQueryable.AnyAsync(flightReadDbContext.Aircraft.AsQueryable()))
|
||||
{
|
||||
await flightReadDbContext.Aircraft.InsertManyAsync(mapper.Map<List<AircraftReadModel>>(InitialData.Aircrafts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task SeedSeatAsync()
|
||||
{
|
||||
if (!await EntityFrameworkQueryableExtensions.AnyAsync(flightDbContext.Seats))
|
||||
{
|
||||
await flightDbContext.Seats.AddRangeAsync(InitialData.Seats);
|
||||
await flightDbContext.SaveChangesAsync();
|
||||
|
||||
if (!await MongoQueryable.AnyAsync(flightReadDbContext.Seat.AsQueryable()))
|
||||
{
|
||||
await flightReadDbContext.Seat.InsertManyAsync(mapper.Map<List<SeatReadModel>>(InitialData.Seats));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SeedFlightAsync()
|
||||
{
|
||||
if (!await EntityFrameworkQueryableExtensions.AnyAsync(flightDbContext.Flights))
|
||||
{
|
||||
await flightDbContext.Flights.AddRangeAsync(InitialData.Flights);
|
||||
await flightDbContext.SaveChangesAsync();
|
||||
|
||||
if (!await MongoQueryable.AnyAsync(flightReadDbContext.Flight.AsQueryable()))
|
||||
{
|
||||
await flightReadDbContext.Flight.InsertManyAsync(mapper.Map<List<FlightReadModel>>(InitialData.Flights));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Models;
|
||||
using BookingMonolith.Flight.Aircrafts.ValueObjects;
|
||||
using BookingMonolith.Flight.Airports.Models;
|
||||
using BookingMonolith.Flight.Airports.ValueObjects;
|
||||
using BookingMonolith.Flight.Flights.ValueObjects;
|
||||
using BookingMonolith.Flight.Seats.Models;
|
||||
using BookingMonolith.Flight.Seats.ValueObjects;
|
||||
using MassTransit;
|
||||
|
||||
namespace BookingMonolith.Flight.Data.Seed;
|
||||
|
||||
using AirportName = Airports.ValueObjects.Name;
|
||||
using Name = Aircrafts.ValueObjects.Name;
|
||||
|
||||
public static class InitialData
|
||||
{
|
||||
public static List<Airport> Airports { get; }
|
||||
public static List<Aircraft> Aircrafts { get; }
|
||||
public static List<Seat> Seats { get; }
|
||||
public static List<Flights.Models.Flight> Flights { get; }
|
||||
|
||||
|
||||
static InitialData()
|
||||
{
|
||||
Airports = new List<Airport>
|
||||
{
|
||||
Airport.Create(AirportId.Of(new Guid("3c5c0000-97c6-fc34-a0cb-08db322230c8")), AirportName.Of("Lisbon International Airport"), Address.Of("LIS"), Code.Of("12988")),
|
||||
Airport.Create(AirportId.Of(new Guid("3c5c0000-97c6-fc34-fc3c-08db322230c8")), AirportName.Of("Sao Paulo International Airport"), Address.Of("BRZ"), Code.Of("11200"))
|
||||
};
|
||||
|
||||
Aircrafts = new List<Aircraft>
|
||||
{
|
||||
Aircraft.Create(AircraftId.Of(new Guid("3c5c0000-97c6-fc34-fcd3-08db322230c8")), Name.Of("Boeing 737"), Model.Of("B737"), ManufacturingYear.Of(2005)),
|
||||
Aircraft.Create(AircraftId.Of(new Guid("3c5c0000-97c6-fc34-2e04-08db322230c9")), Name.Of("Airbus 300"), Model.Of("A300"), ManufacturingYear.Of(2000)),
|
||||
Aircraft.Create(AircraftId.Of(new Guid("3c5c0000-97c6-fc34-2e11-08db322230c9")), Name.Of("Airbus 320"), Model.Of("A320"), ManufacturingYear.Of(2003))
|
||||
};
|
||||
|
||||
|
||||
Flights = new List<Flights.Models.Flight>
|
||||
{
|
||||
Flight.Flights.Models.Flight.Create(FlightId.Of(new Guid("3c5c0000-97c6-fc34-2eb9-08db322230c9")), FlightNumber.Of("BD467"), AircraftId.Of(Aircrafts.First().Id.Value), AirportId.Of( Airports.First().Id), DepartureDate.Of(new DateTime(2022, 1, 31, 12, 0, 0)),
|
||||
ArriveDate.Of(new DateTime(2022, 1, 31, 14, 0, 0)),
|
||||
AirportId.Of(Airports.Last().Id), DurationMinutes.Of(120m),
|
||||
FlightDate.Of(new DateTime(2022, 1, 31, 13, 0, 0)), Flight.Flights.Enums.FlightStatus.Completed,
|
||||
Price.Of(8000))
|
||||
};
|
||||
|
||||
Seats = new List<Seat>
|
||||
{
|
||||
Seat.Create(SeatId.Of(NewId.NextGuid()), SeatNumber.Of( "12A"),Flight.Seats.Enums.SeatType.Window, Flight.Seats.Enums.SeatClass.Economy, FlightId.Of((Guid)Flights.First().Id)),
|
||||
Seat.Create(SeatId.Of(NewId.NextGuid()), SeatNumber.Of("12B"), Flight.Seats.Enums.SeatType.Window, Flight.Seats.Enums.SeatClass.Economy, FlightId.Of((Guid)Flights.First().Id)),
|
||||
Seat.Create(SeatId.Of(NewId.NextGuid()), SeatNumber.Of("12C"), Flight.Seats.Enums.SeatType.Middle, Flight.Seats.Enums.SeatClass.Economy, FlightId.Of((Guid) Flights.First().Id)),
|
||||
Seat.Create(SeatId.Of(NewId.NextGuid()), SeatNumber.Of("12D"), Flight.Seats.Enums.SeatType.Middle, Flight.Seats.Enums.SeatClass.Economy, FlightId.Of((Guid) Flights.First().Id)),
|
||||
Seat.Create(SeatId.Of(NewId.NextGuid()), SeatNumber.Of("12E"), Flight.Seats.Enums.SeatType.Aisle, Flight.Seats.Enums.SeatClass.Economy, FlightId.Of((Guid) Flights.First().Id)),
|
||||
Seat.Create(SeatId.Of(NewId.NextGuid()), SeatNumber.Of("12F"), Flight.Seats.Enums.SeatType.Aisle, Flight.Seats.Enums.SeatClass.Economy, FlightId.Of((Guid) Flights.First().Id))
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
dotnet ef migrations add initial --context FlightDbContext -o "Flight\Data\Migrations"
|
||||
dotnet ef database update --context FlightDbContext
|
||||
@ -1,49 +0,0 @@
|
||||
using BookingMonolith.Flight.Aircrafts.Features.CreatingAircraft.V1;
|
||||
using BookingMonolith.Flight.Airports.Features.CreatingAirport.V1;
|
||||
using BookingMonolith.Flight.Flights.Features.CreatingFlight.V1;
|
||||
using BookingMonolith.Flight.Flights.Features.DeletingFlight.V1;
|
||||
using BookingMonolith.Flight.Flights.Features.UpdatingFlight.V1;
|
||||
using BookingMonolith.Flight.Seats.Features.CreatingSeat.V1;
|
||||
using BookingMonolith.Flight.Seats.Features.ReservingSeat.V1;
|
||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||
using BuildingBlocks.Core;
|
||||
using BuildingBlocks.Core.Event;
|
||||
|
||||
namespace BookingMonolith.Flight;
|
||||
|
||||
// ref: https://www.ledjonbehluli.com/posts/domain_to_integration_event/
|
||||
public sealed class FlightEventMapper : IEventMapper
|
||||
{
|
||||
public IIntegrationEvent? MapToIntegrationEvent(IDomainEvent @event)
|
||||
{
|
||||
return @event switch
|
||||
{
|
||||
FlightCreatedDomainEvent e => new FlightCreated(e.Id),
|
||||
FlightUpdatedDomainEvent e => new FlightUpdated(e.Id),
|
||||
FlightDeletedDomainEvent e => new FlightDeleted(e.Id),
|
||||
AirportCreatedDomainEvent e => new AirportCreated(e.Id),
|
||||
AircraftCreatedDomainEvent e => new AircraftCreated(e.Id),
|
||||
SeatCreatedDomainEvent e => new SeatCreated(e.Id),
|
||||
SeatReservedDomainEvent e => new SeatReserved(e.Id),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public IInternalCommand? MapToInternalCommand(IDomainEvent @event)
|
||||
{
|
||||
return @event switch
|
||||
{
|
||||
FlightCreatedDomainEvent e => new CreateFlightMongo(e.Id, e.FlightNumber, e.AircraftId, e.DepartureDate, e.DepartureAirportId,
|
||||
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
||||
FlightUpdatedDomainEvent e => new UpdateFlightMongo(e.Id, e.FlightNumber, e.AircraftId, e.DepartureDate, e.DepartureAirportId,
|
||||
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
||||
FlightDeletedDomainEvent e => new DeleteFlightMongo(e.Id, e.FlightNumber, e.AircraftId, e.DepartureDate, e.DepartureAirportId,
|
||||
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
||||
AircraftCreatedDomainEvent e => new CreateAircraftMongo(e.Id, e.Name, e.Model, e.ManufacturingYear, e.IsDeleted),
|
||||
AirportCreatedDomainEvent e => new CreateAirportMongo(e.Id, e.Name, e.Address, e.Code, e.IsDeleted),
|
||||
SeatCreatedDomainEvent e => new CreateSeatMongo(e.Id, e.SeatNumber, e.Type, e.Class, e.FlightId, e.IsDeleted),
|
||||
SeatReservedDomainEvent e => new ReserveSeatMongo(e.Id, e.SeatNumber, e.Type, e.Class, e.FlightId, e.IsDeleted),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
namespace BookingMonolith.Flight;
|
||||
|
||||
public class FlightRoot
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Flights.Dtos;
|
||||
public record FlightDto(Guid Id, string FlightNumber, Guid AircraftId, Guid DepartureAirportId,
|
||||
DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate,
|
||||
Enums.FlightStatus Status, decimal Price);
|
||||
@ -1,10 +0,0 @@
|
||||
namespace BookingMonolith.Flight.Flights.Enums;
|
||||
|
||||
public enum FlightStatus
|
||||
{
|
||||
Unknown = 0,
|
||||
Flying = 1,
|
||||
Delay = 2,
|
||||
Canceled = 3,
|
||||
Completed = 4
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Net;
|
||||
using BuildingBlocks.Exception;
|
||||
|
||||
namespace BookingMonolith.Flight.Flights.Exceptions;
|
||||
|
||||
public class FlightAlreadyExistException : AppException
|
||||
{
|
||||
public FlightAlreadyExistException(int? code = default) : base("Flight already exist!", HttpStatusCode.Conflict, code)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Net;
|
||||
using BuildingBlocks.Exception;
|
||||
|
||||
namespace BookingMonolith.Flight.Flights.Exceptions;
|
||||
|
||||
public class FlightNotFountException : AppException
|
||||
{
|
||||
public FlightNotFountException() : base("Flight not found!", HttpStatusCode.NotFound)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
using SmartCharging.Infrastructure.Exceptions;
|
||||
|
||||
namespace BookingMonolith.Flight.Flights.Exceptions;
|
||||
|
||||
public class InvalidArriveDateException : DomainException
|
||||
{
|
||||
public InvalidArriveDateException(DateTime arriveDate)
|
||||
: base($"Arrive Date: '{arriveDate}' is invalid.")
|
||||
{
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user