Compare commits

...

97 Commits
v2.1.0 ... main

Author SHA1 Message Date
Meysam Hadeli
d99d1a9a9a
Merge pull request #374 from meysamhadeli/refactor/refactor-docker-files
refactor: refactor dockerfiles
2026-02-26 23:50:46 +03:30
Meysam Hadeli
6e1fe61a65 refactor: refactor dockerfiles 2026-02-26 23:49:12 +03:30
Meysam Hadeli
a882b3cfe2
Merge pull request #373 from meysamhadeli/fix/fix-ci
fix: fix ci failed
2026-02-24 22:56:10 +03:30
Meysam Hadeli
14cc9e7c96 fix: fix ci failed 2026-02-24 22:54:44 +03:30
Meysam Hadeli
0f66c14299 fix: fix ci failed for tests 2026-02-21 22:00:57 +03:30
Meysam Hadeli
7f9cf8b922 fix: fix ci failed for tests 2026-02-20 23:18:29 +03:30
Meysam Hadeli
23d4babd52 fix: fix ci failed for tests 2026-02-20 20:57:26 +03:30
Meysam Hadeli
8d4819624e fix: fix ci failed for tests 2026-02-20 02:47:07 +03:30
Meysam Hadeli
043c20002c
Merge pull request #372 from meysamhadeli/fix/fix-ci-field-for-tests
fix: fix ci failed for tests
2026-02-20 02:11:41 +03:30
Meysam Hadeli
94a22dfc23 fix: fix ci failed for tests 2026-02-20 02:10:54 +03:30
Meysam Hadeli
3ce312891a Merge branch 'fix/fix-ci-failed' 2026-02-20 00:27:53 +03:30
Meysam Hadeli
a62177a6c4 fix: fix ci failed 2026-02-20 00:25:48 +03:30
Meysam Hadeli
b67d000580
Merge pull request #371 from meysamhadeli/fix/fix-ci-failed
fix: fix ci failed
2026-02-19 23:32:27 +03:30
Meysam Hadeli
2a5909bdbd fix: fix ci failed 2026-02-19 23:30:10 +03:30
Meysam Hadeli
786fbb121f
Merge pull request #370 from meysamhadeli/fix/fix-ci-failed
fix: fix ci failed
2026-02-19 23:19:09 +03:30
Meysam Hadeli
b9b3c26edc fix: fix ci failed 2026-02-19 23:17:14 +03:30
Meysam Hadeli
9dcd6625b2
Merge pull request #369 from meysamhadeli/fix/fix-ci-failed
Fix/fix ci failed
2026-02-19 22:03:04 +03:30
Meysam Hadeli
43666a7dd3 fix: fix ci failed 2026-02-19 22:01:04 +03:30
Meysam Hadeli
23b14eabe7 fix: fix ci failed 2026-02-19 21:59:25 +03:30
Meysam Hadeli
9164c770b5
Merge pull request #368 from meysamhadeli/fix/fix-ci-failed
Fix/fix ci failed
2026-02-19 21:08:53 +03:30
Meysam Hadeli
3bdcc6341f fix: fix ci failed 2026-02-19 21:06:59 +03:30
Meysam Hadeli
20e49770b2 fix: fix ci failed 2026-02-19 21:05:18 +03:30
Meysam Hadeli
e259b64476
Merge pull request #367 from meysamhadeli/chore-update-dockerfiles-to-dotnet-10
Chore update dockerfiles to dotnet 10
2026-02-16 21:13:10 +03:30
Meysam Hadeli
7476502e50 fix: fix formatting 2026-02-16 21:09:00 +03:30
Meysam Hadeli
64dfee4224 chore: update Dockerfiles to .net 10 2026-02-16 21:06:37 +03:30
Meysam Hadeli
bd94742d18
Merge pull request #366 from meysamhadeli/chore/update-config-file
chore: update .config file
2026-02-13 17:49:13 +03:30
Meysam Hadeli
d5e9f75dfc chore: update .config file 2026-02-13 17:29:58 +03:30
Meysam Hadeli
eef8aead7e
Merge pull request #365 from meysamhadeli/feat/update-packages-to-dotnet-10
Feat/update packages to dotnet 10
2026-02-13 14:52:12 +03:30
Meysam Hadeli
38c339c1aa chore: update ci build version 2026-02-13 00:49:49 +03:30
Meysam Hadeli
20bd2ac0bc docs: update documentation 2026-02-13 00:47:15 +03:30
Meysam Hadeli
3b86cf7917 feat: update packages to .net 10 2026-02-13 00:39:59 +03:30
Meysam Hadeli
d1dbe6209c feat: update packages to .net 10 2026-02-13 00:38:09 +03:30
Meysam Hadeli
475fa90e1c
Merge pull request #364 from meysamhadeli/chore/update-aspire-namespaces
chore: update aspire namespaces
2025-10-10 14:19:28 +03:30
Meysam Hadeli
0dd7941136 chore: update aspire namespaces 2025-10-10 14:07:55 +03:30
Meysam Hadeli
29a1e47a2d
Merge pull request #363 from meysamhadeli/chore/remove-additional-files
chore: remove additional files
2025-10-09 17:20:48 +03:30
Meysam Hadeli
68f768d687 chore: remove additional files 2025-10-09 17:18:05 +03:30
Meysam Hadeli
e2fbd27222
docs: update documentation 2025-10-09 16:15:00 +03:30
Meysam Hadeli
d6e313a560
Merge pull request #360 from meysamhadeli/chore/update-aspire-structure
chore/update aspire structure
2025-07-30 20:14:38 +03:30
Meysam Hadeli
57000c5802 chore: update aspire structure 2025-07-30 19:38:31 +03:30
Meysam Hadeli
b3ce2889b2 chore: update aspire structure 2025-07-30 19:37:07 +03:30
Meysam Hadeli
a3c6f670e1
Merge pull request #359 from meysamhadeli/feat/add-docker-compose-deployment-to-aspire-host
feat: add docker compose deployment to aspire host
2025-07-29 23:58:52 +03:30
Meysam Hadeli
3bd8cb1db3 feat: add docker compose deployment to aspire host 2025-07-29 23:13:26 +03:30
Meysam Hadeli
b9e1a1b949
Merge pull request #358 from meysamhadeli/docs/update-documentation
docs: update aspire documentation
2025-07-23 16:40:39 +03:30
Meysam Hadeli
e76353c2df docs: update aspire documentation 2025-07-23 16:37:40 +03:30
Meysam Hadeli
44e408258f
Merge pull request #357 from meysamhadeli/docs/update-aspir-docs
docs/update aspir docs
2025-07-23 16:28:40 +03:30
Meysam Hadeli
10627f8de6 fix: fix formatting 2025-07-23 16:18:05 +03:30
Meysam Hadeli
61d90da20e docs: update aspire documentation 2025-07-23 16:11:20 +03:30
Meysam Hadeli
be13a0ac27
Merge pull request #356 from meysamhadeli/docs/add-aspire-documentation
docs/add aspire documentation
2025-07-23 15:50:16 +03:30
Meysam Hadeli
aba06b9675 chore: update .editorconfig 2025-07-23 15:39:50 +03:30
Meysam Hadeli
a887b0406e chore: update .gitattributes 2025-07-23 15:37:24 +03:30
Meysam Hadeli
da1a3df324 docs: add aspire documentation 2025-07-23 15:28:05 +03:30
Meysam Hadeli
756f166711
Merge pull request #355 from meysamhadeli/feat/add-aspire-integrations
feat: add .net aspire integrations
2025-07-22 02:03:09 +03:30
Meysam Hadeli
0809701fe7 Merge branch 'main' into feat/add-aspire-integrations 2025-07-22 01:36:07 +03:30
Meysam Hadeli
ab512476d0 feat: add .net aspire integrations 2025-07-22 01:32:05 +03:30
Meysam Hadeli
b2e6d4c834
Update README.md 2025-07-14 20:27:44 +03:30
Meysam Hadeli
a67909d109
Update README.md 2025-07-14 20:26:56 +03:30
Meysam Hadeli
11e3bb3904
Merge pull request #354 from meysamhadeli/fix/fix-building-blocks-path-in-dockerfile
fix: fix building-blocks path in dockerfiles
2025-07-04 00:10:20 +03:30
Meysam Hadeli
e3154c23bc fix: fix building-blocks path in dockerfiles 2025-07-03 23:59:11 +03:30
Meysam Hadeli
89589c2c72
Merge pull request #353 from meysamhadeli/chore/cleanup-unused-files
chore: cleanup unused files
2025-07-03 23:43:47 +03:30
Meysam Hadeli
406d3e16e7 chore: cleanup unused files 2025-07-03 23:39:55 +03:30
Meysam Hadeli
aeb19e2f4b
Merge pull request #352 from meysamhadeli/refactor/refactor-structure
refactor: refactor structure of project
2025-07-03 23:36:49 +03:30
Meysam Hadeli
2e02f1b3bf refactor: refactor structure of project 2025-07-03 23:22:26 +03:30
Meysam Hadeli
c33eaf4d07
Merge pull request #351 from meysamhadeli/refactro/refactor-app-and-domain-exceptions
refactor: refactor app and domain exceptions
2025-06-12 21:22:39 +03:30
Meysam Hadeli
afbe8ffeff refactor: refactor app and domain exceptions 2025-06-12 20:37:29 +03:30
Meysam Hadeli
05fcc24bc8
Merge pull request #350 from meysamhadeli/fix/dotnet-format-issue
Fix/dotnet format issue
2025-05-17 20:13:05 +03:30
Meysam Hadeli
768178b153 fix: fix dotnet format issue 2025-05-17 19:57:23 +03:30
Meysam Hadeli
ca7ee3833b fix: fix dotnet format issue 2025-05-17 19:54:14 +03:30
Meysam Hadeli
b0da80bfff
Merge pull request #349 from AyobKafrashian/Complete-modular-monolith-tests
feat: compleate modular monolith tests
2025-05-16 22:30:44 +03:30
AyobKafrashian
93850aaf2f Merge remote-tracking branch 'origin/main' into Complete-modular-monolith-tests 2025-05-16 21:58:30 +03:30
Meysam Hadeli
d26115ccc5
chore: bypass dotnet format 2025-05-16 21:31:42 +03:30
unknown
1bf20a8334 feat:compleate modular monolith tests 2025-05-16 17:59:41 +03:30
Meysam Hadeli
157d9e24d0
Merge pull request #347 from meysamhadeli/chore/update-rest-client-in-monolith
chore: update rest client in monolith
2025-05-13 01:20:55 +03:30
Meysam Hadeli
a6b9d1c948 chore: update rest client in monolith 2025-05-13 01:20:13 +03:30
Meysam Hadeli
dedf6086fc
Merge pull request #346 from meysamhadeli/feat/add-support-role-base-policy
feat: add support role base authorization policy
2025-05-12 00:47:16 +03:30
Meysam Hadeli
eb5bf1da61 feat: add support role base authorization policy 2025-05-12 00:46:19 +03:30
Meysam Hadeli
879fde8d80
Merge pull request #345 from meysamhadeli/refactor/refactor-loading-invisible-asseblies
refactor: refactor loading invisible assemblies
2025-05-11 18:20:20 +03:30
Meysam Hadeli
5115e0daec refactor: refactor loading invisible assemblies 2025-05-11 18:19:22 +03:30
Meysam Hadeli
774866e9ad
Merge pull request #343 from AyobKafrashian/Add-tests-modular-monolith
Add tests modular monolith(flight module)
2025-05-11 13:42:22 +03:30
a.kafrashian
444b96bc73 fix(package-lock): update integrity hashes 2025-05-11 12:51:20 +03:30
unknown
ba0bcc120e refactor:add end to end testing to flight csproj 2025-05-11 01:08:50 +03:30
Meysam Hadeli
fadd128d1f
Update TestBase.cs 2025-05-10 20:43:42 +03:30
a.kafrashian
f3b96dab73 refactor:import end to end test to flight csproj 2025-05-05 15:52:51 +03:30
a.kafrashian
68d9db7849 feat:add end to end test for flight 2025-05-05 15:48:54 +03:30
unknown
1fb9558227 fix(TestBase):add postgres connection settings for Flight, Identity and Passenger 2025-05-05 00:39:27 +03:30
a.kafrashian
c91538493b fix:unify 'flight' namespace in Booking and Flight modules 2025-05-04 12:51:44 +03:30
unknown
660cac9ee5 feat(flight):add initial Unit.Test project 2025-05-04 07:12:26 +03:30
Meysam Hadeli
628257ba6c
docs: update documentation 2025-05-01 00:45:31 +03:30
Meysam Hadeli
a1f12f7129
Merge pull request #338 from meysamhadeli/docs/update-documentation
docs: update documentation
2025-04-30 17:00:25 +03:30
Meysam Hadeli
c7a92d7391 docs: update documentation 2025-04-30 16:59:26 +03:30
Meysam Hadeli
4b4eca5a8f
Merge pull request #337 from AyobKafrashian/Ad-docker-compose-deployment-for-modular-monolith
feat: add docker compose and docker compose infrastructure to modular…
2025-04-29 00:54:28 +03:30
unknown
d04169e6c2 feat: add docker compose and docker compose infrastructure to modular monolith deployment 2025-04-27 22:58:27 +03:30
Meysam Hadeli
92fac775ba
Merge pull request #336 from meysamhadeli/refactor/refactor-deployments
refactor: refactor deployments
2025-04-24 23:27:58 +03:30
Meysam Hadeli
5dde8aab42 refactor: refactor deployments 2025-04-24 23:26:57 +03:30
Meysam Hadeli
c9c2478bbf
Merge pull request #335 from AyobKafrashian/Complete-docker-compose-services-for-monolith
feat: complete docker compose services for monolith
2025-04-24 21:47:40 +03:30
unknown
566f9bd8b7 feat: complete docker compose services for monolith 2025-04-24 21:27:04 +03:30
Meysam Hadeli
56f3a1cc94
Merge pull request #334 from AyobKafrashian/Add-docker-compose-deployment-for-monolith
feat: Add docker compose configuration to Monolith deployment
2025-04-24 17:50:30 +03:30
unknown
24b1f08901 feat: Add docker compose configuration to Monolith deployment 2025-04-22 15:35:50 +03:30
1018 changed files with 3918 additions and 24322 deletions

3
.aspire/settings.json Normal file
View File

@ -0,0 +1,3 @@
{
"appHostPath": "../src/Aspire/src/AppHost/AppHost.csproj"
}

View File

@ -3,18 +3,28 @@
"isRoot": true,
"tools": {
"dotnet-outdated-tool": {
"version": "4.6.4",
"version": "4.6.9",
"commands": [
"dotnet-outdated"
],
"rollForward": false
]
},
"dotnet-ef": {
"version": "9.0.0",
"version": "10.0.3",
"commands": [
"dotnet-ef"
],
"rollForward": false
]
},
"aspire.cli": {
"version": "13.1.1",
"commands": [
"aspire"
]
},
"csharpier": {
"version": "0.30.6",
"commands": [
"dotnet-csharpier"
]
}
}
}

View File

@ -9,127 +9,167 @@
## https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/
## https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/
## Microsoft Rules
##
root = true
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
# Global settings
# All files
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_style = space
# Xml files
[*.xml]
indent_size = 2
# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_style = space
indent_size = 2
[*.{md,json}]
indent_style = space
indent_size = 4
# C# files
[*.cs]
indent_style = space
indent_size = 4
max_line_length = 100
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
tab_width = 4
max_line_length = 120
# New line preferences
insert_final_newline = false
#### .NET Coding Conventions ####
[*.{cs,vb}]
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true
file_header_template = unset
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?#enable-on-build
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules#option-format
# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
# Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
# Field preferences
dotnet_style_readonly_field = true:warning
# Parameter preferences
dotnet_code_quality_unused_parameters = all:suggestion
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
#### C# Coding Conventions ####
[*.cs]
# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_switch_expression = true:suggestion
# Null-checking preferences
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_prefer_static_anonymous_function = true:suggestion
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,file,const,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_top_level_statements = true:silent
# Expression-level preferences
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#indentation-options
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
# only use var when it's obvious what the variable type is
# csharp_style_var_for_built_in_types = false:none
# csharp_style_var_when_type_is_apparent = false:none
# csharp_style_var_elsewhere = false:suggestion
# use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_style.static_prefix_style.required_prefix = s_
dotnet_naming_style.static_prefix_style.capitalization = camel_case
# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
# Code style defaults
dotnet_sort_system_directives_first = true
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false
# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
# Expression-bodied members
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
@ -139,6 +179,7 @@ csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
@ -154,6 +195,200 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
[*.{cs,vb}]
# Naming rules
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = suggestion
dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces
dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase
dotnet_naming_rule.type_parameters_should_be_tpascalcase.severity = suggestion
dotnet_naming_rule.type_parameters_should_be_tpascalcase.symbols = type_parameters
dotnet_naming_rule.type_parameters_should_be_tpascalcase.style = tpascalcase
dotnet_naming_rule.methods_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.methods_should_be_pascalcase.symbols = methods
dotnet_naming_rule.methods_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.properties_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.properties_should_be_pascalcase.symbols = properties
dotnet_naming_rule.properties_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.events_should_be_pascalcase.symbols = events
dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables
dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase
dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants
dotnet_naming_rule.local_constants_should_be_camelcase.style = camelcase
dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion
dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters
dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase
dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields
dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields
dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields
dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields
dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums
dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase
dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase
# Symbol specifications
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interfaces.required_modifiers =
dotnet_naming_symbols.enums.applicable_kinds = enum
dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enums.required_modifiers =
dotnet_naming_symbols.events.applicable_kinds = event
dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.events.required_modifiers =
dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.methods.required_modifiers =
dotnet_naming_symbols.properties.applicable_kinds = property
dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.properties.required_modifiers =
dotnet_naming_symbols.public_fields.applicable_kinds = field
dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_fields.required_modifiers =
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_fields.required_modifiers =
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_fields.required_modifiers = static
dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum
dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types_and_namespaces.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.type_parameters.applicable_kinds = namespace
dotnet_naming_symbols.type_parameters.applicable_accessibilities = *
dotnet_naming_symbols.type_parameters.required_modifiers =
dotnet_naming_symbols.private_constant_fields.applicable_kinds = field
dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_constant_fields.required_modifiers = const
dotnet_naming_symbols.local_variables.applicable_kinds = local
dotnet_naming_symbols.local_variables.applicable_accessibilities = local
dotnet_naming_symbols.local_variables.required_modifiers =
dotnet_naming_symbols.local_constants.applicable_kinds = local
dotnet_naming_symbols.local_constants.applicable_accessibilities = local
dotnet_naming_symbols.local_constants.required_modifiers = const
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *
dotnet_naming_symbols.parameters.required_modifiers =
dotnet_naming_symbols.public_constant_fields.applicable_kinds = field
dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_constant_fields.required_modifiers = const
dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal
dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascalcase.required_prefix =
dotnet_naming_style.pascalcase.required_suffix =
dotnet_naming_style.pascalcase.word_separator =
dotnet_naming_style.pascalcase.capitalization = pascal_case
dotnet_naming_style.ipascalcase.required_prefix = I
dotnet_naming_style.ipascalcase.required_suffix =
dotnet_naming_style.ipascalcase.word_separator =
dotnet_naming_style.ipascalcase.capitalization = pascal_case
dotnet_naming_style.tpascalcase.required_prefix = T
dotnet_naming_style.tpascalcase.required_suffix =
dotnet_naming_style.tpascalcase.word_separator =
dotnet_naming_style.tpascalcase.capitalization = pascal_case
dotnet_naming_style._camelcase.required_prefix = _
dotnet_naming_style._camelcase.required_suffix =
dotnet_naming_style._camelcase.word_separator =
dotnet_naming_style._camelcase.capitalization = camel_case
dotnet_naming_style.camelcase.required_prefix =
dotnet_naming_style.camelcase.required_suffix =
dotnet_naming_style.camelcase.word_separator =
dotnet_naming_style.camelcase.capitalization = camel_case
dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case
##################################################################################
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/
@ -175,7 +410,7 @@ dotnet_diagnostic.CA1304.severity = error
# CA1307: Specify StringComparison for clarity
dotnet_diagnostic.CA1307.severity = error
# CA1308: Normalize strings to uppercase
dotnet_diagnostic.CA1308.severity = error
dotnet_diagnostic.CA1308.severity = none
# CA1309: Use ordinal StringComparison
dotnet_diagnostic.CA1309.severity = error
# CA1724: Type names should not match namespaces
@ -210,7 +445,18 @@ dotnet_diagnostic.ca1848.severity = Suggestion
dotnet_diagnostic.ca1810.severity = Suggestion
# CA1725: Parameter names should match base declaration
dotnet_diagnostic.ca1725.severity = Suggestion
# https://csharpier.com/docs/IntegratingWithLinters#code-analysis-rules
# CA1515: Consider making public types internal
dotnet_diagnostic.CA1515.severity = None
# CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = Suggestion
# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = None
# CA1716: Identifiers should not match keywords
dotnet_diagnostic.CA1716.severity = Suggestion
# CA1032: Implement standard exception constructors
dotnet_diagnostic.CA1032.severity = Suggestion
# AV1500: A method should not exceed a predefined number (60-100 lines) of lines
dotnet_diagnostic.AV1500.severity = none
##################################################################################
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/
@ -220,7 +466,7 @@ dotnet_diagnostic.ca1725.severity = Suggestion
dotnet_diagnostic.IDE0048.severity = Suggestion
dotnet_diagnostic.IDE0028.severity = Suggestion
dotnet_diagnostic.IDE0029.severity = Suggestion
dotnet_diagnostic.IDE0030.severity = Suggestion
dotnet_diagnostic.IDE0030 .severity = Suggestion
dotnet_diagnostic.IDE0004.severity = error
# IDE0005: Remove unnecessary usings/imports
@ -230,21 +476,21 @@ dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0051.severity = Suggestion
# IDE0052: Remove unread private members (writes but no reads)
dotnet_diagnostic.IDE0052.severity = error
dotnet_diagnostic.IDE0052.severity = warning
# Remove unnecessary using directives (IDE0005)
dotnet_diagnostic.IDE0005.severity = none
# CS1574: XML comment on 'construct' has syntactically incorrect cref attribute 'name'
dotnet_diagnostic.CS1574.severity = error
# IDE0055: Fix formatting
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/dotnet-formatting-options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055
dotnet_diagnostic.IDE0055.severity = suggestion
# CS1574: XML comment on 'construct' has syntactically incorrect cref attribute 'name'
dotnet_diagnostic.CS1574.severity = error
# IDE0160, IDE0161: Report violations when block-scoped namespaces are used
dotnet_diagnostic.IDE0160.severity = none
dotnet_diagnostic.IDE0161.severity = none
# https://csharpier.com/docs/IntegratingWithLinters#code-analysis-rules
dotnet_diagnostic.IDE0055.severity = none
##################################################################################
# https://jetbrains.com.xy2401.com/help/resharper/EditorConfig_Index.html
@ -378,59 +624,6 @@ resharper_blank_lines_before_multiline_statements = 1
resharper_parentheses_non_obvious_operations = arithmetic, multiplicative, equality, relational, additive
resharper_parentheses_redundancy_style = remove_if_not_clarifies_precedence
##################################################################################
## https://github.com/bkoelman/CSharpGuidelinesAnalyzer
## CSharpGuidelines
##################################################################################
dotnet_diagnostic.AV1561.max_parameter_count = 5
# AV1008: Class should be non-static or its name should be suffixed with Extensions
dotnet_diagnostic.AV1008.severity = none
# AV1010: Type hides inherited member
dotnet_diagnostic.AV1010.severity = none
# AV1115: Member or local function contains the word 'and', which suggests doing multiple things
dotnet_diagnostic.AV1115.severity = suggestion
# AV1130: Return type in signature for Type should be a collection interface instead of a concrete type
dotnet_diagnostic.AV1130.severity = none
# AV1135: null is returned from method which has return type of string, collection or task
dotnet_diagnostic.AV1135.severity = none # re-enable if we can distinguish between string, collection and task
# AV1210: Catch a specific exception instead of Exception, SystemException or ApplicationException
dotnet_diagnostic.AV1210.severity = none
# AV1250: Evaluate LINQ query before returning it
dotnet_diagnostic.AV1250.severity = suggestion
# AV1500: Method 'CallerIdentifier.DetermineCallerIdentity()' contains 10 statements, which exceeds the maximum of 7 statements
dotnet_diagnostic.AV1500.severity = none
# AV1532: Loop statement contains nested loop
dotnet_diagnostic.AV1532.severity = suggestion
# AV1535: Missing block in case or default clause of switch statement
dotnet_diagnostic.AV1535.severity = none # re-enable if we can adjust the formatting to not indent the scope braces
# AV1537: If-else-if construct should end with an unconditional else clause
dotnet_diagnostic.AV1537.severity = suggestion
# AV1551: Method overload with the most parameters should be virtual
dotnet_diagnostic.AV1551.severity = none
# AV1555: Avoid using non-(nullable-)boolean named arguments
dotnet_diagnostic.AV1555.severity = suggestion
# AV1561: Method contains 5 parameters, which exceeds the maximum of 3 parameters
dotnet_diagnostic.AV1561.severity = suggestion
# AV1564: Parameter in public or internal member is of type bool or bool?
dotnet_diagnostic.AV1564.severity = suggestion
# AV1554: Do not use optional parameters in interface methods or their concrete implementations
dotnet_diagnostic.AV1554.severity = none
# AV1580: Argument for parameter calls nested method
dotnet_diagnostic.AV1580.severity = none
# AV1706: Parameter 'p' should have a more descriptive name
dotnet_diagnostic.AV1706.severity = warning
# AV1708: Type name contains term that should be avoided
dotnet_diagnostic.AV1708.severity = suggestion
# AV1710: Field contains the name of its containing type
dotnet_diagnostic.AV1710.severity = none
# AV2202: Replace call to Nullable<T>.HasValue with null check
dotnet_diagnostic.AV2202.severity = none
# AV2305: Missing XML comment for internally visible type or member
dotnet_diagnostic.AV2305.severity = none
# AV2407: Region should be removed
dotnet_diagnostic.AV2407.severity = none
##################################################################################
## https://github.com/DotNetAnalyzers/StyleCopAnalyzers/tree/master/documentation
## https://documentation.help/StyleCop/StyleCop.html
@ -553,16 +746,85 @@ dotnet_diagnostic.sa1101.severity = None
# The keywords within the declaration of an element do not follow a standard ordering scheme.
dotnet_diagnostic.SA1206.severity = None
# A single-line comment within C# code is not preceded by a blank line.
dotnet_diagnostic.SA1515.severity = Suggestion
dotnet_diagnostic.SA1106.severity = None
# https://csharpier.com/docs/IntegratingWithLinters#stylecopanalyzers
# IDE0055: Fix formatting
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/dotnet-formatting-options
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055
# StyleCopAnalyzers
dotnet_diagnostic.SA1000.severity = none
dotnet_diagnostic.SA1009.severity = none
dotnet_diagnostic.SA1111.severity = none
dotnet_diagnostic.SA1118.severity = none
dotnet_diagnostic.SA1137.severity = none
dotnet_diagnostic.SA1413.severity = none
dotnet_diagnostic.SA1500.severity = none
dotnet_diagnostic.SA1501.severity = none
dotnet_diagnostic.SA1502.severity = none
dotnet_diagnostic.SA1504.severity = none
dotnet_diagnostic.SA1515.severity = none
dotnet_diagnostic.SA1516.severity = none
# for csharpier <= 0.21.0
dotnet_diagnostic.SA1127.severity = none
dotnet_diagnostic.SA1128.severity = none
dotnet_diagnostic.SA1001.severity = none
dotnet_diagnostic.SA1002.severity = none
dotnet_diagnostic.SA1003.severity = none
dotnet_diagnostic.SA1007.severity = none
dotnet_diagnostic.SA1008.severity = none
dotnet_diagnostic.SA1010.severity = none
dotnet_diagnostic.SA1011.severity = none
dotnet_diagnostic.SA1012.severity = none
dotnet_diagnostic.SA1013.severity = none
dotnet_diagnostic.SA1014.severity = none
dotnet_diagnostic.SA1015.severity = none
dotnet_diagnostic.SA1016.severity = none
dotnet_diagnostic.SA1017.severity = none
dotnet_diagnostic.SA1018.severity = none
dotnet_diagnostic.SA1019.severity = none
dotnet_diagnostic.SA1020.severity = none
dotnet_diagnostic.SA1021.severity = none
dotnet_diagnostic.SA1022.severity = none
dotnet_diagnostic.SA1023.severity = none
dotnet_diagnostic.SA1024.severity = none
dotnet_diagnostic.SA1025.severity = none
dotnet_diagnostic.SA1026.severity = none
dotnet_diagnostic.SA1027.severity = none
dotnet_diagnostic.SA1028.severity = none
dotnet_diagnostic.SA1102.severity = none
dotnet_diagnostic.SA1103.severity = none
dotnet_diagnostic.SA1104.severity = none
dotnet_diagnostic.SA1105.severity = none
dotnet_diagnostic.SA1107.severity = none
dotnet_diagnostic.SA1110.severity = none
dotnet_diagnostic.SA1112.severity = none
dotnet_diagnostic.SA1113.severity = none
dotnet_diagnostic.SA1114.severity = none
dotnet_diagnostic.SA1115.severity = none
dotnet_diagnostic.SA1116.severity = none
dotnet_diagnostic.SA1117.severity = none
dotnet_diagnostic.SA1127.severity = none
dotnet_diagnostic.SA1128.severity = none
dotnet_diagnostic.SA1136.severity = none
dotnet_diagnostic.SA1505.severity = none
dotnet_diagnostic.SA1506.severity = none
dotnet_diagnostic.SA1507.severity = none
dotnet_diagnostic.SA1508.severity = none
dotnet_diagnostic.SA1509.severity = none
dotnet_diagnostic.SA1510.severity = none
dotnet_diagnostic.SA1511.severity = none
dotnet_diagnostic.SA1517.severity = none
dotnet_diagnostic.SA1518.severity = none
##################################################################################
## https://github.com/meziantou/Meziantou.Analyzer/tree/main/docs
## Meziantou.Analyzer
# MA0049: Type name should not match containing namespace
dotnet_diagnostic.ma0049.severity = Suggestion
# MA0048: File name must match type name
dotnet_diagnostic.ma0048.severity = Suggestion
@ -616,11 +878,14 @@ dotnet_diagnostic.MA0047.severity = none
# Use an overload of 'GetHashCode' that has a StringComparison parameter
dotnet_diagnostic.MA0074.severity = none
# MA0049: Type name should not match containing namespace
dotnet_diagnostic.MA0049.severity = none
##################################################################################
## http://pihrt.net/Roslynator/Analyzers
## http://pihrt.net/Roslynator/Refactorings
## https://github.com/JosefPihrt/Roslynator/blob/main/docs/Configuration.md
## https://josefpihrt.github.io/docs/
## Roslynator
##################################################################################
# RCS1036 - Remove redundant empty line.
dotnet_diagnostic.rcs1036.severity = None
@ -655,7 +920,6 @@ dotnet_diagnostic.rcs1047.severity = error
# RCS1174: Remove redundant async/await
dotnet_diagnostic.rcs1174.severity = Suggestion
# Combine 'Enumerable.Where' method chain. It doesn't make it more readable in all cases.
dotnet_diagnostic.RCS1112.severity = suggestion
@ -693,6 +957,30 @@ dotnet_diagnostic.RCS1237.severity = none
# RCS1228: Unused element in documentation comment. (Equivalent to SA1614)
dotnet_diagnostic.RCS1228.severity = suggestion
# RCS1047: Non-asynchronous method name should not end with 'Async'
#dotnet_diagnostic.RCS1047.severity = suggestion
##################################################################################
## https://github.com/semihokur/asyncfixer
## AsyncFixer01
##################################################################################
# https://cezarypiatek.github.io/post/async-analyzers-p1/#1-redundant-asyncawait
# AsyncFixer01: Unnecessary async/await usage
dotnet_diagnostic.asyncfixer01.severity = Suggestion
# https://cezarypiatek.github.io/post/async-analyzers-p1/#2-calling-synchronous-method-inside-the-async-method
# AsyncFixer02: Long-running or blocking operations inside an async method
dotnet_diagnostic.asyncfixer02.severity = error
# https://cezarypiatek.github.io/post/async-analyzers-p1/#3-async-void-method
# AsyncFixer03: Fire & forget async void methods
dotnet_diagnostic.asyncfixer03.severity = error
# https://cezarypiatek.github.io/post/async-analyzers-p1/#6-not-awaited-task-inside-the-using-block
# AsyncFixer04: Fire & forget async call inside a using block
dotnet_diagnostic.asyncfixer04.severity = error
##################################################################################
## https://github.com/microsoft/vs-threading
## Microsoft.VisualStudio.Threading.Analyzers
@ -702,7 +990,6 @@ dotnet_diagnostic.RCS1228.severity = suggestion
# VSTHRD103: Call async methods when in an async method
dotnet_diagnostic.vsthrd103.severity = Suggestion
# https://cezarypiatek.github.io/post/async-analyzers-p1/#3-async-void-method
# VSTHRD100: Avoid async void methods
dotnet_diagnostic.vsthrd100.severity = error
@ -738,3 +1025,20 @@ dotnet_diagnostic.vsthrd200.severity = Suggestion
# https://cezarypiatek.github.io/post/async-analyzers-p2/#12-non-asynchronous-method-names-shouldnt-end-with-async
# VSTHRD200: Use "Async" suffix for async methods
dotnet_diagnostic.vsthrd200.severity = Suggestion
# VSTHRD003 Avoid awaiting foreign Tasks
dotnet_diagnostic.VSTHRD003.severity = Suggestion
##################################################################################
## https://github.com/hvanbakel/Asyncify-CSharp
## Asyncify
##################################################################################
# https://cezarypiatek.github.io/post/async-analyzers-p2/#8-synchronous-waits
# AsyncifyInvocation: Use Task Async
dotnet_diagnostic.asyncifyinvocation.severity = error
# https://cezarypiatek.github.io/post/async-analyzers-p2/#8-synchronous-waits
# AsyncifyVariable: Use Task Async
dotnet_diagnostic.asyncifyvariable.severity = error

8
.gitattributes vendored
View File

@ -18,7 +18,7 @@
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
@ -47,9 +47,9 @@
###############################################################################
# diff behavior for common document formats
#
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
@ -61,4 +61,4 @@
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
#*.RTF diff=astextplain

View File

@ -34,7 +34,7 @@ runs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x.x'
dotnet-version: '10.x.x'
# https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools
- name: Restore .NET Tools

View File

@ -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
.gitpod.Dockerfile vendored
View File

@ -1 +0,0 @@
FROM gitpod/workspace-dotnet:latest

View File

@ -1,37 +0,0 @@
# https://github.com/gitpod-samples/template-dotnet-core-cli-csharp
# https://www.gitpod.io/docs/introduction/languages/dotnet
# https://github.com/gitpod-samples/template-docker-compose
# https://www.gitpod.io/docs/references/gitpod-yml
# https://www.gitpod.io/docs/configure
# https://www.gitpod.io/docs/configure/workspaces/ports
image:
file: .gitpod.Dockerfile
vscode:
extensions:
- muhammad-sammy.csharp
- editorconfig.editorconfig
- vivaxy.vscode-conventional-commits
- humao.rest-client
- ms-azuretools.vscode-docker
- donjayamanne.githistory
- pkief.material-icon-theme
- emmanuelbeziat.vscode-great-icons
# https://www.gitpod.io/docs/configure/workspaces/tasks#execution-order
# https://www.gitpod.io/docs/configure/projects/prebuilds
tasks:
- name: Init Docker-Compose
# https://www.gitpod.io/docs/configure/projects/prebuilds
# We load docker on pre-build for increasing speed
init: |
docker-compose pull
docker-compose -f ./deployments/docker-compose/infrastracture.yaml up -d
- name: Setup kubectl
command: bash $GITPOD_REPO_ROOT/scripts/setup_kubectl_gitpod.sh
- name: Restore & Build
init: |
dotnet dev-certs https
dotnet restore
dotnet build

View File

@ -1 +1,2 @@
npm run format
npm run format
npm run ci-format

View File

@ -1,101 +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)
- [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
![](./assets/booking-monolith.png)
## 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
> ### 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

View File

@ -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
###
###
# @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"
}
###

View File

@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<RootNamespace>Api</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\BookingMonolith\src\BookingMonolith.csproj" />
</ItemGroup>
</Project>

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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"
}
}
}
}

View File

@ -1,59 +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",
"RequireHttpsMetadata": false
},
"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": "*"
}

View File

@ -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}

View File

@ -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}

View File

@ -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
};
}
}

View File

@ -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);
}
}
}

View File

@ -1,6 +0,0 @@
namespace BookingMonolith.Booking;
public class BookingRoot
{
}

View File

@ -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);

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class BookingAlreadyExistException : ConflictException
{
public BookingAlreadyExistException(int? code = default) : base("Booking already exist!", code)
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class FlightNotFoundException : NotFoundException
{
public FlightNotFoundException() : base("Flight doesn't exist!")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidAircraftIdException : BadRequestException
{
public InvalidAircraftIdException(Guid aircraftId)
: base($"aircraftId: '{aircraftId}' is invalid.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidArriveAirportIdException : BadRequestException
{
public InvalidArriveAirportIdException(Guid arriveAirportId)
: base($"arriveAirportId: '{arriveAirportId}' is invalid.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidDepartureAirportIdException : BadRequestException
{
public InvalidDepartureAirportIdException(Guid departureAirportId)
: base($"departureAirportId: '{departureAirportId}' is invalid.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidFlightDateException : BadRequestException
{
public InvalidFlightDateException(DateTime flightDate)
: base($"Flight Date: '{flightDate}' is invalid.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidFlightNumberException : BadRequestException
{
public InvalidFlightNumberException(string flightNumber)
: base($"Flight Number: '{flightNumber}' is invalid.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidPassengerNameException : BadRequestException
{
public InvalidPassengerNameException(string passengerName)
: base($"Passenger Name: '{passengerName}' is invalid.")
{
}
}

View File

@ -1,12 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class InvalidPriceException : BadRequestException
{
public InvalidPriceException(decimal price)
: base($"Price: '{price}' must be grater than or equal 0.")
{
}
}

View File

@ -1,12 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Booking.Bookings.Exceptions;
public class SeatNumberException : BadRequestException
{
public SeatNumberException(string seatNumber)
: base($"Seat Number: '{seatNumber}' is invalid.")
{
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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++;
}
}

View File

@ -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; }
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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; }
}

View File

@ -1,28 +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>
<ItemGroup>
<Folder Include="Booking\Bookings\" />
<Folder Include="Booking\Data\" />
<Folder Include="Flight\Data\Migrations\" />
<Folder Include="Identity\Identities\" />
<Folder Include="Passenger\Passengers\" />
</ItemGroup>
</Project>

View File

@ -1,6 +0,0 @@
namespace BookingMonolith;
public class BookingMonolithRoot
{
}

View File

@ -1,3 +0,0 @@
namespace BookingMonolith.Flight.Aircrafts.Dtos;
public record AircraftDto(long Id, string Name, string Model, int ManufacturingYear);

View File

@ -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)
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
public class InvalidAircraftIdException : BadRequestException
{
public InvalidAircraftIdException(Guid aircraftId)
: base($"AircraftId: '{aircraftId}' is invalid.")
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
public class InvalidManufacturingYearException : BadRequestException
{
public InvalidManufacturingYearException() : base("ManufacturingYear must be greater than 1900")
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
public class InvalidModelException : BadRequestException
{
public InvalidModelException() : base("Model cannot be empty or whitespace.")
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Aircrafts.Exceptions;
public class InvalidNameException : BadRequestException
{
public InvalidNameException() : base("Name cannot be empty or whitespace.")
{
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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; }
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,3 +0,0 @@
namespace BookingMonolith.Flight.Airports.Dtos;
public record AirportDto(long Id, string Name, string Address, string Code);

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Airports.Exceptions;
public class AirportAlreadyExistException : ConflictException
{
public AirportAlreadyExistException(int? code = default) : base("Airport already exist!", code)
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Airports.Exceptions;
public class InvalidAddressException : BadRequestException
{
public InvalidAddressException() : base("Address cannot be empty or whitespace.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Airports.Exceptions;
public class InvalidAirportIdException : BadRequestException
{
public InvalidAirportIdException(Guid airportId)
: base($"airportId: '{airportId}' is invalid.")
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Airports.Exceptions;
public class InvalidCodeException : BadRequestException
{
public InvalidCodeException() : base("Code cannot be empty or whitespace.")
{
}
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Airports.Exceptions;
public class InvalidNameException : BadRequestException
{
public InvalidNameException() : base("Name cannot be empty or whitespace.")
{
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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; }
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
);
}
}

View File

@ -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();
}
);
}
}

View File

@ -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();
}
);
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}

View File

@ -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; }
}

View File

@ -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
}
}
}

View File

@ -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");
}
}
}

View File

@ -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
}
}
}

View File

@ -1,4 +0,0 @@
namespace BookingMonolith.Flight.Data;
[AttributeUsage(AttributeTargets.Class)]
public class RegisterFlightConfigurationAttribute : Attribute { }

View File

@ -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));
}
}
}
}

View File

@ -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))
};
}
}

View File

@ -1,2 +0,0 @@
dotnet ef migrations add initial --context FlightDbContext -o "Flight\Data\Migrations"
dotnet ef database update --context FlightDbContext

View File

@ -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
};
}
}

View File

@ -1,6 +0,0 @@
namespace BookingMonolith.Flight;
public class FlightRoot
{
}

View File

@ -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);

View File

@ -1,10 +0,0 @@
namespace BookingMonolith.Flight.Flights.Enums;
public enum FlightStatus
{
Unknown = 0,
Flying = 1,
Delay = 2,
Canceled = 3,
Completed = 4
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Flights.Exceptions;
public class FlightAlreadyExistException : ConflictException
{
public FlightAlreadyExistException(int? code = default) : base("Flight already exist!", code)
{
}
}

View File

@ -1,14 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Flights.Exceptions;
public class FlightExceptions : BadRequestException
{
public FlightExceptions(DateTime departureDate, DateTime arriveDate) :
base($"Departure date: '{departureDate}' must be before arrive date: '{arriveDate}'.")
{ }
public FlightExceptions(DateTime flightDate) :
base($"Flight date: '{flightDate}' must be between departure and arrive dates.")
{ }
}

View File

@ -1,10 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Flights.Exceptions;
public class FlightNotFountException : NotFoundException
{
public FlightNotFountException() : base("Flight not found!")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Flights.Exceptions;
public class InvalidArriveDateException : BadRequestException
{
public InvalidArriveDateException(DateTime arriveDate)
: base($"Arrive Date: '{arriveDate}' is invalid.")
{
}
}

View File

@ -1,11 +0,0 @@
using BuildingBlocks.Exception;
namespace BookingMonolith.Flight.Flights.Exceptions;
public class InvalidDepartureDateException : BadRequestException
{
public InvalidDepartureDateException(DateTime departureDate)
: base($"Departure Date: '{departureDate}' is invalid.")
{
}
}

Some files were not shown because too many files have changed in this diff Show More