From c064752c6b897b3c1160e2dac9bfdd34c45e5da7 Mon Sep 17 00:00:00 2001 From: msm1984 Date: Sun, 18 Aug 2024 21:37:26 +0330 Subject: [PATCH] test docker compose --- .github/workflows/CD_Backend.yml | 102 +- .github/workflows/CI_Backend.yml | 56 +- .github/workflows/test.yml | 32 + .gitignore | 1614 ++++++++--------- Dockerfile | 56 +- Summer1403-Project-Group01-Backend.sln | 80 +- backend.Dockerfile | 28 + docker-compose.yml | 80 +- migrate.Dockerfile | 19 + src/Application/Application.csproj | 34 +- .../DTOs/AccountCsv/AccountCsvModel.cs | 28 +- .../Identity/ChangeRole/ChangeRoleRequest.cs | 12 +- .../Identity/CreateUser/CreateUserRequest.cs | 24 +- .../Identity/CreateUser/CreateUserResponse.cs | 18 +- .../Identity/LoginUser/LoginUserRequest.cs | 18 +- .../Identity/LoginUser/LoginUserResponse.cs | 20 +- .../ChangePassword/ChangePasswordRequest.cs | 14 +- .../EditProfile/EditProfileInfoRequest.cs | 16 +- .../EditProfile/EditProfileInfoResponse.cs | 16 +- .../GetProfileInfo/GetProfileInfoRequest.cs | 10 +- .../GetProfileInfo/GetProfileInfoResponse.cs | 18 +- src/Application/DTOs/Result.cs | 92 +- .../GetAllTransactionsResponse.cs | 32 +- .../TransactionCsv/TransactionCsvModel.cs | 28 +- .../ExtensionMethods/ExtensionMethods.cs | 20 +- .../Interfaces/IAccountRepository.cs | 18 +- src/Application/Interfaces/IJwtGenerator.cs | 14 +- src/Application/Interfaces/IRoleManager.cs | 10 +- .../Interfaces/ITransactionRepository.cs | 16 +- src/Application/Interfaces/IUserManager.cs | 36 +- .../Interfaces/Services/IAccountService.cs | 20 +- .../Interfaces/Services/IIdentityService.cs | 22 +- .../Interfaces/Services/IProfileService.cs | 22 +- .../Services/ITransactionService.cs | 18 +- .../Interfaces/SharedService/ICsvService.cs | 10 +- src/Application/Mappers/IdentityMapper.cs | 84 +- src/Application/Mappers/ProfileMapper.cs | 56 +- src/Application/Mappers/TransactionMapper.cs | 46 +- src/Application/Services/AccountService.cs | 112 +- src/Application/Services/IdentityService.cs | 186 +- src/Application/Services/ProfileService.cs | 146 +- .../SharedService/CsvReaderService.cs | 42 +- .../SharedService/PersianDateConverter.cs | 66 +- .../Services/TransactionService.cs | 110 +- src/Domain/Constants/AppRoles.cs | 14 +- src/Domain/Domain.csproj | 26 +- src/Domain/Entities/Account.cs | 38 +- src/Domain/Entities/AppUser.cs | 20 +- src/Domain/Entities/Transaction.cs | 28 +- .../Data/ApplicationDbContext.cs | 74 +- src/Infrastructure/Infrastructure.csproj | 60 +- .../20240814092051_CompleteUser.Designer.cs | 614 +++---- .../Migrations/20240814092051_CompleteUser.cs | 474 ++--- ...17193825_Accounts-Transactions.Designer.cs | 828 ++++----- .../20240817193825_Accounts-Transactions.cs | 276 +-- .../20240818091853_CastIdsToLong.Designer.cs | 828 ++++----- .../20240818091853_CastIdsToLong.cs | 318 ++-- .../ApplicationDbContextModelSnapshot.cs | 822 ++++----- .../Services/AccountRepository.cs | 80 +- .../Services/RoleManagerService.cs | 34 +- .../Services/TransactionRepository.cs | 50 +- .../Services/UserManagerService.cs | 160 +- src/Web/Controllers/AccountController.cs | 120 +- src/Web/Controllers/IdentityController.cs | 134 +- src/Web/Controllers/ProfileController.cs | 146 +- src/Web/Controllers/TransactionController.cs | 100 +- src/Web/DTOs/Account/AccountDto.cs | 28 +- src/Web/DTOs/Identity/ChangeRoleDto.cs | 12 +- src/Web/DTOs/Identity/Login/LoginDto.cs | 22 +- .../DTOs/Identity/Login/UserLoggedInDto.cs | 20 +- src/Web/DTOs/Identity/Signup/SignupDto.cs | 52 +- .../DTOs/Identity/Signup/UserSignedUpDto.cs | 18 +- src/Web/DTOs/Profile/ChangePasswordDto.cs | 20 +- src/Web/DTOs/Profile/ChangeProfileDto.cs | 24 +- src/Web/DTOs/Profile/ProfileInfoDto.cs | 18 +- .../DTOs/Transaction/GotAllTransactionsDto.cs | 24 +- src/Web/DTOs/Transaction/TransactionDto.cs | 20 +- src/Web/Helper/Errors.cs | 28 +- src/Web/Identity/Claims.cs | 12 +- src/Web/Identity/RequiresClaimAttribute.cs | 46 +- src/Web/Mappers/AccountMapper.cs | 46 +- src/Web/Mappers/IdentityMapper.cs | 128 +- src/Web/Mappers/ProfileMapper.cs | 82 +- src/Web/Mappers/TransactionMapper.cs | 64 +- src/Web/Program.cs | 262 +-- src/Web/Properties/launchSettings.json | 82 +- src/Web/Services/JwtGeneratorService.cs | 88 +- src/Web/Startup/SeedData.cs | 90 +- src/Web/Web.csproj | 54 +- src/Web/appsettings.Development.json | 16 +- src/Web/appsettings.json | 46 +- 91 files changed, 5063 insertions(+), 4984 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 backend.Dockerfile create mode 100644 migrate.Dockerfile diff --git a/.github/workflows/CD_Backend.yml b/.github/workflows/CD_Backend.yml index 0025cf0..f37f29e 100644 --- a/.github/workflows/CD_Backend.yml +++ b/.github/workflows/CD_Backend.yml @@ -1,51 +1,51 @@ -name: CD_Backend - -permissions: - contents: write - -on: - push: - branches: - - dev - -jobs: - version-and-release: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Bump version and push tag - id: tag_version - uses: mathieudutour/github-tag-action@v6.2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - - name: login to docker registry - uses: docker/login-action@v3 - with: - username: ${{secrets.DOCKERHUB_USERNAME}} - password: ${{secrets.DOCKERHUB_TOKEN}} - - - name: build and push docker image to registry - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: mohammadsadeghmontazeri/starback:latest - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.tag_version.outputs.new_tag }} - release_name: Release ${{ steps.tag_version.outputs.new_tag }} - body: | - steps.tag_version.outputs.changelog - draft: false - prerelease: false +name: CD_Backend + +permissions: + contents: write + +on: + push: + branches: + - dev + +jobs: + version-and-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: login to docker registry + uses: docker/login-action@v3 + with: + username: ${{secrets.DOCKERHUB_USERNAME}} + password: ${{secrets.DOCKERHUB_TOKEN}} + + - name: build and push docker image to registry + uses: docker/build-push-action@v5 + with: + context: backend.Dockerfile + push: true + tags: mohammadsadeghmontazeri/starback:latest + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag_version.outputs.new_tag }} + release_name: Release ${{ steps.tag_version.outputs.new_tag }} + body: | + steps.tag_version.outputs.changelog + draft: false + prerelease: false diff --git a/.github/workflows/CI_Backend.yml b/.github/workflows/CI_Backend.yml index fe0cdce..e113f27 100644 --- a/.github/workflows/CI_Backend.yml +++ b/.github/workflows/CI_Backend.yml @@ -1,28 +1,28 @@ -name: CI_Backend - -on: - pull_request: - branches: - - dev - -jobs: - build-and-test: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: "6.0.x" - - - name: Restore dependencies - run: dotnet restore - - - name: Build project - run: dotnet build --configuration Release --no-restore - - - name: Run tests - run: dotnet test --no-build --verbosity normal +name: CI_Backend + +on: + pull_request: + branches: + - dev + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: "6.0.x" + + - name: Restore dependencies + run: dotnet restore + + - name: Build project + run: dotnet build --configuration Release --no-restore + + - name: Run tests + run: dotnet test --no-build --verbosity normal diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..81221a8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: test + +permissions: + contents: write + +on: + push: + branches: + - fixcompose + +jobs: + version-and-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: login to docker registry + uses: docker/login-action@v3 + with: + username: ${{secrets.DOCKERHUB_USERNAME}} + password: ${{secrets.DOCKERHUB_TOKEN}} + + - name: build and push docker image to registry + uses: docker/build-push-action@v5 + with: + context: migrate.Dockerfile + push: true + tags: mohammadsadeghmontazeri/migratestar:latest diff --git a/.gitignore b/.gitignore index 58c6b19..006474c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,808 +1,808 @@ -# Created by https://www.toptal.com/developers/gitignore/api/dotnetcore,aspnetcore,csharp,rider,visualstudiocode,visualstudio -# Edit at https://www.toptal.com/developers/gitignore?templates=dotnetcore,aspnetcore,csharp,rider,visualstudiocode,visualstudio - -### ASPNETCore ### -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/ - -### Csharp ### -## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore - -# User-specific files -*.rsuser - -# User-specific files (MonoDevelop/Xamarin Studio) - -# Mono auto generated files -mono_crash.* - -# Build results -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -# Uncomment if you have tasks that create the project's static files in wwwroot - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results - -# NUnit -nunit-*.xml - -# Build Results of an ATL Project - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_h.h -*.iobj -*.ipdb -*_wpftmp.csproj -*.tlog - -# Chutzpah Test files - -# Visual C++ cache files - -# Visual Studio profiler - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace - -# Guidance Automation Toolkit - -# ReSharper is a .NET coding add-in - -# TeamCity is a build add-in - -# DotCover is a Code Coverage Tool - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results - -# NCrunch - -# MightyMoose - -# Web workbench (sass) - -# Installshield output folder - -# DocProject is a documentation generator add-in - -# Click-Once directory - -# Publish Web Output -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted - -# NuGet Packages -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files - -# Microsoft Azure Build Output - -# Microsoft Azure Emulator - -# Windows Store app package directories and files -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) - -# RIA/Silverlight projects - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.ndf - -# Business Intelligence projects -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes - -# GhostDoc plugin setting file - -# Node.js Tools for Visual Studio - -# Visual Studio 6 build log - -# Visual Studio 6 workspace options file - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files - -# Visual Studio LightSwitch build output - -# Paket dependency manager - -# FAKE - F# Make - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# Visual Studio History (VSHistory) files -.vshistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -# Windows Installer files from build outputs -*.cab -*.msi -*.msix -*.msm -*.msp - -# JetBrains Rider - -### DotnetCore ### -# .NET Core build folders -bin/ -obj/ - -# Common node modules locations -/node_modules -/wwwroot/node_modules - -### Rider ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### VisualStudioCode ### -!.vscode/*.code-snippets - -# Local History for Visual Studio Code - -# Built Visual Studio Code Extensions -*.vsix - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history -.ionide - -### VisualStudio ### - -# User-specific files - -# User-specific files (MonoDevelop/Xamarin Studio) - -# Mono auto generated files - -# Build results - -# Visual Studio 2015/2017 cache/options directory -# Uncomment if you have tasks that create the project's static files in wwwroot - -# Visual Studio 2017 auto generated files - -# MSTest test Results - -# NUnit - -# Build Results of an ATL Project - -# Benchmark Results - -# .NET Core - -# ASP.NET Scaffolding - -# StyleCop - -# Files built by Visual Studio - -# Chutzpah Test files - -# Visual C++ cache files - -# Visual Studio profiler - -# Visual Studio Trace Files - -# TFS 2012 Local Workspace - -# Guidance Automation Toolkit - -# ReSharper is a .NET coding add-in - -# TeamCity is a build add-in - -# DotCover is a Code Coverage Tool - -# AxoCover is a Code Coverage Tool - -# Coverlet is a free, cross platform Code Coverage Tool - -# Visual Studio code coverage results - -# NCrunch - -# MightyMoose - -# Web workbench (sass) - -# Installshield output folder - -# DocProject is a documentation generator add-in - -# Click-Once directory - -# Publish Web Output -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted - -# NuGet Packages -# NuGet Symbol Packages -# The packages folder can be ignored because of Package Restore -# except build/, which is used as an MSBuild target. -# Uncomment if necessary however generally it will be regenerated when needed -# NuGet v3's project.json files produces more ignorable files - -# Microsoft Azure Build Output - -# Microsoft Azure Emulator - -# Windows Store app package directories and files - -# Visual Studio cache files -# files ending in .cache can be ignored -# but keep track of directories ending in .cache - -# Others - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) - -# RIA/Silverlight projects - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) - -# SQL Server files - -# Business Intelligence projects - -# Microsoft Fakes - -# GhostDoc plugin setting file - -# Node.js Tools for Visual Studio - -# Visual Studio 6 build log - -# Visual Studio 6 workspace options file - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) - -# Visual Studio 6 technical files - -# Visual Studio LightSwitch build output - -# Paket dependency manager - -# FAKE - F# Make - -# CodeRush personal settings - -# Python Tools for Visual Studio (PTVS) - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio - -# Telerik's JustMock configuration file - -# BizTalk build output - -# OpenCover UI analysis results - -# Azure Stream Analytics local run output - -# MSBuild Binary and Structured Log - -# NVidia Nsight GPU debugger configuration file - -# MFractors (Xamarin productivity tool) working folder - -# Local History for Visual Studio - -# Visual Studio History (VSHistory) files - -# BeatPulse healthcheck temp database - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 - -# Ionide (cross platform F# VS Code tools) working folder - -# Fody - auto-generated XML schema - -# VS Code files for those working on multiple tools - -# Local History for Visual Studio Code - -# Windows Installer files from build outputs - -# JetBrains Rider - -### VisualStudio Patch ### -# Additional files built by Visual Studio - +# Created by https://www.toptal.com/developers/gitignore/api/dotnetcore,aspnetcore,csharp,rider,visualstudiocode,visualstudio +# Edit at https://www.toptal.com/developers/gitignore?templates=dotnetcore,aspnetcore,csharp,rider,visualstudiocode,visualstudio + +### ASPNETCore ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ + +### Csharp ### +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser + +# User-specific files (MonoDevelop/Xamarin Studio) + +# Mono auto generated files +mono_crash.* + +# Build results +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +# Uncomment if you have tasks that create the project's static files in wwwroot + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results + +# NUnit +nunit-*.xml + +# Build Results of an ATL Project + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_h.h +*.iobj +*.ipdb +*_wpftmp.csproj +*.tlog + +# Chutzpah Test files + +# Visual C++ cache files + +# Visual Studio profiler + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace + +# Guidance Automation Toolkit + +# ReSharper is a .NET coding add-in + +# TeamCity is a build add-in + +# DotCover is a Code Coverage Tool + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results + +# NCrunch + +# MightyMoose + +# Web workbench (sass) + +# Installshield output folder + +# DocProject is a documentation generator add-in + +# Click-Once directory + +# Publish Web Output +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted + +# NuGet Packages +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files + +# Microsoft Azure Build Output + +# Microsoft Azure Emulator + +# Windows Store app package directories and files +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) + +# RIA/Silverlight projects + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.ndf + +# Business Intelligence projects +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes + +# GhostDoc plugin setting file + +# Node.js Tools for Visual Studio + +# Visual Studio 6 build log + +# Visual Studio 6 workspace options file + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output + +# Paket dependency manager + +# FAKE - F# Make + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider + +### DotnetCore ### +# .NET Core build folders +bin/ +obj/ + +# Common node modules locations +/node_modules +/wwwroot/node_modules + +### Rider ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### VisualStudioCode ### +!.vscode/*.code-snippets + +# Local History for Visual Studio Code + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### VisualStudio ### + +# User-specific files + +# User-specific files (MonoDevelop/Xamarin Studio) + +# Mono auto generated files + +# Build results + +# Visual Studio 2015/2017 cache/options directory +# Uncomment if you have tasks that create the project's static files in wwwroot + +# Visual Studio 2017 auto generated files + +# MSTest test Results + +# NUnit + +# Build Results of an ATL Project + +# Benchmark Results + +# .NET Core + +# ASP.NET Scaffolding + +# StyleCop + +# Files built by Visual Studio + +# Chutzpah Test files + +# Visual C++ cache files + +# Visual Studio profiler + +# Visual Studio Trace Files + +# TFS 2012 Local Workspace + +# Guidance Automation Toolkit + +# ReSharper is a .NET coding add-in + +# TeamCity is a build add-in + +# DotCover is a Code Coverage Tool + +# AxoCover is a Code Coverage Tool + +# Coverlet is a free, cross platform Code Coverage Tool + +# Visual Studio code coverage results + +# NCrunch + +# MightyMoose + +# Web workbench (sass) + +# Installshield output folder + +# DocProject is a documentation generator add-in + +# Click-Once directory + +# Publish Web Output +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted + +# NuGet Packages +# NuGet Symbol Packages +# The packages folder can be ignored because of Package Restore +# except build/, which is used as an MSBuild target. +# Uncomment if necessary however generally it will be regenerated when needed +# NuGet v3's project.json files produces more ignorable files + +# Microsoft Azure Build Output + +# Microsoft Azure Emulator + +# Windows Store app package directories and files + +# Visual Studio cache files +# files ending in .cache can be ignored +# but keep track of directories ending in .cache + +# Others + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) + +# RIA/Silverlight projects + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) + +# SQL Server files + +# Business Intelligence projects + +# Microsoft Fakes + +# GhostDoc plugin setting file + +# Node.js Tools for Visual Studio + +# Visual Studio 6 build log + +# Visual Studio 6 workspace options file + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output + +# Paket dependency manager + +# FAKE - F# Make + +# CodeRush personal settings + +# Python Tools for Visual Studio (PTVS) + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio + +# Telerik's JustMock configuration file + +# BizTalk build output + +# OpenCover UI analysis results + +# Azure Stream Analytics local run output + +# MSBuild Binary and Structured Log + +# NVidia Nsight GPU debugger configuration file + +# MFractors (Xamarin productivity tool) working folder + +# Local History for Visual Studio + +# Visual Studio History (VSHistory) files + +# BeatPulse healthcheck temp database + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 + +# Ionide (cross platform F# VS Code tools) working folder + +# Fody - auto-generated XML schema + +# VS Code files for those working on multiple tools + +# Local History for Visual Studio Code + +# Windows Installer files from build outputs + +# JetBrains Rider + +### VisualStudio Patch ### +# Additional files built by Visual Studio + # End of https://www.toptal.com/developers/gitignore/api/dotnetcore,aspnetcore,csharp,rider,visualstudiocode,visualstudio \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index dbe76ad..a2c001b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,28 @@ -# Use the official .NET SDK image to build the app -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build -WORKDIR /app - -# Copy everything and restore as distinct layers -COPY . ./ -RUN dotnet restore - -# Build and publish the app to the out directory -RUN dotnet publish src/Web/Web.csproj -c Release -o out - -# Use the official ASP.NET image to serve the app -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime -WORKDIR /app -COPY --from=build /app/out ./ - -# Environment variables for the database connection -ENV ASPNETCORE_ENVIRONMENT=Development -ENV ConnectionStrings__DefaultConnection=Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword -ENV ASPNETCORE_URLS=http://*:80 -EXPOSE 80 - - -# Start the application -ENTRYPOINT ["dotnet", "Web.dll"] - - - +# Use the official .NET SDK image to build the app +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /app + +# Copy everything and restore as distinct layers +COPY . ./ +RUN dotnet restore + +# Build and publish the app to the out directory +RUN dotnet publish src/Web/Web.csproj -c Release -o out + +# Use the official ASP.NET image to serve the app +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +WORKDIR /app +COPY --from=build /app/out ./ + +# Environment variables for the database connection +ENV ASPNETCORE_ENVIRONMENT=Development +ENV ConnectionStrings__DefaultConnection=Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword +ENV ASPNETCORE_URLS=http://*:80 +EXPOSE 80 + + +# Start the application +ENTRYPOINT ["dotnet", "Web.dll"] + + + diff --git a/Summer1403-Project-Group01-Backend.sln b/Summer1403-Project-Group01-Backend.sln index e26f675..a2c1933 100644 --- a/Summer1403-Project-Group01-Backend.sln +++ b/Summer1403-Project-Group01-Backend.sln @@ -1,40 +1,40 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31903.59 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{B358A8CE-2718-4056-94AA-D5A40DD67AEF}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Application\Application.csproj", "{90C204C7-AB46-45E5-9AE0-912800436545}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "src\Web\Web.csproj", "{961DAD51-ECA7-4389-8CD8-04DC47720E37}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Debug|Any CPU.Build.0 = Debug|Any CPU - {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Release|Any CPU.ActiveCfg = Release|Any CPU - {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Release|Any CPU.Build.0 = Release|Any CPU - {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Release|Any CPU.Build.0 = Release|Any CPU - {90C204C7-AB46-45E5-9AE0-912800436545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {90C204C7-AB46-45E5-9AE0-912800436545}.Debug|Any CPU.Build.0 = Debug|Any CPU - {90C204C7-AB46-45E5-9AE0-912800436545}.Release|Any CPU.ActiveCfg = Release|Any CPU - {90C204C7-AB46-45E5-9AE0-912800436545}.Release|Any CPU.Build.0 = Release|Any CPU - {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Debug|Any CPU.Build.0 = Debug|Any CPU - {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Release|Any CPU.ActiveCfg = Release|Any CPU - {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{B358A8CE-2718-4056-94AA-D5A40DD67AEF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Application\Application.csproj", "{90C204C7-AB46-45E5-9AE0-912800436545}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "src\Web\Web.csproj", "{961DAD51-ECA7-4389-8CD8-04DC47720E37}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84F8DBE3-ACF4-49A7-AB89-97A97BF6C351}.Release|Any CPU.Build.0 = Release|Any CPU + {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B358A8CE-2718-4056-94AA-D5A40DD67AEF}.Release|Any CPU.Build.0 = Release|Any CPU + {90C204C7-AB46-45E5-9AE0-912800436545}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90C204C7-AB46-45E5-9AE0-912800436545}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90C204C7-AB46-45E5-9AE0-912800436545}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90C204C7-AB46-45E5-9AE0-912800436545}.Release|Any CPU.Build.0 = Release|Any CPU + {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {961DAD51-ECA7-4389-8CD8-04DC47720E37}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/backend.Dockerfile b/backend.Dockerfile new file mode 100644 index 0000000..a2c001b --- /dev/null +++ b/backend.Dockerfile @@ -0,0 +1,28 @@ +# Use the official .NET SDK image to build the app +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /app + +# Copy everything and restore as distinct layers +COPY . ./ +RUN dotnet restore + +# Build and publish the app to the out directory +RUN dotnet publish src/Web/Web.csproj -c Release -o out + +# Use the official ASP.NET image to serve the app +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +WORKDIR /app +COPY --from=build /app/out ./ + +# Environment variables for the database connection +ENV ASPNETCORE_ENVIRONMENT=Development +ENV ConnectionStrings__DefaultConnection=Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword +ENV ASPNETCORE_URLS=http://*:80 +EXPOSE 80 + + +# Start the application +ENTRYPOINT ["dotnet", "Web.dll"] + + + diff --git a/docker-compose.yml b/docker-compose.yml index ccda1aa..a1643b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,41 +1,41 @@ -version: '3.8' - -services: - db: - image: postgres:15 - environment: - POSTGRES_USER: yourusername - POSTGRES_PASSWORD: yourpassword - POSTGRES_DB: YourDatabaseName - ports: - - "5432:5432" - volumes: - - pgdata:/var/lib/postgresql/data - - migrate: - image: mcr.microsoft.com/dotnet/sdk:8.0 - depends_on: - - db - working_dir: /app - volumes: - - .:/app - environment: - ConnectionStrings__DefaultConnection: Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword - command: > - bash -c "dotnet tool install --global dotnet-ef && - export PATH=\"$PATH:/root/.dotnet/tools\" && - dotnet ef database update --project src/Infrastructure/Infrastructure.csproj --startup-project src/Web/Web.csproj" - - web: - build: . - depends_on: - migrate: - condition: service_completed_successfully - environment: - ASPNETCORE_ENVIRONMENT: Development - ConnectionStrings__DefaultConnection: Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword - ports: - - "8080:80" - -volumes: +version: '3.8' + +services: + db: + image: postgres:15 + environment: + POSTGRES_USER: yourusername + POSTGRES_PASSWORD: yourpassword + POSTGRES_DB: YourDatabaseName + ports: + - "5432:5432" + volumes: + - pgdata:/var/lib/postgresql/data + + migrate: + image: mcr.microsoft.com/dotnet/sdk:8.0 + depends_on: + - db + working_dir: /app + volumes: + - .:/app + environment: + ConnectionStrings__DefaultConnection: Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword + command: > + bash -c "dotnet tool install --global dotnet-ef && + export PATH=\"$PATH:/root/.dotnet/tools\" && + dotnet ef database update --project src/Infrastructure/Infrastructure.csproj --startup-project src/Web/Web.csproj" + + web: + image: mohammadsadeghmontazeri/starback:latest + depends_on: + migrate: + condition: service_completed_successfully + environment: + ASPNETCORE_ENVIRONMENT: Development + ConnectionStrings__DefaultConnection: Host=db;Database=YourDatabaseName;Username=yourusername;Password=yourpassword + ports: + - "8080:80" + +volumes: pgdata: \ No newline at end of file diff --git a/migrate.Dockerfile b/migrate.Dockerfile new file mode 100644 index 0000000..86a231c --- /dev/null +++ b/migrate.Dockerfile @@ -0,0 +1,19 @@ +# Use the .NET SDK image as the base image +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# Set the working directory inside the container +WORKDIR /app + +# Copy the project files into the container +COPY . . + +# Install the dotnet-ef tool globally +RUN dotnet tool install --global dotnet-ef + +# Ensure the global tools are in the PATH +ENV PATH="$PATH:/root/.dotnet/tools" + + + +# Run the EF database update command directly +CMD ["dotnet", "ef", "database", "update", "--project", "src/Infrastructure/Infrastructure.csproj", "--startup-project", "src/Web/Web.csproj"] diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index 633569a..88c78fe 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -1,17 +1,17 @@ - - - - net8.0 - enable - enable - - - - - - - - - - - + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/src/Application/DTOs/AccountCsv/AccountCsvModel.cs b/src/Application/DTOs/AccountCsv/AccountCsvModel.cs index 81ee0cb..0fce57a 100644 --- a/src/Application/DTOs/AccountCsv/AccountCsvModel.cs +++ b/src/Application/DTOs/AccountCsv/AccountCsvModel.cs @@ -1,15 +1,15 @@ -namespace Application.DTOs.AccountCsv; - -public class AccountCsvModel -{ - public long AccountID { get; set; } - public long CardID { get; set; } - public string IBAN { get; set; } = String.Empty; - public string AccountType { get; set; } = String.Empty; - public string BranchTelephone { get; set; } = String.Empty; - public string BranchAdress { get; set; } = String.Empty; - public string BranchName { get; set; } = String.Empty; - public string OwnerName { get; set; } = String.Empty; - public string OwnerLastName { get; set; } = String.Empty; - public string OwnerID { get; set; } = String.Empty; +namespace Application.DTOs.AccountCsv; + +public class AccountCsvModel +{ + public long AccountID { get; set; } + public long CardID { get; set; } + public string IBAN { get; set; } = String.Empty; + public string AccountType { get; set; } = String.Empty; + public string BranchTelephone { get; set; } = String.Empty; + public string BranchAdress { get; set; } = String.Empty; + public string BranchName { get; set; } = String.Empty; + public string OwnerName { get; set; } = String.Empty; + public string OwnerLastName { get; set; } = String.Empty; + public string OwnerID { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Identity/ChangeRole/ChangeRoleRequest.cs b/src/Application/DTOs/Identity/ChangeRole/ChangeRoleRequest.cs index 7cbce05..2d4d905 100644 --- a/src/Application/DTOs/Identity/ChangeRole/ChangeRoleRequest.cs +++ b/src/Application/DTOs/Identity/ChangeRole/ChangeRoleRequest.cs @@ -1,7 +1,7 @@ -namespace Application.DTOs.Identity.ChangeRole; - -public class ChangeRoleRequest -{ - public string UserName { get; set; } = string.Empty; - public string Role { get; set; } = string.Empty; +namespace Application.DTOs.Identity.ChangeRole; + +public class ChangeRoleRequest +{ + public string UserName { get; set; } = string.Empty; + public string Role { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Identity/CreateUser/CreateUserRequest.cs b/src/Application/DTOs/Identity/CreateUser/CreateUserRequest.cs index cefb92e..991f117 100644 --- a/src/Application/DTOs/Identity/CreateUser/CreateUserRequest.cs +++ b/src/Application/DTOs/Identity/CreateUser/CreateUserRequest.cs @@ -1,13 +1,13 @@ -using System.ComponentModel.DataAnnotations; - -namespace Application.DTOs.Identity; - -public class CreateUserRequest -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Password { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; +using System.ComponentModel.DataAnnotations; + +namespace Application.DTOs.Identity; + +public class CreateUserRequest +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Password { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Identity/CreateUser/CreateUserResponse.cs b/src/Application/DTOs/Identity/CreateUser/CreateUserResponse.cs index 875e5d8..24aa8eb 100644 --- a/src/Application/DTOs/Identity/CreateUser/CreateUserResponse.cs +++ b/src/Application/DTOs/Identity/CreateUser/CreateUserResponse.cs @@ -1,10 +1,10 @@ -namespace Application.DTOs.Identity; - -public class CreateUserResponse -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; +namespace Application.DTOs.Identity; + +public class CreateUserResponse +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Identity/LoginUser/LoginUserRequest.cs b/src/Application/DTOs/Identity/LoginUser/LoginUserRequest.cs index d10f8a3..15ea49a 100644 --- a/src/Application/DTOs/Identity/LoginUser/LoginUserRequest.cs +++ b/src/Application/DTOs/Identity/LoginUser/LoginUserRequest.cs @@ -1,10 +1,10 @@ -using System.ComponentModel.DataAnnotations; - -namespace Application.DTOs.Identity; - -public class LoginUserRequest -{ - public string? UserName { get; set; } - public string? Email { get; set; } - public string Password { get; set; } = String.Empty; +using System.ComponentModel.DataAnnotations; + +namespace Application.DTOs.Identity; + +public class LoginUserRequest +{ + public string? UserName { get; set; } + public string? Email { get; set; } + public string Password { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Identity/LoginUser/LoginUserResponse.cs b/src/Application/DTOs/Identity/LoginUser/LoginUserResponse.cs index 170c2de..30d9362 100644 --- a/src/Application/DTOs/Identity/LoginUser/LoginUserResponse.cs +++ b/src/Application/DTOs/Identity/LoginUser/LoginUserResponse.cs @@ -1,11 +1,11 @@ -namespace Application.DTOs.Identity; - -public class LoginUserResponse -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; - public string Token { get; set; } = String.Empty; +namespace Application.DTOs.Identity; + +public class LoginUserResponse +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; + public string Token { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Profile/ChangePassword/ChangePasswordRequest.cs b/src/Application/DTOs/Profile/ChangePassword/ChangePasswordRequest.cs index 439af56..3ad7a16 100644 --- a/src/Application/DTOs/Profile/ChangePassword/ChangePasswordRequest.cs +++ b/src/Application/DTOs/Profile/ChangePassword/ChangePasswordRequest.cs @@ -1,8 +1,8 @@ -namespace Application.DTOs.Profile.ChangePassword; - -public class ChangePasswordRequest -{ - public string UserId { get; set; } = string.Empty; - public string CurrentPassword { get; set; } = string.Empty; - public string NewPassword { get; set; } = string.Empty; +namespace Application.DTOs.Profile.ChangePassword; + +public class ChangePasswordRequest +{ + public string UserId { get; set; } = string.Empty; + public string CurrentPassword { get; set; } = string.Empty; + public string NewPassword { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Profile/EditProfile/EditProfileInfoRequest.cs b/src/Application/DTOs/Profile/EditProfile/EditProfileInfoRequest.cs index b132547..d5d3d92 100644 --- a/src/Application/DTOs/Profile/EditProfile/EditProfileInfoRequest.cs +++ b/src/Application/DTOs/Profile/EditProfile/EditProfileInfoRequest.cs @@ -1,9 +1,9 @@ -namespace Application.DTOs.Identity; - -public class EditProfileInfoRequest -{ - public string UserId { get; set; } = string.Empty; - public string UserName { get; set; } = string.Empty; - public string FirstName { get; set; } = string.Empty; - public string LastName { get; set; } = string.Empty; +namespace Application.DTOs.Identity; + +public class EditProfileInfoRequest +{ + public string UserId { get; set; } = string.Empty; + public string UserName { get; set; } = string.Empty; + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Profile/EditProfile/EditProfileInfoResponse.cs b/src/Application/DTOs/Profile/EditProfile/EditProfileInfoResponse.cs index 9fa2e26..67c9be3 100644 --- a/src/Application/DTOs/Profile/EditProfile/EditProfileInfoResponse.cs +++ b/src/Application/DTOs/Profile/EditProfile/EditProfileInfoResponse.cs @@ -1,9 +1,9 @@ -namespace Application.DTOs.Identity; - -public class EditProfileInfoResponse -{ - public string UserName { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string FirstName { get; set; } = string.Empty; - public string LastName { get; set; } = string.Empty; +namespace Application.DTOs.Identity; + +public class EditProfileInfoResponse +{ + public string UserName { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoRequest.cs b/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoRequest.cs index 1b1da1b..4c4c9f3 100644 --- a/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoRequest.cs +++ b/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoRequest.cs @@ -1,6 +1,6 @@ -namespace Application.DTOs.Identity; - -public class GetProfileInfoRequest -{ - public string UserId { get; set; } = String.Empty; +namespace Application.DTOs.Identity; + +public class GetProfileInfoRequest +{ + public string UserId { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoResponse.cs b/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoResponse.cs index c05d18f..ea98334 100644 --- a/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoResponse.cs +++ b/src/Application/DTOs/Profile/GetProfileInfo/GetProfileInfoResponse.cs @@ -1,10 +1,10 @@ -namespace Application.DTOs.Identity; - -public class GetProfileInfoResponse -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; +namespace Application.DTOs.Identity; + +public class GetProfileInfoResponse +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Application/DTOs/Result.cs b/src/Application/DTOs/Result.cs index 23eb544..e2ed9d1 100644 --- a/src/Application/DTOs/Result.cs +++ b/src/Application/DTOs/Result.cs @@ -1,47 +1,47 @@ -namespace Application.DTOs; - -public class Result -{ - public string Message { get; protected set; } = string.Empty; - public bool Succeed { get; protected set; } - - public static Result Ok() - { - return new Result - { - Succeed = true - }; - } - - public static Result Fail(string message = "failed") - { - return new Result - { - Succeed = false, - Message = message - }; - } -} - -public class Result : Result -{ - public T? Value { get; private set; } - - public static Result Ok(T value) - { - return new Result - { - Succeed = true, - Value = value - }; - } - - public static Result Fail(string message = "failed") - { - return new Result - { - Succeed = false, - Message = message - }; - } +namespace Application.DTOs; + +public class Result +{ + public string Message { get; protected set; } = string.Empty; + public bool Succeed { get; protected set; } + + public static Result Ok() + { + return new Result + { + Succeed = true + }; + } + + public static Result Fail(string message = "failed") + { + return new Result + { + Succeed = false, + Message = message + }; + } +} + +public class Result : Result +{ + public T? Value { get; private set; } + + public static Result Ok(T value) + { + return new Result + { + Succeed = true, + Value = value + }; + } + + public static Result Fail(string message = "failed") + { + return new Result + { + Succeed = false, + Message = message + }; + } } \ No newline at end of file diff --git a/src/Application/DTOs/TransactionCsv/GetAllTransactionsResponse.cs b/src/Application/DTOs/TransactionCsv/GetAllTransactionsResponse.cs index 80f5631..5c5ba49 100644 --- a/src/Application/DTOs/TransactionCsv/GetAllTransactionsResponse.cs +++ b/src/Application/DTOs/TransactionCsv/GetAllTransactionsResponse.cs @@ -1,17 +1,17 @@ -namespace Web.DTOs.Transaction; - -public class GetAllTransactionsResponse -{ - public List Transactions { get; set; } = new(); - - public class TransactionDto - { - public long TransactionId { get; set; } - public long SourceAccountId { get; set; } - public long DestinationAccountId { get; set; } - public decimal Amount { get; set; } - public DateTime Date { get; set; } - public string Type { get; set; } = string.Empty; - } - +namespace Web.DTOs.Transaction; + +public class GetAllTransactionsResponse +{ + public List Transactions { get; set; } = new(); + + public class TransactionDto + { + public long TransactionId { get; set; } + public long SourceAccountId { get; set; } + public long DestinationAccountId { get; set; } + public decimal Amount { get; set; } + public DateTime Date { get; set; } + public string Type { get; set; } = string.Empty; + } + } \ No newline at end of file diff --git a/src/Application/DTOs/TransactionCsv/TransactionCsvModel.cs b/src/Application/DTOs/TransactionCsv/TransactionCsvModel.cs index 895f937..1b1cac9 100644 --- a/src/Application/DTOs/TransactionCsv/TransactionCsvModel.cs +++ b/src/Application/DTOs/TransactionCsv/TransactionCsvModel.cs @@ -1,15 +1,15 @@ -using Application.Services.SharedService; -using CsvHelper.Configuration.Attributes; - -namespace Application.DTOs.TransactionCsv; - -public class TransactionCsvModel -{ - public long TransactionID { get; set; } - public long SourceAcount { get; set; } - public long DestiantionAccount { get; set; } - public decimal Amount { get; set; } - [TypeConverter(typeof(PersianDateConverter))] - public DateTime Date { get; set; } - public string Type { get; set; } = string.Empty; +using Application.Services.SharedService; +using CsvHelper.Configuration.Attributes; + +namespace Application.DTOs.TransactionCsv; + +public class TransactionCsvModel +{ + public long TransactionID { get; set; } + public long SourceAcount { get; set; } + public long DestiantionAccount { get; set; } + public decimal Amount { get; set; } + [TypeConverter(typeof(PersianDateConverter))] + public DateTime Date { get; set; } + public string Type { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Application/ExtensionMethods/ExtensionMethods.cs b/src/Application/ExtensionMethods/ExtensionMethods.cs index 408e9ea..d3d5930 100644 --- a/src/Application/ExtensionMethods/ExtensionMethods.cs +++ b/src/Application/ExtensionMethods/ExtensionMethods.cs @@ -1,11 +1,11 @@ -using Microsoft.AspNetCore.Identity; - -namespace Application.ExtensionMethods; - -public static class ExtensionMethods -{ - public static string FirstMessage(this IEnumerable errors) - { - return errors.FirstOrDefault()?.Description ?? "Unknown Error."; - } +using Microsoft.AspNetCore.Identity; + +namespace Application.ExtensionMethods; + +public static class ExtensionMethods +{ + public static string FirstMessage(this IEnumerable errors) + { + return errors.FirstOrDefault()?.Description ?? "Unknown Error."; + } } \ No newline at end of file diff --git a/src/Application/Interfaces/IAccountRepository.cs b/src/Application/Interfaces/IAccountRepository.cs index 19cc5ba..88ca7ad 100644 --- a/src/Application/Interfaces/IAccountRepository.cs +++ b/src/Application/Interfaces/IAccountRepository.cs @@ -1,10 +1,10 @@ -using Domain.Entities; - -namespace Application.Interfaces; - -public interface IAccountRepository -{ - Task CreateBulkAsync(List accounts); - Task GetByIdAsync(long accountId); - Task> GetTransactionsByAccountId(long accountId); +using Domain.Entities; + +namespace Application.Interfaces; + +public interface IAccountRepository +{ + Task CreateBulkAsync(List accounts); + Task GetByIdAsync(long accountId); + Task> GetTransactionsByAccountId(long accountId); } \ No newline at end of file diff --git a/src/Application/Interfaces/IJwtGenerator.cs b/src/Application/Interfaces/IJwtGenerator.cs index 5c9c40c..d0d6041 100644 --- a/src/Application/Interfaces/IJwtGenerator.cs +++ b/src/Application/Interfaces/IJwtGenerator.cs @@ -1,8 +1,8 @@ -using Domain.Entities; - -namespace Web.Interfaces; - -public interface IJwtGenerator -{ - string GenerateToken(AppUser user, string role); +using Domain.Entities; + +namespace Web.Interfaces; + +public interface IJwtGenerator +{ + string GenerateToken(AppUser user, string role); } \ No newline at end of file diff --git a/src/Application/Interfaces/IRoleManager.cs b/src/Application/Interfaces/IRoleManager.cs index 5b20e42..8516595 100644 --- a/src/Application/Interfaces/IRoleManager.cs +++ b/src/Application/Interfaces/IRoleManager.cs @@ -1,6 +1,6 @@ -namespace Application.Interfaces; - -public interface IRoleManager -{ - Task RoleExistsAsync(string roleName); +namespace Application.Interfaces; + +public interface IRoleManager +{ + Task RoleExistsAsync(string roleName); } \ No newline at end of file diff --git a/src/Application/Interfaces/ITransactionRepository.cs b/src/Application/Interfaces/ITransactionRepository.cs index 1a96ef2..a73dc45 100644 --- a/src/Application/Interfaces/ITransactionRepository.cs +++ b/src/Application/Interfaces/ITransactionRepository.cs @@ -1,9 +1,9 @@ -using Domain.Entities; - -namespace Application.Interfaces; - -public interface ITransactionRepository -{ - Task CreateBulkAsync(List transactions); - Task> GetAllTransactions(); +using Domain.Entities; + +namespace Application.Interfaces; + +public interface ITransactionRepository +{ + Task CreateBulkAsync(List transactions); + Task> GetAllTransactions(); } \ No newline at end of file diff --git a/src/Application/Interfaces/IUserManager.cs b/src/Application/Interfaces/IUserManager.cs index 2e9c136..4baf0d7 100644 --- a/src/Application/Interfaces/IUserManager.cs +++ b/src/Application/Interfaces/IUserManager.cs @@ -1,19 +1,19 @@ -using Application.DTOs; -using Domain.Entities; -using Microsoft.AspNetCore.Identity; - -namespace Application.Interfaces; - -public interface IUserManager -{ - Task CreateAsync(AppUser user, string password); - Task SetRoleAsync(AppUser user, string role); - Task ChangeRoleAsync(AppUser user, string newRole); - Task FindByNameAsync(string userName); - Task FindByEmailAsync(string email); - Task FindByIdAsync(string userId); - Task UpdateAsync(AppUser user); - Task ChangePasswordAsync(AppUser user, string currentPassword, string newPassword); - Task GetRoleAsync(AppUser user); - Task CheckPasswordAsync(AppUser user, string password); +using Application.DTOs; +using Domain.Entities; +using Microsoft.AspNetCore.Identity; + +namespace Application.Interfaces; + +public interface IUserManager +{ + Task CreateAsync(AppUser user, string password); + Task SetRoleAsync(AppUser user, string role); + Task ChangeRoleAsync(AppUser user, string newRole); + Task FindByNameAsync(string userName); + Task FindByEmailAsync(string email); + Task FindByIdAsync(string userId); + Task UpdateAsync(AppUser user); + Task ChangePasswordAsync(AppUser user, string currentPassword, string newPassword); + Task GetRoleAsync(AppUser user); + Task CheckPasswordAsync(AppUser user, string password); } \ No newline at end of file diff --git a/src/Application/Interfaces/Services/IAccountService.cs b/src/Application/Interfaces/Services/IAccountService.cs index 6e41d4c..9a87aeb 100644 --- a/src/Application/Interfaces/Services/IAccountService.cs +++ b/src/Application/Interfaces/Services/IAccountService.cs @@ -1,11 +1,11 @@ -using Application.DTOs; -using Domain.Entities; - -namespace Application.Interfaces.Services; - -public interface IAccountService -{ - Task AddAccountsFromCsvAsync(string filePath); - Task GetAccountByIdAsync(long accountId); - Task>> GetTransactionsByUserId(long accountId); +using Application.DTOs; +using Domain.Entities; + +namespace Application.Interfaces.Services; + +public interface IAccountService +{ + Task AddAccountsFromCsvAsync(string filePath); + Task GetAccountByIdAsync(long accountId); + Task>> GetTransactionsByUserId(long accountId); } \ No newline at end of file diff --git a/src/Application/Interfaces/Services/IIdentityService.cs b/src/Application/Interfaces/Services/IIdentityService.cs index a399a97..ae51223 100644 --- a/src/Application/Interfaces/Services/IIdentityService.cs +++ b/src/Application/Interfaces/Services/IIdentityService.cs @@ -1,12 +1,12 @@ -using Application.DTOs; -using Application.DTOs.Identity; -using Application.DTOs.Identity.ChangeRole; - -namespace Application.Interfaces.Services; - -public interface IIdentityService -{ - Task> SignUpUser(CreateUserRequest createIdentityDto); - Task> Login(LoginUserRequest loginDto); - Task ChangeRole(ChangeRoleRequest changeRoleRequest); +using Application.DTOs; +using Application.DTOs.Identity; +using Application.DTOs.Identity.ChangeRole; + +namespace Application.Interfaces.Services; + +public interface IIdentityService +{ + Task> SignUpUser(CreateUserRequest createIdentityDto); + Task> Login(LoginUserRequest loginDto); + Task ChangeRole(ChangeRoleRequest changeRoleRequest); } \ No newline at end of file diff --git a/src/Application/Interfaces/Services/IProfileService.cs b/src/Application/Interfaces/Services/IProfileService.cs index ccbf8bd..b8de465 100644 --- a/src/Application/Interfaces/Services/IProfileService.cs +++ b/src/Application/Interfaces/Services/IProfileService.cs @@ -1,12 +1,12 @@ -using Application.DTOs; -using Application.DTOs.Identity; -using Application.DTOs.Profile.ChangePassword; - -namespace Application.Interfaces.Services; - -public interface IProfileService -{ - Task> EditProfileInfo(EditProfileInfoRequest infoRequest); - Task> GetProfileInfo(GetProfileInfoRequest profileRequest); - Task ChangePassword(ChangePasswordRequest request); +using Application.DTOs; +using Application.DTOs.Identity; +using Application.DTOs.Profile.ChangePassword; + +namespace Application.Interfaces.Services; + +public interface IProfileService +{ + Task> EditProfileInfo(EditProfileInfoRequest infoRequest); + Task> GetProfileInfo(GetProfileInfoRequest profileRequest); + Task ChangePassword(ChangePasswordRequest request); } \ No newline at end of file diff --git a/src/Application/Interfaces/Services/ITransactionService.cs b/src/Application/Interfaces/Services/ITransactionService.cs index cb5ffaa..5d5cd4c 100644 --- a/src/Application/Interfaces/Services/ITransactionService.cs +++ b/src/Application/Interfaces/Services/ITransactionService.cs @@ -1,10 +1,10 @@ -using Application.DTOs; -using Web.DTOs.Transaction; - -namespace Application.Interfaces.Services; - -public interface ITransactionService -{ - Task AddTransactionsFromCsvAsync(string filePath); - Task> GetAllTransactions(); +using Application.DTOs; +using Web.DTOs.Transaction; + +namespace Application.Interfaces.Services; + +public interface ITransactionService +{ + Task AddTransactionsFromCsvAsync(string filePath); + Task> GetAllTransactions(); } \ No newline at end of file diff --git a/src/Application/Interfaces/SharedService/ICsvService.cs b/src/Application/Interfaces/SharedService/ICsvService.cs index 58318df..37d4ea7 100644 --- a/src/Application/Interfaces/SharedService/ICsvService.cs +++ b/src/Application/Interfaces/SharedService/ICsvService.cs @@ -1,6 +1,6 @@ -namespace Application.Interfaces.SharedService; - -public interface ICsvService -{ - +namespace Application.Interfaces.SharedService; + +public interface ICsvService +{ + } \ No newline at end of file diff --git a/src/Application/Mappers/IdentityMapper.cs b/src/Application/Mappers/IdentityMapper.cs index 41414b7..dd67eb0 100644 --- a/src/Application/Mappers/IdentityMapper.cs +++ b/src/Application/Mappers/IdentityMapper.cs @@ -1,43 +1,43 @@ -using Application.DTOs.Identity; -using Domain.Entities; - -namespace Application.Mappers; - -public static class IdentityMapper -{ - public static AppUser ToAppUser(this CreateUserRequest createUserRequest) - { - return new AppUser - { - FirstName = createUserRequest.FirstName, - LastName = createUserRequest.LastName, - Email = createUserRequest.Email, - UserName = createUserRequest.UserName - }; - } - - public static CreateUserResponse ToCreateUserResponse(this AppUser appUser, string role) - { - return new CreateUserResponse - { - FirstName = appUser.FirstName, - LastName = appUser.LastName, - Email = appUser.Email, - UserName = appUser.UserName, - Role = role - }; - } - - public static LoginUserResponse ToLoginUserResponse(this AppUser appUser, string role, string token) - { - return new LoginUserResponse - { - FirstName = appUser.FirstName, - LastName = appUser.LastName, - Email = appUser.Email, - UserName = appUser.UserName, - Role = role, - Token = token - }; - } +using Application.DTOs.Identity; +using Domain.Entities; + +namespace Application.Mappers; + +public static class IdentityMapper +{ + public static AppUser ToAppUser(this CreateUserRequest createUserRequest) + { + return new AppUser + { + FirstName = createUserRequest.FirstName, + LastName = createUserRequest.LastName, + Email = createUserRequest.Email, + UserName = createUserRequest.UserName + }; + } + + public static CreateUserResponse ToCreateUserResponse(this AppUser appUser, string role) + { + return new CreateUserResponse + { + FirstName = appUser.FirstName, + LastName = appUser.LastName, + Email = appUser.Email, + UserName = appUser.UserName, + Role = role + }; + } + + public static LoginUserResponse ToLoginUserResponse(this AppUser appUser, string role, string token) + { + return new LoginUserResponse + { + FirstName = appUser.FirstName, + LastName = appUser.LastName, + Email = appUser.Email, + UserName = appUser.UserName, + Role = role, + Token = token + }; + } } \ No newline at end of file diff --git a/src/Application/Mappers/ProfileMapper.cs b/src/Application/Mappers/ProfileMapper.cs index 7c2982a..a4535f0 100644 --- a/src/Application/Mappers/ProfileMapper.cs +++ b/src/Application/Mappers/ProfileMapper.cs @@ -1,29 +1,29 @@ -using Application.DTOs.Identity; -using Domain.Entities; - -namespace Application.Mappers; - -public static class ProfileMapper -{ - public static GetProfileInfoResponse ToGetProfileInfoResponse(this AppUser user, string role) - { - return new GetProfileInfoResponse - { - FirstName = user.FirstName, - LastName = user.LastName, - Email = user.Email, - UserName = user.UserName, - Role = role - }; - } - public static EditProfileInfoResponse ToEditProfileInfoResponse(this AppUser user) - { - return new EditProfileInfoResponse - { - FirstName = user.FirstName, - LastName = user.LastName, - Email = user.Email, - UserName = user.UserName - }; - } +using Application.DTOs.Identity; +using Domain.Entities; + +namespace Application.Mappers; + +public static class ProfileMapper +{ + public static GetProfileInfoResponse ToGetProfileInfoResponse(this AppUser user, string role) + { + return new GetProfileInfoResponse + { + FirstName = user.FirstName, + LastName = user.LastName, + Email = user.Email, + UserName = user.UserName, + Role = role + }; + } + public static EditProfileInfoResponse ToEditProfileInfoResponse(this AppUser user) + { + return new EditProfileInfoResponse + { + FirstName = user.FirstName, + LastName = user.LastName, + Email = user.Email, + UserName = user.UserName + }; + } } \ No newline at end of file diff --git a/src/Application/Mappers/TransactionMapper.cs b/src/Application/Mappers/TransactionMapper.cs index f9d0c22..0a27a6d 100644 --- a/src/Application/Mappers/TransactionMapper.cs +++ b/src/Application/Mappers/TransactionMapper.cs @@ -1,24 +1,24 @@ -using Web.DTOs.Transaction; -using Domain.Entities; - -namespace Application.Mappers -{ - public static class TransactionMapper - { - public static GetAllTransactionsResponse ToGetAllTransactionsResponse(this List transactions) - { - return new GetAllTransactionsResponse - { - Transactions = transactions.Select(transaction => new GetAllTransactionsResponse.TransactionDto - { - TransactionId = transaction.TransactionId, - SourceAccountId = transaction.SourceAccountId, - DestinationAccountId = transaction.DestinationAccountId, - Amount = transaction.Amount, - Date = transaction.Date, - Type = transaction.Type - }).ToList() - }; - } - } +using Web.DTOs.Transaction; +using Domain.Entities; + +namespace Application.Mappers +{ + public static class TransactionMapper + { + public static GetAllTransactionsResponse ToGetAllTransactionsResponse(this List transactions) + { + return new GetAllTransactionsResponse + { + Transactions = transactions.Select(transaction => new GetAllTransactionsResponse.TransactionDto + { + TransactionId = transaction.TransactionId, + SourceAccountId = transaction.SourceAccountId, + DestinationAccountId = transaction.DestinationAccountId, + Amount = transaction.Amount, + Date = transaction.Date, + Type = transaction.Type + }).ToList() + }; + } + } } \ No newline at end of file diff --git a/src/Application/Services/AccountService.cs b/src/Application/Services/AccountService.cs index 27f70f8..c75e89c 100644 --- a/src/Application/Services/AccountService.cs +++ b/src/Application/Services/AccountService.cs @@ -1,57 +1,57 @@ -using Application.DTOs; -using Application.DTOs.AccountCsv; -using Application.Interfaces; -using Application.Interfaces.Services; -using Application.Services.SharedService; -using Domain.Entities; - -namespace Application.Services; - -public class AccountService : IAccountService -{ - private readonly IAccountRepository _accountRepository; - - public AccountService(IAccountRepository accountRepository) - { - _accountRepository = accountRepository; - } - - public async Task AddAccountsFromCsvAsync(string filePath) - { - var accountCsvModels = CsvReaderService.ReadFromCsv(filePath); - - var accounts = accountCsvModels.Select(csvModel => new Account - { - AccountId = csvModel.AccountID, - CardId = csvModel.CardID, - Iban = csvModel.IBAN, - AccountType = csvModel.AccountType, - BranchTelephone = csvModel.BranchTelephone, - BranchAddress = csvModel.BranchAdress, - BranchName = csvModel.BranchName, - OwnerName = csvModel.OwnerName, - OwnerLastName = csvModel.OwnerLastName, - OwnerId = csvModel.OwnerID - }).ToList(); - - await _accountRepository.CreateBulkAsync(accounts); - } - - public async Task GetAccountByIdAsync(long accountId) - { - return await _accountRepository.GetByIdAsync(accountId); - } - - public async Task>> GetTransactionsByUserId(long accountId) - { - var account = await _accountRepository.GetByIdAsync(accountId); - - if (account == null) - { - return Result>.Fail("Account not found"); - } - - var transactions = await _accountRepository.GetTransactionsByAccountId(accountId); - return Result>.Ok(transactions); - } +using Application.DTOs; +using Application.DTOs.AccountCsv; +using Application.Interfaces; +using Application.Interfaces.Services; +using Application.Services.SharedService; +using Domain.Entities; + +namespace Application.Services; + +public class AccountService : IAccountService +{ + private readonly IAccountRepository _accountRepository; + + public AccountService(IAccountRepository accountRepository) + { + _accountRepository = accountRepository; + } + + public async Task AddAccountsFromCsvAsync(string filePath) + { + var accountCsvModels = CsvReaderService.ReadFromCsv(filePath); + + var accounts = accountCsvModels.Select(csvModel => new Account + { + AccountId = csvModel.AccountID, + CardId = csvModel.CardID, + Iban = csvModel.IBAN, + AccountType = csvModel.AccountType, + BranchTelephone = csvModel.BranchTelephone, + BranchAddress = csvModel.BranchAdress, + BranchName = csvModel.BranchName, + OwnerName = csvModel.OwnerName, + OwnerLastName = csvModel.OwnerLastName, + OwnerId = csvModel.OwnerID + }).ToList(); + + await _accountRepository.CreateBulkAsync(accounts); + } + + public async Task GetAccountByIdAsync(long accountId) + { + return await _accountRepository.GetByIdAsync(accountId); + } + + public async Task>> GetTransactionsByUserId(long accountId) + { + var account = await _accountRepository.GetByIdAsync(accountId); + + if (account == null) + { + return Result>.Fail("Account not found"); + } + + var transactions = await _accountRepository.GetTransactionsByAccountId(accountId); + return Result>.Ok(transactions); + } } \ No newline at end of file diff --git a/src/Application/Services/IdentityService.cs b/src/Application/Services/IdentityService.cs index 696050c..6343a00 100644 --- a/src/Application/Services/IdentityService.cs +++ b/src/Application/Services/IdentityService.cs @@ -1,94 +1,94 @@ -using Application.DTOs; -using Application.DTOs.Identity; -using Application.DTOs.Identity.ChangeRole; -using Application.ExtensionMethods; -using Application.Interfaces; -using Application.Interfaces.Services; -using Application.Mappers; -using Domain.Entities; -using Web.Interfaces; - -namespace Application.Services; - -public class IdentityService : IIdentityService -{ - private readonly IUserManager _userManager; - private readonly IRoleManager _roleManager; - private readonly IJwtGenerator _jwtGenerator; - public IdentityService(IUserManager userManager, - IRoleManager roleManager, - IJwtGenerator jwtGenerator) - { - _userManager = userManager; - _roleManager = roleManager; - _jwtGenerator = jwtGenerator; - } - - public async Task> SignUpUser(CreateUserRequest createUserRequest) - { - if (!await _roleManager.RoleExistsAsync(createUserRequest.Role)) - { - return Result.Fail("role does not exist"); - } - - var appUser = createUserRequest.ToAppUser(); - - var appUserResult = await _userManager.CreateAsync(appUser, createUserRequest.Password); - if (!appUserResult.Succeeded) - { - return Result.Fail(appUserResult.Errors.FirstMessage()); - } - - var roleResult = await _userManager.SetRoleAsync(appUser, createUserRequest.Role); - if (!roleResult.Succeeded) - { - return Result.Fail(roleResult.Errors.FirstMessage()); - } - - return Result.Ok(appUser.ToCreateUserResponse(createUserRequest.Role)); - } - - public async Task> Login(LoginUserRequest loginUserRequest) - { - AppUser? appUser; - - if (!string.IsNullOrEmpty(loginUserRequest.UserName)) - { - appUser = await _userManager.FindByNameAsync(loginUserRequest.UserName); - } - else if (!string.IsNullOrEmpty(loginUserRequest.Email)) - { - appUser = await _userManager.FindByEmailAsync(loginUserRequest.Email); - } - else - { - return Result.Fail("You should enter email or username!"); - } - - if (appUser is null) return Result.Fail("Invalid username/email!"); - - var succeed = await _userManager.CheckPasswordAsync(appUser, loginUserRequest.Password); - - if (!succeed) return Result.Fail("Username/Email not found and/or password incorrect"); - - var role = await _userManager.GetRoleAsync(appUser); - var token = _jwtGenerator.GenerateToken(appUser, role); - - return Result.Ok(appUser.ToLoginUserResponse(role, token)); - } - - public async Task ChangeRole(ChangeRoleRequest request) - { - if (!await _roleManager.RoleExistsAsync(request.Role)) - { - return Result.Fail("role does not exist"); - } - AppUser? appUser = await _userManager.FindByNameAsync(request.UserName); - - if (appUser is null) return Result.Fail("Invalid username"); - - var result = await _userManager.ChangeRoleAsync(appUser, request.Role); - - return result.Succeeded ? Result.Ok() : Result.Fail(result.Errors.FirstMessage()); - } +using Application.DTOs; +using Application.DTOs.Identity; +using Application.DTOs.Identity.ChangeRole; +using Application.ExtensionMethods; +using Application.Interfaces; +using Application.Interfaces.Services; +using Application.Mappers; +using Domain.Entities; +using Web.Interfaces; + +namespace Application.Services; + +public class IdentityService : IIdentityService +{ + private readonly IUserManager _userManager; + private readonly IRoleManager _roleManager; + private readonly IJwtGenerator _jwtGenerator; + public IdentityService(IUserManager userManager, + IRoleManager roleManager, + IJwtGenerator jwtGenerator) + { + _userManager = userManager; + _roleManager = roleManager; + _jwtGenerator = jwtGenerator; + } + + public async Task> SignUpUser(CreateUserRequest createUserRequest) + { + if (!await _roleManager.RoleExistsAsync(createUserRequest.Role)) + { + return Result.Fail("role does not exist"); + } + + var appUser = createUserRequest.ToAppUser(); + + var appUserResult = await _userManager.CreateAsync(appUser, createUserRequest.Password); + if (!appUserResult.Succeeded) + { + return Result.Fail(appUserResult.Errors.FirstMessage()); + } + + var roleResult = await _userManager.SetRoleAsync(appUser, createUserRequest.Role); + if (!roleResult.Succeeded) + { + return Result.Fail(roleResult.Errors.FirstMessage()); + } + + return Result.Ok(appUser.ToCreateUserResponse(createUserRequest.Role)); + } + + public async Task> Login(LoginUserRequest loginUserRequest) + { + AppUser? appUser; + + if (!string.IsNullOrEmpty(loginUserRequest.UserName)) + { + appUser = await _userManager.FindByNameAsync(loginUserRequest.UserName); + } + else if (!string.IsNullOrEmpty(loginUserRequest.Email)) + { + appUser = await _userManager.FindByEmailAsync(loginUserRequest.Email); + } + else + { + return Result.Fail("You should enter email or username!"); + } + + if (appUser is null) return Result.Fail("Invalid username/email!"); + + var succeed = await _userManager.CheckPasswordAsync(appUser, loginUserRequest.Password); + + if (!succeed) return Result.Fail("Username/Email not found and/or password incorrect"); + + var role = await _userManager.GetRoleAsync(appUser); + var token = _jwtGenerator.GenerateToken(appUser, role); + + return Result.Ok(appUser.ToLoginUserResponse(role, token)); + } + + public async Task ChangeRole(ChangeRoleRequest request) + { + if (!await _roleManager.RoleExistsAsync(request.Role)) + { + return Result.Fail("role does not exist"); + } + AppUser? appUser = await _userManager.FindByNameAsync(request.UserName); + + if (appUser is null) return Result.Fail("Invalid username"); + + var result = await _userManager.ChangeRoleAsync(appUser, request.Role); + + return result.Succeeded ? Result.Ok() : Result.Fail(result.Errors.FirstMessage()); + } } \ No newline at end of file diff --git a/src/Application/Services/ProfileService.cs b/src/Application/Services/ProfileService.cs index 6c036e7..3bd8ce0 100644 --- a/src/Application/Services/ProfileService.cs +++ b/src/Application/Services/ProfileService.cs @@ -1,74 +1,74 @@ -using Application.DTOs; -using Application.DTOs.Identity; -using Application.DTOs.Profile.ChangePassword; -using Application.ExtensionMethods; -using Application.Interfaces; -using Application.Interfaces.Services; -using Application.Mappers; - -namespace Application.Services; - -public class ProfileService : IProfileService -{ - private readonly IUserManager _userManager; - - public ProfileService(IUserManager userManager) - { - _userManager = userManager; - } - - public async Task> EditProfileInfo(EditProfileInfoRequest infoRequest) - { - var user = await _userManager.FindByIdAsync(infoRequest.UserId); - if (user == null) - return Result.Fail("User not found!"); - - - if (user.UserName != infoRequest.UserName) - { - var existingUser = await _userManager.FindByNameAsync(infoRequest.UserName); - if (existingUser != null) - return Result.Fail("Username is already reserved by another user!"); - } - - user.UserName = infoRequest.UserName; - user.FirstName = infoRequest.FirstName; - user.LastName = infoRequest.LastName; - - var updateResult = await _userManager.UpdateAsync(user); - if (!updateResult.Succeeded) - return Result.Fail(updateResult.Errors.FirstMessage()); - - - return Result.Ok(user.ToEditProfileInfoResponse()); - } - - public async Task> GetProfileInfo(GetProfileInfoRequest getProfileInfoRequest) - { - var user = await _userManager.FindByIdAsync(getProfileInfoRequest.UserId); - - if (user == null) - return Result.Fail("User not found!"); - - var role = await _userManager.GetRoleAsync(user); - - return Result.Ok(user.ToGetProfileInfoResponse(role)); - } - - public async Task ChangePassword(ChangePasswordRequest request) - { - var user = await _userManager.FindByIdAsync(request.UserId); - if (user == null) - return Result.Fail("User not found!"); - - var isPasswordCorrect = await _userManager.CheckPasswordAsync(user, request.CurrentPassword); - if (!isPasswordCorrect) - return Result.Fail("Incorrect current password!"); - - var passwordChangeResult = await _userManager.ChangePasswordAsync(user, request.CurrentPassword, request.NewPassword); - if (!passwordChangeResult.Succeeded) - return Result.Fail(passwordChangeResult.Errors.FirstMessage()); - - return Result.Ok(); - } +using Application.DTOs; +using Application.DTOs.Identity; +using Application.DTOs.Profile.ChangePassword; +using Application.ExtensionMethods; +using Application.Interfaces; +using Application.Interfaces.Services; +using Application.Mappers; + +namespace Application.Services; + +public class ProfileService : IProfileService +{ + private readonly IUserManager _userManager; + + public ProfileService(IUserManager userManager) + { + _userManager = userManager; + } + + public async Task> EditProfileInfo(EditProfileInfoRequest infoRequest) + { + var user = await _userManager.FindByIdAsync(infoRequest.UserId); + if (user == null) + return Result.Fail("User not found!"); + + + if (user.UserName != infoRequest.UserName) + { + var existingUser = await _userManager.FindByNameAsync(infoRequest.UserName); + if (existingUser != null) + return Result.Fail("Username is already reserved by another user!"); + } + + user.UserName = infoRequest.UserName; + user.FirstName = infoRequest.FirstName; + user.LastName = infoRequest.LastName; + + var updateResult = await _userManager.UpdateAsync(user); + if (!updateResult.Succeeded) + return Result.Fail(updateResult.Errors.FirstMessage()); + + + return Result.Ok(user.ToEditProfileInfoResponse()); + } + + public async Task> GetProfileInfo(GetProfileInfoRequest getProfileInfoRequest) + { + var user = await _userManager.FindByIdAsync(getProfileInfoRequest.UserId); + + if (user == null) + return Result.Fail("User not found!"); + + var role = await _userManager.GetRoleAsync(user); + + return Result.Ok(user.ToGetProfileInfoResponse(role)); + } + + public async Task ChangePassword(ChangePasswordRequest request) + { + var user = await _userManager.FindByIdAsync(request.UserId); + if (user == null) + return Result.Fail("User not found!"); + + var isPasswordCorrect = await _userManager.CheckPasswordAsync(user, request.CurrentPassword); + if (!isPasswordCorrect) + return Result.Fail("Incorrect current password!"); + + var passwordChangeResult = await _userManager.ChangePasswordAsync(user, request.CurrentPassword, request.NewPassword); + if (!passwordChangeResult.Succeeded) + return Result.Fail(passwordChangeResult.Errors.FirstMessage()); + + return Result.Ok(); + } } \ No newline at end of file diff --git a/src/Application/Services/SharedService/CsvReaderService.cs b/src/Application/Services/SharedService/CsvReaderService.cs index 53d2424..6217f9d 100644 --- a/src/Application/Services/SharedService/CsvReaderService.cs +++ b/src/Application/Services/SharedService/CsvReaderService.cs @@ -1,22 +1,22 @@ -using System.Globalization; -using Application.DTOs.TransactionCsv; -using CsvHelper; -using CsvHelper.Configuration; - -namespace Application.Services.SharedService; - -public static class CsvReaderService -{ - public static List ReadFromCsv(string filePath) - { - using var reader = new StreamReader(filePath); - using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture) - { - HeaderValidated = null, - MissingFieldFound = null - }); - - var records = csv.GetRecords().ToList(); - return records; - } +using System.Globalization; +using Application.DTOs.TransactionCsv; +using CsvHelper; +using CsvHelper.Configuration; + +namespace Application.Services.SharedService; + +public static class CsvReaderService +{ + public static List ReadFromCsv(string filePath) + { + using var reader = new StreamReader(filePath); + using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture) + { + HeaderValidated = null, + MissingFieldFound = null + }); + + var records = csv.GetRecords().ToList(); + return records; + } } \ No newline at end of file diff --git a/src/Application/Services/SharedService/PersianDateConverter.cs b/src/Application/Services/SharedService/PersianDateConverter.cs index e571925..efd626f 100644 --- a/src/Application/Services/SharedService/PersianDateConverter.cs +++ b/src/Application/Services/SharedService/PersianDateConverter.cs @@ -1,34 +1,34 @@ -using System.Globalization; -using CsvHelper; -using CsvHelper.Configuration; -using CsvHelper.TypeConversion; - -namespace Application.Services.SharedService; - -public class PersianDateConverter : DateTimeConverter -{ - public override object ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData) - { - if (string.IsNullOrWhiteSpace(text)) - { - return DateTime.MinValue; - } - - try - { - var persianCalendar = new PersianCalendar(); - var parts = text.Split('/'); - - var year = int.Parse(parts[0]); - var month = int.Parse(parts[1]); - var day = int.Parse(parts[2]); - - var gregorianDate = persianCalendar.ToDateTime(year, month, day, 0, 0, 0, 0); - return DateTime.SpecifyKind(gregorianDate, DateTimeKind.Utc); - } - catch (Exception ex) - { - throw new TypeConverterException(this, memberMapData, text, row.Context, ex.Message); - } - } +using System.Globalization; +using CsvHelper; +using CsvHelper.Configuration; +using CsvHelper.TypeConversion; + +namespace Application.Services.SharedService; + +public class PersianDateConverter : DateTimeConverter +{ + public override object ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData) + { + if (string.IsNullOrWhiteSpace(text)) + { + return DateTime.MinValue; + } + + try + { + var persianCalendar = new PersianCalendar(); + var parts = text.Split('/'); + + var year = int.Parse(parts[0]); + var month = int.Parse(parts[1]); + var day = int.Parse(parts[2]); + + var gregorianDate = persianCalendar.ToDateTime(year, month, day, 0, 0, 0, 0); + return DateTime.SpecifyKind(gregorianDate, DateTimeKind.Utc); + } + catch (Exception ex) + { + throw new TypeConverterException(this, memberMapData, text, row.Context, ex.Message); + } + } } \ No newline at end of file diff --git a/src/Application/Services/TransactionService.cs b/src/Application/Services/TransactionService.cs index 5b5b9af..378e859 100644 --- a/src/Application/Services/TransactionService.cs +++ b/src/Application/Services/TransactionService.cs @@ -1,56 +1,56 @@ -using Application.DTOs; -using Application.DTOs.TransactionCsv; -using Application.Interfaces; -using Application.Interfaces.Services; -using Application.Mappers; -using Application.Services.SharedService; -using Domain.Entities; -using Web.DTOs.Transaction; - -namespace Application.Services; - -public class TransactionService : ITransactionService -{ - private readonly ITransactionRepository _transactionRepository; - - public TransactionService(ITransactionRepository transactionRepository) - { - _transactionRepository = transactionRepository; - } - - public async Task AddTransactionsFromCsvAsync(string filePath) - { - var transactionCsvModels = CsvReaderService.ReadFromCsv(filePath); - - var transactions = transactionCsvModels.Select(csvModel => new Transaction - { - TransactionId = csvModel.TransactionID, - SourceAccountId = csvModel.SourceAcount, - DestinationAccountId = csvModel.DestiantionAccount, - Amount = csvModel.Amount, - Date = csvModel.Date, - Type = csvModel.Type - }).ToList(); - - await _transactionRepository.CreateBulkAsync(transactions); - } - - public async Task> GetAllTransactions() - { - try - { - var transactions = await _transactionRepository.GetAllTransactions(); - - if (transactions.Count == 0) - { - return Result.Fail("No transactions found"); - } - var response = transactions.ToGetAllTransactionsResponse(); - return Result.Ok(response); - } - catch (Exception ex) - { - return Result.Fail($"An error occurred: {ex.Message}"); - } - } +using Application.DTOs; +using Application.DTOs.TransactionCsv; +using Application.Interfaces; +using Application.Interfaces.Services; +using Application.Mappers; +using Application.Services.SharedService; +using Domain.Entities; +using Web.DTOs.Transaction; + +namespace Application.Services; + +public class TransactionService : ITransactionService +{ + private readonly ITransactionRepository _transactionRepository; + + public TransactionService(ITransactionRepository transactionRepository) + { + _transactionRepository = transactionRepository; + } + + public async Task AddTransactionsFromCsvAsync(string filePath) + { + var transactionCsvModels = CsvReaderService.ReadFromCsv(filePath); + + var transactions = transactionCsvModels.Select(csvModel => new Transaction + { + TransactionId = csvModel.TransactionID, + SourceAccountId = csvModel.SourceAcount, + DestinationAccountId = csvModel.DestiantionAccount, + Amount = csvModel.Amount, + Date = csvModel.Date, + Type = csvModel.Type + }).ToList(); + + await _transactionRepository.CreateBulkAsync(transactions); + } + + public async Task> GetAllTransactions() + { + try + { + var transactions = await _transactionRepository.GetAllTransactions(); + + if (transactions.Count == 0) + { + return Result.Fail("No transactions found"); + } + var response = transactions.ToGetAllTransactionsResponse(); + return Result.Ok(response); + } + catch (Exception ex) + { + return Result.Fail($"An error occurred: {ex.Message}"); + } + } } \ No newline at end of file diff --git a/src/Domain/Constants/AppRoles.cs b/src/Domain/Constants/AppRoles.cs index 51fbebd..a341724 100644 --- a/src/Domain/Constants/AppRoles.cs +++ b/src/Domain/Constants/AppRoles.cs @@ -1,8 +1,8 @@ -namespace Domain.Constants; - -public static class AppRoles -{ - public const string Admin = nameof(Admin); - public const string DataAdmin = nameof(DataAdmin); - public const string DataAnalyst = nameof(DataAnalyst); +namespace Domain.Constants; + +public static class AppRoles +{ + public const string Admin = nameof(Admin); + public const string DataAdmin = nameof(DataAdmin); + public const string DataAnalyst = nameof(DataAnalyst); } \ No newline at end of file diff --git a/src/Domain/Domain.csproj b/src/Domain/Domain.csproj index a65825f..9319e71 100644 --- a/src/Domain/Domain.csproj +++ b/src/Domain/Domain.csproj @@ -1,13 +1,13 @@ - - - - net8.0 - enable - enable - - - - - - - + + + + net8.0 + enable + enable + + + + + + + diff --git a/src/Domain/Entities/Account.cs b/src/Domain/Entities/Account.cs index 40a3b89..fa0b376 100644 --- a/src/Domain/Entities/Account.cs +++ b/src/Domain/Entities/Account.cs @@ -1,20 +1,20 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace Domain.Entities; -[Table("Accounts")] -public class Account -{ - public long AccountId { get; set; } - public long CardId { get; set; } - public string Iban { get; set; } = String.Empty; - public string AccountType { get; set; } = String.Empty; - public string BranchTelephone { get; set; } = String.Empty; - public string BranchAddress { get; set; } = String.Empty; - public string BranchName { get; set; } = String.Empty; - public string OwnerName { get; set; } = String.Empty; - public string OwnerLastName { get; set; } = String.Empty; - public string OwnerId { get; set; } = String.Empty; - - public List SourceTransactions { get; set; } = new(); - public List DestinationTransactions { get; set; } = new(); +using System.ComponentModel.DataAnnotations.Schema; + +namespace Domain.Entities; +[Table("Accounts")] +public class Account +{ + public long AccountId { get; set; } + public long CardId { get; set; } + public string Iban { get; set; } = String.Empty; + public string AccountType { get; set; } = String.Empty; + public string BranchTelephone { get; set; } = String.Empty; + public string BranchAddress { get; set; } = String.Empty; + public string BranchName { get; set; } = String.Empty; + public string OwnerName { get; set; } = String.Empty; + public string OwnerLastName { get; set; } = String.Empty; + public string OwnerId { get; set; } = String.Empty; + + public List SourceTransactions { get; set; } = new(); + public List DestinationTransactions { get; set; } = new(); } \ No newline at end of file diff --git a/src/Domain/Entities/AppUser.cs b/src/Domain/Entities/AppUser.cs index c41129a..f236d5b 100644 --- a/src/Domain/Entities/AppUser.cs +++ b/src/Domain/Entities/AppUser.cs @@ -1,11 +1,11 @@ -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Identity; - -namespace Domain.Entities; -public class AppUser : IdentityUser -{ - [MaxLength(50)] - public string FirstName { get; set; } = String.Empty; - [MaxLength(50)] - public string LastName { get; set; } = String.Empty; +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Identity; + +namespace Domain.Entities; +public class AppUser : IdentityUser +{ + [MaxLength(50)] + public string FirstName { get; set; } = String.Empty; + [MaxLength(50)] + public string LastName { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Domain/Entities/Transaction.cs b/src/Domain/Entities/Transaction.cs index 1a47fbd..831e247 100644 --- a/src/Domain/Entities/Transaction.cs +++ b/src/Domain/Entities/Transaction.cs @@ -1,15 +1,15 @@ -using System.ComponentModel.DataAnnotations.Schema; - -namespace Domain.Entities; -[Table("Transactions")] -public class Transaction -{ - public long TransactionId { get; set; } - public long SourceAccountId { get; set; } - public Account SourceAccount { get; set; } - public long DestinationAccountId { get; set; } - public Account DestinationAccount { get; set; } - public decimal Amount { get; set; } - public DateTime Date { get; set; } - public string Type { get; set; } = String.Empty; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Domain.Entities; +[Table("Transactions")] +public class Transaction +{ + public long TransactionId { get; set; } + public long SourceAccountId { get; set; } + public Account SourceAccount { get; set; } + public long DestinationAccountId { get; set; } + public Account DestinationAccount { get; set; } + public decimal Amount { get; set; } + public DateTime Date { get; set; } + public string Type { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Infrastructure/Data/ApplicationDbContext.cs b/src/Infrastructure/Data/ApplicationDbContext.cs index 47d9d8e..977cdf6 100644 --- a/src/Infrastructure/Data/ApplicationDbContext.cs +++ b/src/Infrastructure/Data/ApplicationDbContext.cs @@ -1,38 +1,38 @@ -using Domain.Constants; -using Domain.Entities; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; - -namespace Infrastructure.Data; - -public class ApplicationDbContext(DbContextOptions dbContextOptions) - : IdentityDbContext(dbContextOptions) -{ - public DbSet Accounts { get; set; } - public DbSet Transactions { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - - List roles = - [ - new IdentityRole { Name = AppRoles.Admin, NormalizedName = AppRoles.Admin.ToUpper()}, - new IdentityRole { Name = AppRoles.DataAdmin, NormalizedName = AppRoles.DataAdmin.ToUpper()}, - new IdentityRole { Name = AppRoles.DataAnalyst, NormalizedName = AppRoles.DataAnalyst.ToUpper()} - ]; - modelBuilder.Entity().HasData(roles); - - modelBuilder.Entity() - .HasOne(t => t.SourceAccount) - .WithMany(a => a.SourceTransactions) - .HasForeignKey(t => t.SourceAccountId) - .OnDelete(DeleteBehavior.Restrict); - - modelBuilder.Entity() - .HasOne(t => t.DestinationAccount) - .WithMany(a => a.DestinationTransactions) - .HasForeignKey(t => t.DestinationAccountId) - .OnDelete(DeleteBehavior.Restrict); - } +using Domain.Constants; +using Domain.Entities; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace Infrastructure.Data; + +public class ApplicationDbContext(DbContextOptions dbContextOptions) + : IdentityDbContext(dbContextOptions) +{ + public DbSet Accounts { get; set; } + public DbSet Transactions { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + List roles = + [ + new IdentityRole { Name = AppRoles.Admin, NormalizedName = AppRoles.Admin.ToUpper()}, + new IdentityRole { Name = AppRoles.DataAdmin, NormalizedName = AppRoles.DataAdmin.ToUpper()}, + new IdentityRole { Name = AppRoles.DataAnalyst, NormalizedName = AppRoles.DataAnalyst.ToUpper()} + ]; + modelBuilder.Entity().HasData(roles); + + modelBuilder.Entity() + .HasOne(t => t.SourceAccount) + .WithMany(a => a.SourceTransactions) + .HasForeignKey(t => t.SourceAccountId) + .OnDelete(DeleteBehavior.Restrict); + + modelBuilder.Entity() + .HasOne(t => t.DestinationAccount) + .WithMany(a => a.DestinationTransactions) + .HasForeignKey(t => t.DestinationAccountId) + .OnDelete(DeleteBehavior.Restrict); + } } \ No newline at end of file diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index b44da95..87ab8bd 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -1,30 +1,30 @@ - - - - net8.0 - enable - enable - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.7\Microsoft.AspNetCore.Identity.dll - - - - + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.7\Microsoft.AspNetCore.Identity.dll + + + + diff --git a/src/Infrastructure/Migrations/20240814092051_CompleteUser.Designer.cs b/src/Infrastructure/Migrations/20240814092051_CompleteUser.Designer.cs index 9713e1c..8ad4fdf 100644 --- a/src/Infrastructure/Migrations/20240814092051_CompleteUser.Designer.cs +++ b/src/Infrastructure/Migrations/20240814092051_CompleteUser.Designer.cs @@ -1,307 +1,307 @@ -// -using System; -using Infrastructure.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 Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20240814092051_CompleteUser")] - partial class CompleteUser - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Infrastructure.Entities.AppUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "502db14d-ec3d-42f2-a56c-c14ad1217dda", - Name = "Admin", - NormalizedName = "ADMIN" - }, - new - { - Id = "1d283a73-9ec4-4897-a709-2f21f1347cd6", - Name = "DataAdmin", - NormalizedName = "DATAADMIN" - }, - new - { - Id = "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc", - Name = "DataAnalyst", - NormalizedName = "DATAANALYST" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Infrastructure.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Infrastructure.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Infrastructure.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Infrastructure.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Infrastructure.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 Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240814092051_CompleteUser")] + partial class CompleteUser + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Infrastructure.Entities.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "502db14d-ec3d-42f2-a56c-c14ad1217dda", + Name = "Admin", + NormalizedName = "ADMIN" + }, + new + { + Id = "1d283a73-9ec4-4897-a709-2f21f1347cd6", + Name = "DataAdmin", + NormalizedName = "DATAADMIN" + }, + new + { + Id = "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc", + Name = "DataAnalyst", + NormalizedName = "DATAANALYST" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Infrastructure.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Infrastructure.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Infrastructure.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Infrastructure.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Migrations/20240814092051_CompleteUser.cs b/src/Infrastructure/Migrations/20240814092051_CompleteUser.cs index d914d01..e57b5ed 100644 --- a/src/Infrastructure/Migrations/20240814092051_CompleteUser.cs +++ b/src/Infrastructure/Migrations/20240814092051_CompleteUser.cs @@ -1,237 +1,237 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace Infrastructure.Migrations -{ - /// - public partial class CompleteUser : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - FirstName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - LastName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "boolean", nullable: false), - PasswordHash = table.Column(type: "text", nullable: true), - SecurityStamp = table.Column(type: "text", nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true), - PhoneNumber = table.Column(type: "text", nullable: true), - PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), - TwoFactorEnabled = table.Column(type: "boolean", nullable: false), - LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), - LockoutEnabled = table.Column(type: "boolean", nullable: false), - AccessFailedCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "text", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "text", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "text", nullable: false), - ProviderKey = table.Column(type: "text", nullable: false), - ProviderDisplayName = table.Column(type: "text", nullable: true), - UserId = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "text", nullable: false), - RoleId = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "text", nullable: false), - LoginProvider = table.Column(type: "text", nullable: false), - Name = table.Column(type: "text", nullable: false), - Value = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc", null, "DataAnalyst", "DATAANALYST" }, - { "1d283a73-9ec4-4897-a709-2f21f1347cd6", null, "DataAdmin", "DATAADMIN" }, - { "502db14d-ec3d-42f2-a56c-c14ad1217dda", null, "Admin", "ADMIN" } - }); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - } - } -} +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Infrastructure.Migrations +{ + /// + public partial class CompleteUser : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "text", nullable: false), + FirstName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + LastName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "text", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + RoleId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(type: "text", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc", null, "DataAnalyst", "DATAANALYST" }, + { "1d283a73-9ec4-4897-a709-2f21f1347cd6", null, "DataAdmin", "DATAADMIN" }, + { "502db14d-ec3d-42f2-a56c-c14ad1217dda", null, "Admin", "ADMIN" } + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.Designer.cs b/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.Designer.cs index e9fb4b7..144d9e4 100644 --- a/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.Designer.cs +++ b/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.Designer.cs @@ -1,414 +1,414 @@ -// -using System; -using Infrastructure.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 Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20240817193825_Accounts-Transactions")] - partial class AccountsTransactions - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Domain.Entities.Account", b => - { - b.Property("AccountId") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AccountId")); - - b.Property("AccountType") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchAddress") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchName") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchTelephone") - .IsRequired() - .HasColumnType("text"); - - b.Property("CardId") - .HasColumnType("integer"); - - b.Property("Iban") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerId") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerLastName") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerName") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("AccountId"); - - b.ToTable("Accounts"); - }); - - modelBuilder.Entity("Domain.Entities.AppUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Domain.Entities.Transaction", b => - { - b.Property("TransactionId") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TransactionId")); - - b.Property("Amount") - .HasColumnType("numeric"); - - b.Property("Date") - .HasColumnType("timestamp with time zone"); - - b.Property("DestinationAccountId") - .HasColumnType("integer"); - - b.Property("SourceAccountId") - .HasColumnType("integer"); - - b.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("TransactionId"); - - b.HasIndex("DestinationAccountId"); - - b.HasIndex("SourceAccountId"); - - b.ToTable("Transactions"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "0a8ca877-f408-4d10-806f-1714e41b0186", - Name = "Admin", - NormalizedName = "ADMIN" - }, - new - { - Id = "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b", - Name = "DataAdmin", - NormalizedName = "DATAADMIN" - }, - new - { - Id = "913a4192-89c6-4d8e-873c-52d9695f8d59", - Name = "DataAnalyst", - NormalizedName = "DATAANALYST" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Domain.Entities.Transaction", b => - { - b.HasOne("Domain.Entities.Account", "DestinationAccount") - .WithMany("DestinationTransactions") - .HasForeignKey("DestinationAccountId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Domain.Entities.Account", "SourceAccount") - .WithMany("SourceTransactions") - .HasForeignKey("SourceAccountId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("DestinationAccount"); - - b.Navigation("SourceAccount"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Domain.Entities.Account", b => - { - b.Navigation("DestinationTransactions"); - - b.Navigation("SourceTransactions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Infrastructure.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 Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240817193825_Accounts-Transactions")] + partial class AccountsTransactions + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Domain.Entities.Account", b => + { + b.Property("AccountId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AccountId")); + + b.Property("AccountType") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchTelephone") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardId") + .HasColumnType("integer"); + + b.Property("Iban") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerId") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerLastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("AccountId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("Domain.Entities.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Transaction", b => + { + b.Property("TransactionId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TransactionId")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DestinationAccountId") + .HasColumnType("integer"); + + b.Property("SourceAccountId") + .HasColumnType("integer"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("TransactionId"); + + b.HasIndex("DestinationAccountId"); + + b.HasIndex("SourceAccountId"); + + b.ToTable("Transactions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "0a8ca877-f408-4d10-806f-1714e41b0186", + Name = "Admin", + NormalizedName = "ADMIN" + }, + new + { + Id = "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b", + Name = "DataAdmin", + NormalizedName = "DATAADMIN" + }, + new + { + Id = "913a4192-89c6-4d8e-873c-52d9695f8d59", + Name = "DataAnalyst", + NormalizedName = "DATAANALYST" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Transaction", b => + { + b.HasOne("Domain.Entities.Account", "DestinationAccount") + .WithMany("DestinationTransactions") + .HasForeignKey("DestinationAccountId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Domain.Entities.Account", "SourceAccount") + .WithMany("SourceTransactions") + .HasForeignKey("SourceAccountId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("DestinationAccount"); + + b.Navigation("SourceAccount"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.Account", b => + { + b.Navigation("DestinationTransactions"); + + b.Navigation("SourceTransactions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.cs b/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.cs index 71753e8..b2e7c6b 100644 --- a/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.cs +++ b/src/Infrastructure/Migrations/20240817193825_Accounts-Transactions.cs @@ -1,138 +1,138 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace Infrastructure.Migrations -{ - /// - public partial class AccountsTransactions : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "1d283a73-9ec4-4897-a709-2f21f1347cd6"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "502db14d-ec3d-42f2-a56c-c14ad1217dda"); - - migrationBuilder.CreateTable( - name: "Accounts", - columns: table => new - { - AccountId = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - CardId = table.Column(type: "integer", nullable: false), - Iban = table.Column(type: "text", nullable: false), - AccountType = table.Column(type: "text", nullable: false), - BranchTelephone = table.Column(type: "text", nullable: false), - BranchAddress = table.Column(type: "text", nullable: false), - BranchName = table.Column(type: "text", nullable: false), - OwnerName = table.Column(type: "text", nullable: false), - OwnerLastName = table.Column(type: "text", nullable: false), - OwnerId = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Accounts", x => x.AccountId); - }); - - migrationBuilder.CreateTable( - name: "Transactions", - columns: table => new - { - TransactionId = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - SourceAccountId = table.Column(type: "integer", nullable: false), - DestinationAccountId = table.Column(type: "integer", nullable: false), - Amount = table.Column(type: "numeric", nullable: false), - Date = table.Column(type: "timestamp with time zone", nullable: false), - Type = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Transactions", x => x.TransactionId); - table.ForeignKey( - name: "FK_Transactions_Accounts_DestinationAccountId", - column: x => x.DestinationAccountId, - principalTable: "Accounts", - principalColumn: "AccountId", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Transactions_Accounts_SourceAccountId", - column: x => x.SourceAccountId, - principalTable: "Accounts", - principalColumn: "AccountId", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "0a8ca877-f408-4d10-806f-1714e41b0186", null, "Admin", "ADMIN" }, - { "913a4192-89c6-4d8e-873c-52d9695f8d59", null, "DataAnalyst", "DATAANALYST" }, - { "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b", null, "DataAdmin", "DATAADMIN" } - }); - - migrationBuilder.CreateIndex( - name: "IX_Transactions_DestinationAccountId", - table: "Transactions", - column: "DestinationAccountId"); - - migrationBuilder.CreateIndex( - name: "IX_Transactions_SourceAccountId", - table: "Transactions", - column: "SourceAccountId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Transactions"); - - migrationBuilder.DropTable( - name: "Accounts"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "0a8ca877-f408-4d10-806f-1714e41b0186"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "913a4192-89c6-4d8e-873c-52d9695f8d59"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b"); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc", null, "DataAnalyst", "DATAANALYST" }, - { "1d283a73-9ec4-4897-a709-2f21f1347cd6", null, "DataAdmin", "DATAADMIN" }, - { "502db14d-ec3d-42f2-a56c-c14ad1217dda", null, "Admin", "ADMIN" } - }); - } - } -} +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Infrastructure.Migrations +{ + /// + public partial class AccountsTransactions : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "1d283a73-9ec4-4897-a709-2f21f1347cd6"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "502db14d-ec3d-42f2-a56c-c14ad1217dda"); + + migrationBuilder.CreateTable( + name: "Accounts", + columns: table => new + { + AccountId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CardId = table.Column(type: "integer", nullable: false), + Iban = table.Column(type: "text", nullable: false), + AccountType = table.Column(type: "text", nullable: false), + BranchTelephone = table.Column(type: "text", nullable: false), + BranchAddress = table.Column(type: "text", nullable: false), + BranchName = table.Column(type: "text", nullable: false), + OwnerName = table.Column(type: "text", nullable: false), + OwnerLastName = table.Column(type: "text", nullable: false), + OwnerId = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Accounts", x => x.AccountId); + }); + + migrationBuilder.CreateTable( + name: "Transactions", + columns: table => new + { + TransactionId = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + SourceAccountId = table.Column(type: "integer", nullable: false), + DestinationAccountId = table.Column(type: "integer", nullable: false), + Amount = table.Column(type: "numeric", nullable: false), + Date = table.Column(type: "timestamp with time zone", nullable: false), + Type = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Transactions", x => x.TransactionId); + table.ForeignKey( + name: "FK_Transactions_Accounts_DestinationAccountId", + column: x => x.DestinationAccountId, + principalTable: "Accounts", + principalColumn: "AccountId", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Transactions_Accounts_SourceAccountId", + column: x => x.SourceAccountId, + principalTable: "Accounts", + principalColumn: "AccountId", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "0a8ca877-f408-4d10-806f-1714e41b0186", null, "Admin", "ADMIN" }, + { "913a4192-89c6-4d8e-873c-52d9695f8d59", null, "DataAnalyst", "DATAANALYST" }, + { "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b", null, "DataAdmin", "DATAADMIN" } + }); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_DestinationAccountId", + table: "Transactions", + column: "DestinationAccountId"); + + migrationBuilder.CreateIndex( + name: "IX_Transactions_SourceAccountId", + table: "Transactions", + column: "SourceAccountId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Transactions"); + + migrationBuilder.DropTable( + name: "Accounts"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "0a8ca877-f408-4d10-806f-1714e41b0186"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "913a4192-89c6-4d8e-873c-52d9695f8d59"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b"); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "15b3c37c-d76a-4b52-a53f-5ec7e65bedcc", null, "DataAnalyst", "DATAANALYST" }, + { "1d283a73-9ec4-4897-a709-2f21f1347cd6", null, "DataAdmin", "DATAADMIN" }, + { "502db14d-ec3d-42f2-a56c-c14ad1217dda", null, "Admin", "ADMIN" } + }); + } + } +} diff --git a/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.Designer.cs b/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.Designer.cs index aad3c71..f7c5d9f 100644 --- a/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.Designer.cs +++ b/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.Designer.cs @@ -1,414 +1,414 @@ -// -using System; -using Infrastructure.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 Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20240818091853_CastIdsToLong")] - partial class CastIdsToLong - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Domain.Entities.Account", b => - { - b.Property("AccountId") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AccountId")); - - b.Property("AccountType") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchAddress") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchName") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchTelephone") - .IsRequired() - .HasColumnType("text"); - - b.Property("CardId") - .HasColumnType("bigint"); - - b.Property("Iban") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerId") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerLastName") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerName") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("AccountId"); - - b.ToTable("Accounts"); - }); - - modelBuilder.Entity("Domain.Entities.AppUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Domain.Entities.Transaction", b => - { - b.Property("TransactionId") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TransactionId")); - - b.Property("Amount") - .HasColumnType("numeric"); - - b.Property("Date") - .HasColumnType("timestamp with time zone"); - - b.Property("DestinationAccountId") - .HasColumnType("bigint"); - - b.Property("SourceAccountId") - .HasColumnType("bigint"); - - b.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("TransactionId"); - - b.HasIndex("DestinationAccountId"); - - b.HasIndex("SourceAccountId"); - - b.ToTable("Transactions"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "bef465d8-3d0e-469f-8b45-5f9be9c40f66", - Name = "Admin", - NormalizedName = "ADMIN" - }, - new - { - Id = "2d28da36-33b9-4ac1-b08f-50b4dd6855d2", - Name = "DataAdmin", - NormalizedName = "DATAADMIN" - }, - new - { - Id = "021da0cb-1048-4551-9858-90c98ee66289", - Name = "DataAnalyst", - NormalizedName = "DATAANALYST" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Domain.Entities.Transaction", b => - { - b.HasOne("Domain.Entities.Account", "DestinationAccount") - .WithMany("DestinationTransactions") - .HasForeignKey("DestinationAccountId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Domain.Entities.Account", "SourceAccount") - .WithMany("SourceTransactions") - .HasForeignKey("SourceAccountId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("DestinationAccount"); - - b.Navigation("SourceAccount"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Domain.Entities.Account", b => - { - b.Navigation("DestinationTransactions"); - - b.Navigation("SourceTransactions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Infrastructure.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 Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240818091853_CastIdsToLong")] + partial class CastIdsToLong + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Domain.Entities.Account", b => + { + b.Property("AccountId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AccountId")); + + b.Property("AccountType") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchTelephone") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardId") + .HasColumnType("bigint"); + + b.Property("Iban") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerId") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerLastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("AccountId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("Domain.Entities.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Transaction", b => + { + b.Property("TransactionId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TransactionId")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DestinationAccountId") + .HasColumnType("bigint"); + + b.Property("SourceAccountId") + .HasColumnType("bigint"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("TransactionId"); + + b.HasIndex("DestinationAccountId"); + + b.HasIndex("SourceAccountId"); + + b.ToTable("Transactions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "bef465d8-3d0e-469f-8b45-5f9be9c40f66", + Name = "Admin", + NormalizedName = "ADMIN" + }, + new + { + Id = "2d28da36-33b9-4ac1-b08f-50b4dd6855d2", + Name = "DataAdmin", + NormalizedName = "DATAADMIN" + }, + new + { + Id = "021da0cb-1048-4551-9858-90c98ee66289", + Name = "DataAnalyst", + NormalizedName = "DATAANALYST" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Transaction", b => + { + b.HasOne("Domain.Entities.Account", "DestinationAccount") + .WithMany("DestinationTransactions") + .HasForeignKey("DestinationAccountId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Domain.Entities.Account", "SourceAccount") + .WithMany("SourceTransactions") + .HasForeignKey("SourceAccountId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("DestinationAccount"); + + b.Navigation("SourceAccount"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.Account", b => + { + b.Navigation("DestinationTransactions"); + + b.Navigation("SourceTransactions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.cs b/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.cs index 79da6aa..7042761 100644 --- a/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.cs +++ b/src/Infrastructure/Migrations/20240818091853_CastIdsToLong.cs @@ -1,159 +1,159 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace Infrastructure.Migrations -{ - /// - public partial class CastIdsToLong : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "0a8ca877-f408-4d10-806f-1714e41b0186"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "913a4192-89c6-4d8e-873c-52d9695f8d59"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b"); - - migrationBuilder.AlterColumn( - name: "SourceAccountId", - table: "Transactions", - type: "bigint", - nullable: false, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "DestinationAccountId", - table: "Transactions", - type: "bigint", - nullable: false, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "TransactionId", - table: "Transactions", - type: "bigint", - nullable: false, - oldClrType: typeof(int), - oldType: "integer") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AlterColumn( - name: "CardId", - table: "Accounts", - type: "bigint", - nullable: false, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "AccountId", - table: "Accounts", - type: "bigint", - nullable: false, - oldClrType: typeof(int), - oldType: "integer") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "021da0cb-1048-4551-9858-90c98ee66289", null, "DataAnalyst", "DATAANALYST" }, - { "2d28da36-33b9-4ac1-b08f-50b4dd6855d2", null, "DataAdmin", "DATAADMIN" }, - { "bef465d8-3d0e-469f-8b45-5f9be9c40f66", null, "Admin", "ADMIN" } - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "021da0cb-1048-4551-9858-90c98ee66289"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "2d28da36-33b9-4ac1-b08f-50b4dd6855d2"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "bef465d8-3d0e-469f-8b45-5f9be9c40f66"); - - migrationBuilder.AlterColumn( - name: "SourceAccountId", - table: "Transactions", - type: "integer", - nullable: false, - oldClrType: typeof(long), - oldType: "bigint"); - - migrationBuilder.AlterColumn( - name: "DestinationAccountId", - table: "Transactions", - type: "integer", - nullable: false, - oldClrType: typeof(long), - oldType: "bigint"); - - migrationBuilder.AlterColumn( - name: "TransactionId", - table: "Transactions", - type: "integer", - nullable: false, - oldClrType: typeof(long), - oldType: "bigint") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AlterColumn( - name: "CardId", - table: "Accounts", - type: "integer", - nullable: false, - oldClrType: typeof(long), - oldType: "bigint"); - - migrationBuilder.AlterColumn( - name: "AccountId", - table: "Accounts", - type: "integer", - nullable: false, - oldClrType: typeof(long), - oldType: "bigint") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "0a8ca877-f408-4d10-806f-1714e41b0186", null, "Admin", "ADMIN" }, - { "913a4192-89c6-4d8e-873c-52d9695f8d59", null, "DataAnalyst", "DATAANALYST" }, - { "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b", null, "DataAdmin", "DATAADMIN" } - }); - } - } -} +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Infrastructure.Migrations +{ + /// + public partial class CastIdsToLong : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "0a8ca877-f408-4d10-806f-1714e41b0186"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "913a4192-89c6-4d8e-873c-52d9695f8d59"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b"); + + migrationBuilder.AlterColumn( + name: "SourceAccountId", + table: "Transactions", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "DestinationAccountId", + table: "Transactions", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "TransactionId", + table: "Transactions", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "CardId", + table: "Accounts", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "AccountId", + table: "Accounts", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "021da0cb-1048-4551-9858-90c98ee66289", null, "DataAnalyst", "DATAANALYST" }, + { "2d28da36-33b9-4ac1-b08f-50b4dd6855d2", null, "DataAdmin", "DATAADMIN" }, + { "bef465d8-3d0e-469f-8b45-5f9be9c40f66", null, "Admin", "ADMIN" } + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "021da0cb-1048-4551-9858-90c98ee66289"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "2d28da36-33b9-4ac1-b08f-50b4dd6855d2"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "bef465d8-3d0e-469f-8b45-5f9be9c40f66"); + + migrationBuilder.AlterColumn( + name: "SourceAccountId", + table: "Transactions", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "DestinationAccountId", + table: "Transactions", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "TransactionId", + table: "Transactions", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "CardId", + table: "Accounts", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + + migrationBuilder.AlterColumn( + name: "AccountId", + table: "Accounts", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "0a8ca877-f408-4d10-806f-1714e41b0186", null, "Admin", "ADMIN" }, + { "913a4192-89c6-4d8e-873c-52d9695f8d59", null, "DataAnalyst", "DATAANALYST" }, + { "fa9ffeed-788f-40cd-a86b-3e5ad7a03e0b", null, "DataAdmin", "DATAADMIN" } + }); + } + } +} diff --git a/src/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs index d3c4ba7..60fd954 100644 --- a/src/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,411 +1,411 @@ -// -using System; -using Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Infrastructure.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.7") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Domain.Entities.Account", b => - { - b.Property("AccountId") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AccountId")); - - b.Property("AccountType") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchAddress") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchName") - .IsRequired() - .HasColumnType("text"); - - b.Property("BranchTelephone") - .IsRequired() - .HasColumnType("text"); - - b.Property("CardId") - .HasColumnType("bigint"); - - b.Property("Iban") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerId") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerLastName") - .IsRequired() - .HasColumnType("text"); - - b.Property("OwnerName") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("AccountId"); - - b.ToTable("Accounts"); - }); - - modelBuilder.Entity("Domain.Entities.AppUser", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Domain.Entities.Transaction", b => - { - b.Property("TransactionId") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TransactionId")); - - b.Property("Amount") - .HasColumnType("numeric"); - - b.Property("Date") - .HasColumnType("timestamp with time zone"); - - b.Property("DestinationAccountId") - .HasColumnType("bigint"); - - b.Property("SourceAccountId") - .HasColumnType("bigint"); - - b.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("TransactionId"); - - b.HasIndex("DestinationAccountId"); - - b.HasIndex("SourceAccountId"); - - b.ToTable("Transactions"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("text"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "bef465d8-3d0e-469f-8b45-5f9be9c40f66", - Name = "Admin", - NormalizedName = "ADMIN" - }, - new - { - Id = "2d28da36-33b9-4ac1-b08f-50b4dd6855d2", - Name = "DataAdmin", - NormalizedName = "DATAADMIN" - }, - new - { - Id = "021da0cb-1048-4551-9858-90c98ee66289", - Name = "DataAnalyst", - NormalizedName = "DATAANALYST" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("text"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("text"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Domain.Entities.Transaction", b => - { - b.HasOne("Domain.Entities.Account", "DestinationAccount") - .WithMany("DestinationTransactions") - .HasForeignKey("DestinationAccountId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.HasOne("Domain.Entities.Account", "SourceAccount") - .WithMany("SourceTransactions") - .HasForeignKey("SourceAccountId") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("DestinationAccount"); - - b.Navigation("SourceAccount"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Domain.Entities.AppUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Domain.Entities.Account", b => - { - b.Navigation("DestinationTransactions"); - - b.Navigation("SourceTransactions"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Infrastructure.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Domain.Entities.Account", b => + { + b.Property("AccountId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("AccountId")); + + b.Property("AccountType") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BranchTelephone") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardId") + .HasColumnType("bigint"); + + b.Property("Iban") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerId") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerLastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OwnerName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("AccountId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("Domain.Entities.AppUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Transaction", b => + { + b.Property("TransactionId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("TransactionId")); + + b.Property("Amount") + .HasColumnType("numeric"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("DestinationAccountId") + .HasColumnType("bigint"); + + b.Property("SourceAccountId") + .HasColumnType("bigint"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("TransactionId"); + + b.HasIndex("DestinationAccountId"); + + b.HasIndex("SourceAccountId"); + + b.ToTable("Transactions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "bef465d8-3d0e-469f-8b45-5f9be9c40f66", + Name = "Admin", + NormalizedName = "ADMIN" + }, + new + { + Id = "2d28da36-33b9-4ac1-b08f-50b4dd6855d2", + Name = "DataAdmin", + NormalizedName = "DATAADMIN" + }, + new + { + Id = "021da0cb-1048-4551-9858-90c98ee66289", + Name = "DataAnalyst", + NormalizedName = "DATAANALYST" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Transaction", b => + { + b.HasOne("Domain.Entities.Account", "DestinationAccount") + .WithMany("DestinationTransactions") + .HasForeignKey("DestinationAccountId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("Domain.Entities.Account", "SourceAccount") + .WithMany("SourceTransactions") + .HasForeignKey("SourceAccountId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("DestinationAccount"); + + b.Navigation("SourceAccount"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.Account", b => + { + b.Navigation("DestinationTransactions"); + + b.Navigation("SourceTransactions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Services/AccountRepository.cs b/src/Infrastructure/Services/AccountRepository.cs index f561501..5ff80ce 100644 --- a/src/Infrastructure/Services/AccountRepository.cs +++ b/src/Infrastructure/Services/AccountRepository.cs @@ -1,41 +1,41 @@ -using Application.Interfaces; -using Domain.Entities; -using Infrastructure.Data; -using Microsoft.EntityFrameworkCore; - -namespace Infrastructure.Services; - -public class AccountRepository : IAccountRepository -{ - private readonly ApplicationDbContext _dbContext; - - public AccountRepository(ApplicationDbContext dbContext) - { - _dbContext = dbContext; - } - - public async Task CreateBulkAsync(List accounts) - { - await _dbContext.Accounts.AddRangeAsync(accounts); - await _dbContext.SaveChangesAsync(); - } - - public async Task GetByIdAsync(long accountId) - { - return await _dbContext.Accounts.FindAsync(accountId); - } - - public async Task> GetTransactionsByAccountId(long accountId) - { - var account = await _dbContext.Accounts - .Include(a => a.SourceTransactions) - .FirstOrDefaultAsync(a => a.AccountId == accountId); - - if (account == null) - { - return new List(); - } - - return account.SourceTransactions.ToList(); - } +using Application.Interfaces; +using Domain.Entities; +using Infrastructure.Data; +using Microsoft.EntityFrameworkCore; + +namespace Infrastructure.Services; + +public class AccountRepository : IAccountRepository +{ + private readonly ApplicationDbContext _dbContext; + + public AccountRepository(ApplicationDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task CreateBulkAsync(List accounts) + { + await _dbContext.Accounts.AddRangeAsync(accounts); + await _dbContext.SaveChangesAsync(); + } + + public async Task GetByIdAsync(long accountId) + { + return await _dbContext.Accounts.FindAsync(accountId); + } + + public async Task> GetTransactionsByAccountId(long accountId) + { + var account = await _dbContext.Accounts + .Include(a => a.SourceTransactions) + .FirstOrDefaultAsync(a => a.AccountId == accountId); + + if (account == null) + { + return new List(); + } + + return account.SourceTransactions.ToList(); + } } \ No newline at end of file diff --git a/src/Infrastructure/Services/RoleManagerService.cs b/src/Infrastructure/Services/RoleManagerService.cs index 71eb37c..7ebd4a8 100644 --- a/src/Infrastructure/Services/RoleManagerService.cs +++ b/src/Infrastructure/Services/RoleManagerService.cs @@ -1,18 +1,18 @@ -using Application.Interfaces; -using Microsoft.AspNetCore.Identity; - -namespace Infrastructure.Services; - -public class RoleManagerService : IRoleManager -{ - private readonly RoleManager _roleManager; - public RoleManagerService(RoleManager roleManager) - { - _roleManager = roleManager; - } - - public async Task RoleExistsAsync(string roleName) - { - return await _roleManager.RoleExistsAsync(roleName); - } +using Application.Interfaces; +using Microsoft.AspNetCore.Identity; + +namespace Infrastructure.Services; + +public class RoleManagerService : IRoleManager +{ + private readonly RoleManager _roleManager; + public RoleManagerService(RoleManager roleManager) + { + _roleManager = roleManager; + } + + public async Task RoleExistsAsync(string roleName) + { + return await _roleManager.RoleExistsAsync(roleName); + } } \ No newline at end of file diff --git a/src/Infrastructure/Services/TransactionRepository.cs b/src/Infrastructure/Services/TransactionRepository.cs index a0eedf4..185a1f8 100644 --- a/src/Infrastructure/Services/TransactionRepository.cs +++ b/src/Infrastructure/Services/TransactionRepository.cs @@ -1,26 +1,26 @@ -using Application.Interfaces; -using Domain.Entities; -using Infrastructure.Data; -using Microsoft.EntityFrameworkCore; - -namespace Infrastructure.Services; - -public class TransactionRepository : ITransactionRepository -{ - private readonly ApplicationDbContext _dbContext; - public TransactionRepository(ApplicationDbContext dbContext) - { - _dbContext = dbContext; - } - - public async Task CreateBulkAsync(List transactions) - { - await _dbContext.Transactions.AddRangeAsync(transactions); - await _dbContext.SaveChangesAsync(); - } - - public async Task> GetAllTransactions() - { - return await _dbContext.Transactions.ToListAsync(); - } +using Application.Interfaces; +using Domain.Entities; +using Infrastructure.Data; +using Microsoft.EntityFrameworkCore; + +namespace Infrastructure.Services; + +public class TransactionRepository : ITransactionRepository +{ + private readonly ApplicationDbContext _dbContext; + public TransactionRepository(ApplicationDbContext dbContext) + { + _dbContext = dbContext; + } + + public async Task CreateBulkAsync(List transactions) + { + await _dbContext.Transactions.AddRangeAsync(transactions); + await _dbContext.SaveChangesAsync(); + } + + public async Task> GetAllTransactions() + { + return await _dbContext.Transactions.ToListAsync(); + } } \ No newline at end of file diff --git a/src/Infrastructure/Services/UserManagerService.cs b/src/Infrastructure/Services/UserManagerService.cs index 0e6773d..e240440 100644 --- a/src/Infrastructure/Services/UserManagerService.cs +++ b/src/Infrastructure/Services/UserManagerService.cs @@ -1,81 +1,81 @@ -using Application.Interfaces; -using Domain.Entities; -using Microsoft.AspNetCore.Identity; - -namespace Infrastructure.Services; - -public class UserManagerService : IUserManager -{ - private readonly UserManager _userManager; - - public UserManagerService(UserManager userManager) - { - _userManager = userManager; - } - - public async Task CreateAsync(AppUser user, string password) - { - return await _userManager.CreateAsync(user, password); - } - - public async Task SetRoleAsync(AppUser user, string role) - { - // TODO check if adding multiple roles - return await _userManager.AddToRoleAsync(user, role); - } - - public async Task ChangeRoleAsync(AppUser user, string newRole) - { - // TODO check if removing multiple roles - var currentRole = await GetRoleAsync(user); - if (currentRole == newRole) - { - return IdentityResult.Success; - } - - var removeRoleResult = await _userManager.RemoveFromRoleAsync(user, currentRole); - if (!removeRoleResult.Succeeded) - { - return removeRoleResult; - } - - return await _userManager.AddToRoleAsync(user, newRole); - } - - public async Task FindByNameAsync(string userName) - { - return await _userManager.FindByNameAsync(userName); - } - - public async Task FindByEmailAsync(string email) - { - return await _userManager.FindByEmailAsync(email); - } - - public async Task FindByIdAsync(string userId) - { - return await _userManager.FindByIdAsync(userId); - } - - public async Task UpdateAsync(AppUser user) - { - return await _userManager.UpdateAsync(user); - } - - public async Task ChangePasswordAsync(AppUser user, string currentPassword, string newPassword) - { - return await _userManager.ChangePasswordAsync(user, currentPassword, newPassword); - } - - public async Task GetRoleAsync(AppUser user) - { - // TODO can return null here. - return (await _userManager.GetRolesAsync(user)).Single(); - } - - public async Task CheckPasswordAsync(AppUser user, string password) - { - // TODO there should be a sign in manager service - return await _userManager.CheckPasswordAsync(user, password); - } +using Application.Interfaces; +using Domain.Entities; +using Microsoft.AspNetCore.Identity; + +namespace Infrastructure.Services; + +public class UserManagerService : IUserManager +{ + private readonly UserManager _userManager; + + public UserManagerService(UserManager userManager) + { + _userManager = userManager; + } + + public async Task CreateAsync(AppUser user, string password) + { + return await _userManager.CreateAsync(user, password); + } + + public async Task SetRoleAsync(AppUser user, string role) + { + // TODO check if adding multiple roles + return await _userManager.AddToRoleAsync(user, role); + } + + public async Task ChangeRoleAsync(AppUser user, string newRole) + { + // TODO check if removing multiple roles + var currentRole = await GetRoleAsync(user); + if (currentRole == newRole) + { + return IdentityResult.Success; + } + + var removeRoleResult = await _userManager.RemoveFromRoleAsync(user, currentRole); + if (!removeRoleResult.Succeeded) + { + return removeRoleResult; + } + + return await _userManager.AddToRoleAsync(user, newRole); + } + + public async Task FindByNameAsync(string userName) + { + return await _userManager.FindByNameAsync(userName); + } + + public async Task FindByEmailAsync(string email) + { + return await _userManager.FindByEmailAsync(email); + } + + public async Task FindByIdAsync(string userId) + { + return await _userManager.FindByIdAsync(userId); + } + + public async Task UpdateAsync(AppUser user) + { + return await _userManager.UpdateAsync(user); + } + + public async Task ChangePasswordAsync(AppUser user, string currentPassword, string newPassword) + { + return await _userManager.ChangePasswordAsync(user, currentPassword, newPassword); + } + + public async Task GetRoleAsync(AppUser user) + { + // TODO can return null here. + return (await _userManager.GetRolesAsync(user)).Single(); + } + + public async Task CheckPasswordAsync(AppUser user, string password) + { + // TODO there should be a sign in manager service + return await _userManager.CheckPasswordAsync(user, password); + } } \ No newline at end of file diff --git a/src/Web/Controllers/AccountController.cs b/src/Web/Controllers/AccountController.cs index 72b109d..f833f02 100644 --- a/src/Web/Controllers/AccountController.cs +++ b/src/Web/Controllers/AccountController.cs @@ -1,61 +1,61 @@ -using Application.Interfaces.Services; -using Microsoft.AspNetCore.Mvc; -using Web.Mappers; - -namespace Web.Controllers; - -[ApiController] -[Route("[controller]/[action]")] -public class AccountController : ControllerBase -{ - private readonly IAccountService _accountService; - - public AccountController(IAccountService accountService) - { - _accountService = accountService; - } - - [HttpPost] - public async Task ImportAccounts([FromForm] IFormFile file) - { - if (file.Length == 0) - return BadRequest("No file uploaded."); - - var filePath = Path.GetTempFileName(); - - await using (var stream = System.IO.File.Create(filePath)) - { - await file.CopyToAsync(stream); - } - - await _accountService.AddAccountsFromCsvAsync(filePath); - - return Ok("Accounts imported successfully."); - } - - [HttpGet("{accountId}")] - public async Task GetAccountById(long accountId) - { - var account = await _accountService.GetAccountByIdAsync(accountId); - if (account == null) - { - return NotFound(); - } - - return Ok(account.ToAccountDto()); - } - - [HttpGet("{accountId}")] - public async Task GetTransactionsByUserId(long accountId) - { - var result = await _accountService.GetTransactionsByUserId(accountId); - if (!result.Succeed) - { - return NotFound("User do not exist"); - } - - var transactions = result.Value; - - return Ok(transactions!.Select(t => t.ToTransactionDto())); - } +using Application.Interfaces.Services; +using Microsoft.AspNetCore.Mvc; +using Web.Mappers; + +namespace Web.Controllers; + +[ApiController] +[Route("[controller]/[action]")] +public class AccountController : ControllerBase +{ + private readonly IAccountService _accountService; + + public AccountController(IAccountService accountService) + { + _accountService = accountService; + } + + [HttpPost] + public async Task ImportAccounts([FromForm] IFormFile file) + { + if (file.Length == 0) + return BadRequest("No file uploaded."); + + var filePath = Path.GetTempFileName(); + + await using (var stream = System.IO.File.Create(filePath)) + { + await file.CopyToAsync(stream); + } + + await _accountService.AddAccountsFromCsvAsync(filePath); + + return Ok("Accounts imported successfully."); + } + + [HttpGet("{accountId}")] + public async Task GetAccountById(long accountId) + { + var account = await _accountService.GetAccountByIdAsync(accountId); + if (account == null) + { + return NotFound(); + } + + return Ok(account.ToAccountDto()); + } + + [HttpGet("{accountId}")] + public async Task GetTransactionsByUserId(long accountId) + { + var result = await _accountService.GetTransactionsByUserId(accountId); + if (!result.Succeed) + { + return NotFound("User do not exist"); + } + + var transactions = result.Value; + + return Ok(transactions!.Select(t => t.ToTransactionDto())); + } } \ No newline at end of file diff --git a/src/Web/Controllers/IdentityController.cs b/src/Web/Controllers/IdentityController.cs index 1090af0..45e7392 100644 --- a/src/Web/Controllers/IdentityController.cs +++ b/src/Web/Controllers/IdentityController.cs @@ -1,68 +1,68 @@ -using Application.Interfaces.Services; -using Domain.Constants; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Web.DTOs.Identity; -using Web.Helper; -using Web.Identity; -using Web.Mappers; - -namespace Web.Controllers; - -[ApiController] -[Route("[controller]/[action]")] -public class IdentityController : ControllerBase -{ - private readonly IIdentityService _identityService; - public IdentityController(IIdentityService identityService) - { - _identityService = identityService; - } - - [HttpPost] - [Authorize] - [RequiresClaim(Claims.Role, AppRoles.Admin)] - public async Task Signup([FromBody] SignupDto signupDto) - { - var result = await _identityService.SignUpUser(signupDto.ToCreateUserRequest()); - - if (!result.Succeed) - { - return BadRequest(Errors.New(nameof(Signup), result.Message)); - } - - var response = result.Value!; - - return Ok(response.ToUserSignedUpDto()); - } - - [HttpPost] - public async Task Login([FromBody] LoginDto loginDto) - { - var result = await _identityService.Login(loginDto.ToLoginUserRequest()); - - if (!result.Succeed) - { - return Unauthorized(Errors.New(nameof(Login), result.Message)); - } - - var response = result.Value!; - - return Ok(response.ToUserLoggedInDto()); - } - - [HttpPut] - [Authorize] - [RequiresClaim(Claims.Role, AppRoles.Admin)] - public async Task ChangeRole([FromBody] ChangeRoleDto changeRoleDto) - { - var result = await _identityService.ChangeRole(changeRoleDto.ToChangeRoleRequest()); - - if (!result.Succeed) - { - return BadRequest(Errors.New(nameof(ChangeRole), result.Message)); - } - - return Ok("Role changed successfully!"); - } +using Application.Interfaces.Services; +using Domain.Constants; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Web.DTOs.Identity; +using Web.Helper; +using Web.Identity; +using Web.Mappers; + +namespace Web.Controllers; + +[ApiController] +[Route("[controller]/[action]")] +public class IdentityController : ControllerBase +{ + private readonly IIdentityService _identityService; + public IdentityController(IIdentityService identityService) + { + _identityService = identityService; + } + + [HttpPost] + [Authorize] + [RequiresClaim(Claims.Role, AppRoles.Admin)] + public async Task Signup([FromBody] SignupDto signupDto) + { + var result = await _identityService.SignUpUser(signupDto.ToCreateUserRequest()); + + if (!result.Succeed) + { + return BadRequest(Errors.New(nameof(Signup), result.Message)); + } + + var response = result.Value!; + + return Ok(response.ToUserSignedUpDto()); + } + + [HttpPost] + public async Task Login([FromBody] LoginDto loginDto) + { + var result = await _identityService.Login(loginDto.ToLoginUserRequest()); + + if (!result.Succeed) + { + return Unauthorized(Errors.New(nameof(Login), result.Message)); + } + + var response = result.Value!; + + return Ok(response.ToUserLoggedInDto()); + } + + [HttpPut] + [Authorize] + [RequiresClaim(Claims.Role, AppRoles.Admin)] + public async Task ChangeRole([FromBody] ChangeRoleDto changeRoleDto) + { + var result = await _identityService.ChangeRole(changeRoleDto.ToChangeRoleRequest()); + + if (!result.Succeed) + { + return BadRequest(Errors.New(nameof(ChangeRole), result.Message)); + } + + return Ok("Role changed successfully!"); + } } \ No newline at end of file diff --git a/src/Web/Controllers/ProfileController.cs b/src/Web/Controllers/ProfileController.cs index 27ba7f1..d570d89 100644 --- a/src/Web/Controllers/ProfileController.cs +++ b/src/Web/Controllers/ProfileController.cs @@ -1,74 +1,74 @@ -using Application.DTOs; -using Application.DTOs.Identity; -using Application.Interfaces.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Web.DTOs.Profile; -using Web.Helper; -using Web.Identity; -using Web.Mappers; - -namespace Web.Controllers; - -[ApiController] -[Route("[controller]/[action]")] -public class ProfileController : ControllerBase -{ - private readonly IProfileService _profileService; - - public ProfileController(IProfileService profileService) - { - _profileService = profileService; - } - - [HttpPut] - [Authorize] - public async Task EditProfileInfo([FromBody] EditProfileInfoDto editProfileInfoDto) - { - var userId = User.Claims.First(x => x.Type == Claims.UserId).Value; - - Result result = await _profileService.EditProfileInfo(editProfileInfoDto.ToEditProfileInfoRequest(userId)); - - if (!result.Succeed) - { - return BadRequest(Errors.New(nameof(EditProfileInfo), result.Message)); - } - - return Ok("Profile info updated successfully!"); - } - - [HttpGet] - [Authorize] - public async Task GetProfileInfo() - { - var userId = User.Claims.First(x => x.Type == Claims.UserId).Value; - - var result = await _profileService.GetProfileInfo(new GetProfileInfoRequest{UserId = userId}); - - if (!result.Succeed) - { - return NotFound(Errors.New(nameof(GetProfileInfo), "User not found!")); - } - - var user = result.Value!; - - return Ok(user.ToProfileInfoDto()); - } - - [HttpPut] - [Authorize] - public async Task ChangePassword([FromBody] ChangePasswordDto changePasswordDto) - { - var userId = User.Claims.First(x => x.Type == Claims.UserId).Value; - - var result = await _profileService.ChangePassword(changePasswordDto.ToChangePasswordRequest(userId)); - - if (!result.Succeed) - { - return BadRequest(Errors.New(nameof(ChangePassword), result.Message)); - } - - return Ok("Password changed successfully!"); - } - +using Application.DTOs; +using Application.DTOs.Identity; +using Application.Interfaces.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Web.DTOs.Profile; +using Web.Helper; +using Web.Identity; +using Web.Mappers; + +namespace Web.Controllers; + +[ApiController] +[Route("[controller]/[action]")] +public class ProfileController : ControllerBase +{ + private readonly IProfileService _profileService; + + public ProfileController(IProfileService profileService) + { + _profileService = profileService; + } + + [HttpPut] + [Authorize] + public async Task EditProfileInfo([FromBody] EditProfileInfoDto editProfileInfoDto) + { + var userId = User.Claims.First(x => x.Type == Claims.UserId).Value; + + Result result = await _profileService.EditProfileInfo(editProfileInfoDto.ToEditProfileInfoRequest(userId)); + + if (!result.Succeed) + { + return BadRequest(Errors.New(nameof(EditProfileInfo), result.Message)); + } + + return Ok("Profile info updated successfully!"); + } + + [HttpGet] + [Authorize] + public async Task GetProfileInfo() + { + var userId = User.Claims.First(x => x.Type == Claims.UserId).Value; + + var result = await _profileService.GetProfileInfo(new GetProfileInfoRequest{UserId = userId}); + + if (!result.Succeed) + { + return NotFound(Errors.New(nameof(GetProfileInfo), "User not found!")); + } + + var user = result.Value!; + + return Ok(user.ToProfileInfoDto()); + } + + [HttpPut] + [Authorize] + public async Task ChangePassword([FromBody] ChangePasswordDto changePasswordDto) + { + var userId = User.Claims.First(x => x.Type == Claims.UserId).Value; + + var result = await _profileService.ChangePassword(changePasswordDto.ToChangePasswordRequest(userId)); + + if (!result.Succeed) + { + return BadRequest(Errors.New(nameof(ChangePassword), result.Message)); + } + + return Ok("Password changed successfully!"); + } + } \ No newline at end of file diff --git a/src/Web/Controllers/TransactionController.cs b/src/Web/Controllers/TransactionController.cs index 4c88357..53210dc 100644 --- a/src/Web/Controllers/TransactionController.cs +++ b/src/Web/Controllers/TransactionController.cs @@ -1,51 +1,51 @@ -using Application.Interfaces.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Web.Helper; -using Web.Mappers; - -namespace Web.Controllers; - -[ApiController] -[Route("[controller]/[action]")] -public class TransactionController : ControllerBase -{ - public readonly ITransactionService _transactionService; - - public TransactionController(ITransactionService transactionService) - { - _transactionService = transactionService; - } - - [HttpPost] - public async Task ImportTransactions([FromForm] IFormFile file) - { - if (file.Length == 0) - return BadRequest("No file uploaded."); - - var filePath = Path.GetTempFileName(); - - await using (var stream = System.IO.File.Create(filePath)) - { - await file.CopyToAsync(stream); - } - - await _transactionService.AddTransactionsFromCsvAsync(filePath); - - return Ok("Transactions imported successfully."); - } - - [HttpGet] - [Authorize] - public async Task GetAllTransactions() - { - var allTransactions = await _transactionService.GetAllTransactions(); - if (!allTransactions.Succeed) - { - return BadRequest(Errors.New(nameof(GetAllTransactions), allTransactions.Message)); - } - - var response = allTransactions.Value!; - return Ok(response.ToGotAllTransactionsDto()); - } +using Application.Interfaces.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Web.Helper; +using Web.Mappers; + +namespace Web.Controllers; + +[ApiController] +[Route("[controller]/[action]")] +public class TransactionController : ControllerBase +{ + public readonly ITransactionService _transactionService; + + public TransactionController(ITransactionService transactionService) + { + _transactionService = transactionService; + } + + [HttpPost] + public async Task ImportTransactions([FromForm] IFormFile file) + { + if (file.Length == 0) + return BadRequest("No file uploaded."); + + var filePath = Path.GetTempFileName(); + + await using (var stream = System.IO.File.Create(filePath)) + { + await file.CopyToAsync(stream); + } + + await _transactionService.AddTransactionsFromCsvAsync(filePath); + + return Ok("Transactions imported successfully."); + } + + [HttpGet] + [Authorize] + public async Task GetAllTransactions() + { + var allTransactions = await _transactionService.GetAllTransactions(); + if (!allTransactions.Succeed) + { + return BadRequest(Errors.New(nameof(GetAllTransactions), allTransactions.Message)); + } + + var response = allTransactions.Value!; + return Ok(response.ToGotAllTransactionsDto()); + } } \ No newline at end of file diff --git a/src/Web/DTOs/Account/AccountDto.cs b/src/Web/DTOs/Account/AccountDto.cs index 717e229..5ef90c2 100644 --- a/src/Web/DTOs/Account/AccountDto.cs +++ b/src/Web/DTOs/Account/AccountDto.cs @@ -1,15 +1,15 @@ -namespace Web.DTOs.Account; - -public class AccountDto -{ - public long AccountId { get; set; } - public long CardId { get; set; } - public string Iban { get; set; } = String.Empty; - public string AccountType { get; set; } = String.Empty; - public string BranchTelephone { get; set; } = String.Empty; - public string BranchAddress { get; set; } = String.Empty; - public string BranchName { get; set; } = String.Empty; - public string OwnerName { get; set; } = String.Empty; - public string OwnerLastName { get; set; } = String.Empty; - public string OwnerId { get; set; } = String.Empty; +namespace Web.DTOs.Account; + +public class AccountDto +{ + public long AccountId { get; set; } + public long CardId { get; set; } + public string Iban { get; set; } = String.Empty; + public string AccountType { get; set; } = String.Empty; + public string BranchTelephone { get; set; } = String.Empty; + public string BranchAddress { get; set; } = String.Empty; + public string BranchName { get; set; } = String.Empty; + public string OwnerName { get; set; } = String.Empty; + public string OwnerLastName { get; set; } = String.Empty; + public string OwnerId { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Identity/ChangeRoleDto.cs b/src/Web/DTOs/Identity/ChangeRoleDto.cs index eb60349..f6301f2 100644 --- a/src/Web/DTOs/Identity/ChangeRoleDto.cs +++ b/src/Web/DTOs/Identity/ChangeRoleDto.cs @@ -1,7 +1,7 @@ -namespace Web.DTOs.Identity; - -public class ChangeRoleDto -{ - public string UserName { get; set; } = string.Empty; - public string Role { get; set; } = string.Empty; +namespace Web.DTOs.Identity; + +public class ChangeRoleDto +{ + public string UserName { get; set; } = string.Empty; + public string Role { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Identity/Login/LoginDto.cs b/src/Web/DTOs/Identity/Login/LoginDto.cs index 41d0209..67b7985 100644 --- a/src/Web/DTOs/Identity/Login/LoginDto.cs +++ b/src/Web/DTOs/Identity/Login/LoginDto.cs @@ -1,12 +1,12 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.InteropServices.JavaScript; - -namespace Web.DTOs.Identity; - -public class LoginDto -{ - public string? UserName { get; set; } - public string? Email { get; set; } - [Required] - public string Password { get; set; } = String.Empty; +using System.ComponentModel.DataAnnotations; +using System.Runtime.InteropServices.JavaScript; + +namespace Web.DTOs.Identity; + +public class LoginDto +{ + public string? UserName { get; set; } + public string? Email { get; set; } + [Required] + public string Password { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Identity/Login/UserLoggedInDto.cs b/src/Web/DTOs/Identity/Login/UserLoggedInDto.cs index 8ef5237..f26d6e5 100644 --- a/src/Web/DTOs/Identity/Login/UserLoggedInDto.cs +++ b/src/Web/DTOs/Identity/Login/UserLoggedInDto.cs @@ -1,11 +1,11 @@ -namespace Web.DTOs.Identity; - -public class UserLoggedInDto -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; - public string Token { get; set; } = String.Empty; +namespace Web.DTOs.Identity; + +public class UserLoggedInDto +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; + public string Token { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Identity/Signup/SignupDto.cs b/src/Web/DTOs/Identity/Signup/SignupDto.cs index 3d1a1db..10d674c 100644 --- a/src/Web/DTOs/Identity/Signup/SignupDto.cs +++ b/src/Web/DTOs/Identity/Signup/SignupDto.cs @@ -1,27 +1,27 @@ -using System.ComponentModel.DataAnnotations; - -namespace Web.DTOs.Identity; - -public class SignupDto -{ - [Required] - [MaxLength(50)] - public string FirstName { get; set; } = String.Empty; - [Required] - [MaxLength(50)] - public string LastName { get; set; } = String.Empty; - [Required] - [MaxLength(50)] - [EmailAddress] - public string Email { get; set; } = String.Empty; - [Required] - [MaxLength(50)] - public string UserName { get; set; } = String.Empty; - [Required] - [MaxLength(50)] - [MinLength(8)] - public string Password { get; set; } = String.Empty; - [Required] - [MaxLength(50)] - public string Role { get; set; } = String.Empty; +using System.ComponentModel.DataAnnotations; + +namespace Web.DTOs.Identity; + +public class SignupDto +{ + [Required] + [MaxLength(50)] + public string FirstName { get; set; } = String.Empty; + [Required] + [MaxLength(50)] + public string LastName { get; set; } = String.Empty; + [Required] + [MaxLength(50)] + [EmailAddress] + public string Email { get; set; } = String.Empty; + [Required] + [MaxLength(50)] + public string UserName { get; set; } = String.Empty; + [Required] + [MaxLength(50)] + [MinLength(8)] + public string Password { get; set; } = String.Empty; + [Required] + [MaxLength(50)] + public string Role { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Identity/Signup/UserSignedUpDto.cs b/src/Web/DTOs/Identity/Signup/UserSignedUpDto.cs index d5dc30d..3bda182 100644 --- a/src/Web/DTOs/Identity/Signup/UserSignedUpDto.cs +++ b/src/Web/DTOs/Identity/Signup/UserSignedUpDto.cs @@ -1,10 +1,10 @@ -namespace Web.DTOs.Identity; - -public class UserSignedUpDto -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; +namespace Web.DTOs.Identity; + +public class UserSignedUpDto +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Profile/ChangePasswordDto.cs b/src/Web/DTOs/Profile/ChangePasswordDto.cs index cdd49cc..ed05cd2 100644 --- a/src/Web/DTOs/Profile/ChangePasswordDto.cs +++ b/src/Web/DTOs/Profile/ChangePasswordDto.cs @@ -1,11 +1,11 @@ -using System.ComponentModel.DataAnnotations; - -namespace Web.DTOs.Profile; - -public class ChangePasswordDto -{ - [Required] - public string CurrentPassword { get; set; } = string.Empty; - [Required] - public string NewPassword { get; set; } = string.Empty; +using System.ComponentModel.DataAnnotations; + +namespace Web.DTOs.Profile; + +public class ChangePasswordDto +{ + [Required] + public string CurrentPassword { get; set; } = string.Empty; + [Required] + public string NewPassword { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Profile/ChangeProfileDto.cs b/src/Web/DTOs/Profile/ChangeProfileDto.cs index f9de508..e417eba 100644 --- a/src/Web/DTOs/Profile/ChangeProfileDto.cs +++ b/src/Web/DTOs/Profile/ChangeProfileDto.cs @@ -1,13 +1,13 @@ -using System.ComponentModel.DataAnnotations; - -namespace Web.DTOs.Profile; - -public class EditProfileInfoDto -{ - [Required] - public string UserName { get; set; } = string.Empty; - [Required] - public string FirstName { get; set; } = string.Empty; - [Required] - public string LastName { get; set; } = string.Empty; +using System.ComponentModel.DataAnnotations; + +namespace Web.DTOs.Profile; + +public class EditProfileInfoDto +{ + [Required] + public string UserName { get; set; } = string.Empty; + [Required] + public string FirstName { get; set; } = string.Empty; + [Required] + public string LastName { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Profile/ProfileInfoDto.cs b/src/Web/DTOs/Profile/ProfileInfoDto.cs index d217fd2..ffe7c9c 100644 --- a/src/Web/DTOs/Profile/ProfileInfoDto.cs +++ b/src/Web/DTOs/Profile/ProfileInfoDto.cs @@ -1,10 +1,10 @@ -namespace Web.DTOs.Profile; - -public class ProfileInfoDto -{ - public string FirstName { get; set; } = String.Empty; - public string LastName { get; set; } = String.Empty; - public string Email { get; set; } = String.Empty; - public string UserName { get; set; } = String.Empty; - public string Role { get; set; } = String.Empty; +namespace Web.DTOs.Profile; + +public class ProfileInfoDto +{ + public string FirstName { get; set; } = String.Empty; + public string LastName { get; set; } = String.Empty; + public string Email { get; set; } = String.Empty; + public string UserName { get; set; } = String.Empty; + public string Role { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Transaction/GotAllTransactionsDto.cs b/src/Web/DTOs/Transaction/GotAllTransactionsDto.cs index 35460e5..aaa451e 100644 --- a/src/Web/DTOs/Transaction/GotAllTransactionsDto.cs +++ b/src/Web/DTOs/Transaction/GotAllTransactionsDto.cs @@ -1,13 +1,13 @@ -using System.ComponentModel.DataAnnotations; - -namespace Web.DTOs.Transaction; - -public class GotAllTransactionsDto -{ - public long TransactionId { get; set; } - public long SourceAccountId { get; set; } - public long DestinationAccountId { get; set; } - public decimal Amount { get; set; } - public DateTime Date { get; set; } - public string Type { get; set; } = string.Empty; +using System.ComponentModel.DataAnnotations; + +namespace Web.DTOs.Transaction; + +public class GotAllTransactionsDto +{ + public long TransactionId { get; set; } + public long SourceAccountId { get; set; } + public long DestinationAccountId { get; set; } + public decimal Amount { get; set; } + public DateTime Date { get; set; } + public string Type { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/Web/DTOs/Transaction/TransactionDto.cs b/src/Web/DTOs/Transaction/TransactionDto.cs index da584af..b75add9 100644 --- a/src/Web/DTOs/Transaction/TransactionDto.cs +++ b/src/Web/DTOs/Transaction/TransactionDto.cs @@ -1,11 +1,11 @@ -namespace Web.DTOs.Transaction; - -public class TransactionDto -{ - public long TransactionId { get; set; } - public long SourceAccountId { get; set; } - public long DestinationAccountId { get; set; } - public decimal Amount { get; set; } - public DateTime Date { get; set; } - public string Type { get; set; } = String.Empty; +namespace Web.DTOs.Transaction; + +public class TransactionDto +{ + public long TransactionId { get; set; } + public long SourceAccountId { get; set; } + public long DestinationAccountId { get; set; } + public decimal Amount { get; set; } + public DateTime Date { get; set; } + public string Type { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/Web/Helper/Errors.cs b/src/Web/Helper/Errors.cs index 02f6d73..86b93b1 100644 --- a/src/Web/Helper/Errors.cs +++ b/src/Web/Helper/Errors.cs @@ -1,15 +1,15 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Web.Helper; - -public static class Errors -{ - public static Object New(string title, string message) - { - return new - { - title = title, - message = new List { message } - }; - } +using Microsoft.AspNetCore.Mvc; + +namespace Web.Helper; + +public static class Errors +{ + public static Object New(string title, string message) + { + return new + { + title = title, + message = new List { message } + }; + } } \ No newline at end of file diff --git a/src/Web/Identity/Claims.cs b/src/Web/Identity/Claims.cs index b0ff7b2..815b69b 100644 --- a/src/Web/Identity/Claims.cs +++ b/src/Web/Identity/Claims.cs @@ -1,7 +1,7 @@ -namespace Web.Identity; - -public static class Claims -{ - public const string UserId = nameof(UserId); - public const string Role = nameof(Role); +namespace Web.Identity; + +public static class Claims +{ + public const string UserId = nameof(UserId); + public const string Role = nameof(Role); } \ No newline at end of file diff --git a/src/Web/Identity/RequiresClaimAttribute.cs b/src/Web/Identity/RequiresClaimAttribute.cs index 8fbb713..035d96c 100644 --- a/src/Web/Identity/RequiresClaimAttribute.cs +++ b/src/Web/Identity/RequiresClaimAttribute.cs @@ -1,24 +1,24 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Web.Identity; - -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] -public class RequiresClaimAttribute : Attribute, IAuthorizationFilter -{ - private readonly string _claimName; - private readonly string _claimValue; - - public RequiresClaimAttribute(string claimName, string claimValue) - { - _claimName = claimName; - _claimValue = claimValue; - } - public void OnAuthorization(AuthorizationFilterContext context) - { - if (!context.HttpContext.User.HasClaim(_claimName, _claimValue)) - { - context.Result = new ForbidResult(); - } - } +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Web.Identity; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] +public class RequiresClaimAttribute : Attribute, IAuthorizationFilter +{ + private readonly string _claimName; + private readonly string _claimValue; + + public RequiresClaimAttribute(string claimName, string claimValue) + { + _claimName = claimName; + _claimValue = claimValue; + } + public void OnAuthorization(AuthorizationFilterContext context) + { + if (!context.HttpContext.User.HasClaim(_claimName, _claimValue)) + { + context.Result = new ForbidResult(); + } + } } \ No newline at end of file diff --git a/src/Web/Mappers/AccountMapper.cs b/src/Web/Mappers/AccountMapper.cs index efcf367..a05c625 100644 --- a/src/Web/Mappers/AccountMapper.cs +++ b/src/Web/Mappers/AccountMapper.cs @@ -1,24 +1,24 @@ -using Domain.Entities; -using Web.DTOs.Account; - -namespace Web.Mappers; - -public static class AccountMapper -{ - public static AccountDto ToAccountDto(this Account account) - { - return new AccountDto - { - AccountId = account.AccountId, - CardId = account.CardId, - Iban = account.Iban, - AccountType = account.AccountType, - BranchTelephone = account.BranchTelephone, - BranchAddress = account.BranchAddress, - BranchName = account.BranchName, - OwnerName = account.OwnerName, - OwnerLastName = account.OwnerLastName, - OwnerId = account.OwnerId - }; - } +using Domain.Entities; +using Web.DTOs.Account; + +namespace Web.Mappers; + +public static class AccountMapper +{ + public static AccountDto ToAccountDto(this Account account) + { + return new AccountDto + { + AccountId = account.AccountId, + CardId = account.CardId, + Iban = account.Iban, + AccountType = account.AccountType, + BranchTelephone = account.BranchTelephone, + BranchAddress = account.BranchAddress, + BranchName = account.BranchName, + OwnerName = account.OwnerName, + OwnerLastName = account.OwnerLastName, + OwnerId = account.OwnerId + }; + } } \ No newline at end of file diff --git a/src/Web/Mappers/IdentityMapper.cs b/src/Web/Mappers/IdentityMapper.cs index c82e83f..f46f5a7 100644 --- a/src/Web/Mappers/IdentityMapper.cs +++ b/src/Web/Mappers/IdentityMapper.cs @@ -1,65 +1,65 @@ -using Application.DTOs.Identity; -using Application.DTOs.Identity.ChangeRole; -using Web.DTOs.Identity; - -namespace Web.Mappers; - -public static class IdentityMapper -{ - public static CreateUserRequest ToCreateUserRequest(this SignupDto signupDto) - { - return new CreateUserRequest - { - FirstName = signupDto.FirstName, - LastName = signupDto.LastName, - Email = signupDto.Email, - UserName = signupDto.UserName, - Password = signupDto.Password, - Role = signupDto.Role - }; - } - - public static LoginUserRequest ToLoginUserRequest(this LoginDto loginDto) - { - return new LoginUserRequest - { - UserName = loginDto.UserName, - Email = loginDto.Email, - Password = loginDto.Password - }; - } - - public static UserSignedUpDto ToUserSignedUpDto(this CreateUserResponse createUserResponse) - { - return new UserSignedUpDto - { - FirstName = createUserResponse.FirstName, - LastName = createUserResponse.LastName, - Email = createUserResponse.Email, - UserName = createUserResponse.UserName, - Role = createUserResponse.Role - }; - } - - public static UserLoggedInDto ToUserLoggedInDto(this LoginUserResponse loginUserResponse) - { - return new UserLoggedInDto - { - FirstName = loginUserResponse.FirstName, - LastName = loginUserResponse.LastName, - Email = loginUserResponse.Email, - UserName = loginUserResponse.UserName, - Role = loginUserResponse.Role, - Token = loginUserResponse.Token - }; - } - - public static ChangeRoleRequest ToChangeRoleRequest(this ChangeRoleDto changeRoleDto) - { - return new ChangeRoleRequest - { - UserName = changeRoleDto.UserName, - Role = changeRoleDto.Role - }; - } +using Application.DTOs.Identity; +using Application.DTOs.Identity.ChangeRole; +using Web.DTOs.Identity; + +namespace Web.Mappers; + +public static class IdentityMapper +{ + public static CreateUserRequest ToCreateUserRequest(this SignupDto signupDto) + { + return new CreateUserRequest + { + FirstName = signupDto.FirstName, + LastName = signupDto.LastName, + Email = signupDto.Email, + UserName = signupDto.UserName, + Password = signupDto.Password, + Role = signupDto.Role + }; + } + + public static LoginUserRequest ToLoginUserRequest(this LoginDto loginDto) + { + return new LoginUserRequest + { + UserName = loginDto.UserName, + Email = loginDto.Email, + Password = loginDto.Password + }; + } + + public static UserSignedUpDto ToUserSignedUpDto(this CreateUserResponse createUserResponse) + { + return new UserSignedUpDto + { + FirstName = createUserResponse.FirstName, + LastName = createUserResponse.LastName, + Email = createUserResponse.Email, + UserName = createUserResponse.UserName, + Role = createUserResponse.Role + }; + } + + public static UserLoggedInDto ToUserLoggedInDto(this LoginUserResponse loginUserResponse) + { + return new UserLoggedInDto + { + FirstName = loginUserResponse.FirstName, + LastName = loginUserResponse.LastName, + Email = loginUserResponse.Email, + UserName = loginUserResponse.UserName, + Role = loginUserResponse.Role, + Token = loginUserResponse.Token + }; + } + + public static ChangeRoleRequest ToChangeRoleRequest(this ChangeRoleDto changeRoleDto) + { + return new ChangeRoleRequest + { + UserName = changeRoleDto.UserName, + Role = changeRoleDto.Role + }; + } } \ No newline at end of file diff --git a/src/Web/Mappers/ProfileMapper.cs b/src/Web/Mappers/ProfileMapper.cs index 61f007e..c359014 100644 --- a/src/Web/Mappers/ProfileMapper.cs +++ b/src/Web/Mappers/ProfileMapper.cs @@ -1,42 +1,42 @@ -using Application.DTOs.Identity; -using Application.DTOs.Profile.ChangePassword; -using Web.DTOs.Profile; - -namespace Web.Mappers; - -public static class ProfileMapper -{ - public static EditProfileInfoRequest ToEditProfileInfoRequest(this EditProfileInfoDto editProfileInfoDto, - string userId) - { - return new EditProfileInfoRequest - { - UserId = userId, - UserName = editProfileInfoDto.UserName, - FirstName = editProfileInfoDto.FirstName, - LastName = editProfileInfoDto.LastName, - }; - } - - public static ProfileInfoDto ToProfileInfoDto(this GetProfileInfoResponse getProfileInfoResponse) - { - return new ProfileInfoDto - { - FirstName = getProfileInfoResponse.FirstName, - LastName = getProfileInfoResponse.LastName, - Email = getProfileInfoResponse.Email, - UserName = getProfileInfoResponse.UserName, - Role = getProfileInfoResponse.Role - }; - } - - public static ChangePasswordRequest ToChangePasswordRequest(this ChangePasswordDto changePasswordDto, string userId) - { - return new ChangePasswordRequest - { - UserId = userId, - CurrentPassword = changePasswordDto.CurrentPassword, - NewPassword = changePasswordDto.NewPassword - }; - } +using Application.DTOs.Identity; +using Application.DTOs.Profile.ChangePassword; +using Web.DTOs.Profile; + +namespace Web.Mappers; + +public static class ProfileMapper +{ + public static EditProfileInfoRequest ToEditProfileInfoRequest(this EditProfileInfoDto editProfileInfoDto, + string userId) + { + return new EditProfileInfoRequest + { + UserId = userId, + UserName = editProfileInfoDto.UserName, + FirstName = editProfileInfoDto.FirstName, + LastName = editProfileInfoDto.LastName, + }; + } + + public static ProfileInfoDto ToProfileInfoDto(this GetProfileInfoResponse getProfileInfoResponse) + { + return new ProfileInfoDto + { + FirstName = getProfileInfoResponse.FirstName, + LastName = getProfileInfoResponse.LastName, + Email = getProfileInfoResponse.Email, + UserName = getProfileInfoResponse.UserName, + Role = getProfileInfoResponse.Role + }; + } + + public static ChangePasswordRequest ToChangePasswordRequest(this ChangePasswordDto changePasswordDto, string userId) + { + return new ChangePasswordRequest + { + UserId = userId, + CurrentPassword = changePasswordDto.CurrentPassword, + NewPassword = changePasswordDto.NewPassword + }; + } } \ No newline at end of file diff --git a/src/Web/Mappers/TransactionMapper.cs b/src/Web/Mappers/TransactionMapper.cs index 9fae733..6905884 100644 --- a/src/Web/Mappers/TransactionMapper.cs +++ b/src/Web/Mappers/TransactionMapper.cs @@ -1,33 +1,33 @@ -using Domain.Entities; -using Web.DTOs.Transaction; - -namespace Web.Mappers; - -public static class TransactionMapper -{ - public static TransactionDto ToTransactionDto(this Transaction transaction) - { - return new TransactionDto - { - TransactionId = transaction.TransactionId, - SourceAccountId = transaction.SourceAccountId, - DestinationAccountId = transaction.DestinationAccountId, - Amount = transaction.Amount, - Date = transaction.Date, - Type = transaction.Type - }; - } - - public static List ToGotAllTransactionsDto(this GetAllTransactionsResponse response) - { - return response.Transactions.Select(transaction => new GetAllTransactionsResponse.TransactionDto - { - TransactionId = transaction.TransactionId, - SourceAccountId = transaction.SourceAccountId, - DestinationAccountId = transaction.DestinationAccountId, - Amount = transaction.Amount, - Date = transaction.Date, - Type = transaction.Type - }).ToList(); - } +using Domain.Entities; +using Web.DTOs.Transaction; + +namespace Web.Mappers; + +public static class TransactionMapper +{ + public static TransactionDto ToTransactionDto(this Transaction transaction) + { + return new TransactionDto + { + TransactionId = transaction.TransactionId, + SourceAccountId = transaction.SourceAccountId, + DestinationAccountId = transaction.DestinationAccountId, + Amount = transaction.Amount, + Date = transaction.Date, + Type = transaction.Type + }; + } + + public static List ToGotAllTransactionsDto(this GetAllTransactionsResponse response) + { + return response.Transactions.Select(transaction => new GetAllTransactionsResponse.TransactionDto + { + TransactionId = transaction.TransactionId, + SourceAccountId = transaction.SourceAccountId, + DestinationAccountId = transaction.DestinationAccountId, + Amount = transaction.Amount, + Date = transaction.Date, + Type = transaction.Type + }).ToList(); + } } \ No newline at end of file diff --git a/src/Web/Program.cs b/src/Web/Program.cs index bba03b1..6a5f0a3 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -1,132 +1,132 @@ -using System.Text; -using Application.Interfaces; -using Application.Interfaces.Services; -using Application.Services; -using Domain.Entities; -using Infrastructure.Data; -using Infrastructure.Services; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; -using Microsoft.OpenApi.Models; -using Web.Interfaces; -using Web.Services; -using Web.Startup; - -var builder = WebApplication.CreateBuilder(args); -var config = builder.Configuration; - -// Add services to the container. -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); -builder.Services.AddControllers(); -builder.Services.AddDbContext(options => -{ - options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")); -}); -builder.Services.AddIdentity() - .AddEntityFrameworkStores(); - -builder.Services.AddAuthentication(x => -{ - x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; -}).AddJwtBearer(x => -{ - x.TokenValidationParameters = new TokenValidationParameters - { - ValidIssuer = config["JwtSettings:Issuer"], - ValidAudience = config["JwtSettings:Audience"], - IssuerSigningKey = new SymmetricSecurityKey( - Encoding.UTF8.GetBytes(config["JwtSettings:Key"]!)), - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = true, - ValidateIssuerSigningKey = true - }; -}); - -builder.Services.AddAuthorization(); - -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - -builder.Services.AddControllers().AddNewtonsoftJson(options => -{ - options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; -}); - -builder.Services.AddSwaggerGen(opt => -{ - opt.SwaggerDoc("v1", new OpenApiInfo { Title = "MyAPI", Version = "v1" }); - opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme - { - In = ParameterLocation.Header, - Description = "Please enter token", - Name = "Authorization", - Type = SecuritySchemeType.Http, - BearerFormat = "JWT", - Scheme = "bearer" - }); - - opt.AddSecurityRequirement(new OpenApiSecurityRequirement - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type=ReferenceType.SecurityScheme, - Id="Bearer" - } - }, - new string[]{} - } - }); - - -}); - -builder.Services.AddCors(options => -{ - options.AddPolicy("AllowSpecificOrigins", corsPolicyBuilder => - { - corsPolicyBuilder.WithOrigins("http://localhost:4200") - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); -}); - -var app = builder.Build(); - -using (var scope = app.Services.CreateScope()) -{ - var services = scope.ServiceProvider; - await SeedData.Initialize(services, config); -} - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} -app.UseHttpsRedirection(); -app.UseCors("AllowSpecificOrigins"); -app.UseAuthentication(); -app.UseAuthorization(); - - -app.MapControllers(); +using System.Text; +using Application.Interfaces; +using Application.Interfaces.Services; +using Application.Services; +using Domain.Entities; +using Infrastructure.Data; +using Infrastructure.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using Web.Interfaces; +using Web.Services; +using Web.Startup; + +var builder = WebApplication.CreateBuilder(args); +var config = builder.Configuration; + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +builder.Services.AddControllers(); +builder.Services.AddDbContext(options => +{ + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")); +}); +builder.Services.AddIdentity() + .AddEntityFrameworkStores(); + +builder.Services.AddAuthentication(x => +{ + x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; +}).AddJwtBearer(x => +{ + x.TokenValidationParameters = new TokenValidationParameters + { + ValidIssuer = config["JwtSettings:Issuer"], + ValidAudience = config["JwtSettings:Audience"], + IssuerSigningKey = new SymmetricSecurityKey( + Encoding.UTF8.GetBytes(config["JwtSettings:Key"]!)), + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true + }; +}); + +builder.Services.AddAuthorization(); + +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +builder.Services.AddControllers().AddNewtonsoftJson(options => +{ + options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; +}); + +builder.Services.AddSwaggerGen(opt => +{ + opt.SwaggerDoc("v1", new OpenApiInfo { Title = "MyAPI", Version = "v1" }); + opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + Description = "Please enter token", + Name = "Authorization", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT", + Scheme = "bearer" + }); + + opt.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type=ReferenceType.SecurityScheme, + Id="Bearer" + } + }, + new string[]{} + } + }); + + +}); + +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowSpecificOrigins", corsPolicyBuilder => + { + corsPolicyBuilder.WithOrigins("http://localhost:4200") + .AllowAnyHeader() + .AllowAnyMethod() + .AllowCredentials(); + }); +}); + +var app = builder.Build(); + +using (var scope = app.Services.CreateScope()) +{ + var services = scope.ServiceProvider; + await SeedData.Initialize(services, config); +} + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} +app.UseHttpsRedirection(); +app.UseCors("AllowSpecificOrigins"); +app.UseAuthentication(); +app.UseAuthorization(); + + +app.MapControllers(); app.Run(); \ No newline at end of file diff --git a/src/Web/Properties/launchSettings.json b/src/Web/Properties/launchSettings.json index 84fb0e0..b2dcfc4 100644 --- a/src/Web/Properties/launchSettings.json +++ b/src/Web/Properties/launchSettings.json @@ -1,41 +1,41 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:21960", - "sslPort": 44337 - } - }, - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5236", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7018;http://localhost:5236", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:21960", + "sslPort": 44337 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5236", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7018;http://localhost:5236", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Web/Services/JwtGeneratorService.cs b/src/Web/Services/JwtGeneratorService.cs index 42784a8..1284228 100644 --- a/src/Web/Services/JwtGeneratorService.cs +++ b/src/Web/Services/JwtGeneratorService.cs @@ -1,45 +1,45 @@ -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; -using Domain.Entities; -using Microsoft.IdentityModel.Tokens; -using Web.Identity; -using Web.Interfaces; - -namespace Web.Services; - -public class JwtGeneratorService : IJwtGenerator -{ - private readonly IConfiguration _configuration; - private readonly SymmetricSecurityKey _symmetricSecurityKey; - public JwtGeneratorService(IConfiguration configuration) - { - _configuration = configuration; - _symmetricSecurityKey = new SymmetricSecurityKey( - System.Text.Encoding.UTF8.GetBytes(_configuration["JwtSettings:Key"]) - ); - } - public string GenerateToken(AppUser user, string role) - { - var claims = new List - { - new Claim(JwtRegisteredClaimNames.Sub, user.Email), - new Claim(Claims.UserId, user.Id), - new Claim(Claims.Role, role) - }; - - var credentials = new SigningCredentials(_symmetricSecurityKey, SecurityAlgorithms.HmacSha512Signature); - - var tokenDescriptor = new SecurityTokenDescriptor - { - Subject = new ClaimsIdentity(claims), - Expires = DateTime.Now.AddHours(8), - SigningCredentials = credentials, - Issuer = _configuration["JwtSettings:Issuer"], - Audience = _configuration["JwtSettings:Audience"] - }; - - var tokenHandler = new JwtSecurityTokenHandler(); - var token = tokenHandler.CreateToken(tokenDescriptor); - return tokenHandler.WriteToken(token); - } +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using Domain.Entities; +using Microsoft.IdentityModel.Tokens; +using Web.Identity; +using Web.Interfaces; + +namespace Web.Services; + +public class JwtGeneratorService : IJwtGenerator +{ + private readonly IConfiguration _configuration; + private readonly SymmetricSecurityKey _symmetricSecurityKey; + public JwtGeneratorService(IConfiguration configuration) + { + _configuration = configuration; + _symmetricSecurityKey = new SymmetricSecurityKey( + System.Text.Encoding.UTF8.GetBytes(_configuration["JwtSettings:Key"]) + ); + } + public string GenerateToken(AppUser user, string role) + { + var claims = new List + { + new Claim(JwtRegisteredClaimNames.Sub, user.Email), + new Claim(Claims.UserId, user.Id), + new Claim(Claims.Role, role) + }; + + var credentials = new SigningCredentials(_symmetricSecurityKey, SecurityAlgorithms.HmacSha512Signature); + + var tokenDescriptor = new SecurityTokenDescriptor + { + Subject = new ClaimsIdentity(claims), + Expires = DateTime.Now.AddHours(8), + SigningCredentials = credentials, + Issuer = _configuration["JwtSettings:Issuer"], + Audience = _configuration["JwtSettings:Audience"] + }; + + var tokenHandler = new JwtSecurityTokenHandler(); + var token = tokenHandler.CreateToken(tokenDescriptor); + return tokenHandler.WriteToken(token); + } } \ No newline at end of file diff --git a/src/Web/Startup/SeedData.cs b/src/Web/Startup/SeedData.cs index dd79cca..283627a 100644 --- a/src/Web/Startup/SeedData.cs +++ b/src/Web/Startup/SeedData.cs @@ -1,45 +1,45 @@ -using Domain.Entities; -using Microsoft.AspNetCore.Identity; - -namespace Web.Startup; - -public static class SeedData -{ - public static async Task Initialize(IServiceProvider serviceProvider, IConfigurationManager config) - { - var userManager = serviceProvider.GetRequiredService>(); - var roleManager = serviceProvider.GetRequiredService>(); - - var id = config["RootUser:Id"]!; - var roleName = config["RootUser:RoleName"]!; - var userName = config["RootUser:UserName"]!; - var email = config["RootUser:Email"]; - var password = config["RootUser:Password"]!; - - // Check if the root user already exists - var rootUser = await userManager.FindByIdAsync(id); - if (rootUser == null) - { - // Create the root user - rootUser = new AppUser - { - Id = id, - UserName = userName, - Email = email, - EmailConfirmed = true - }; - var result = await userManager.CreateAsync(rootUser, password); - - if (!result.Succeeded) - { - throw new Exception("Failed to create root user"); - } - - var roleResult = await userManager.AddToRoleAsync(rootUser, roleName); - if (!roleResult.Succeeded) - { - throw new Exception("Failed to add to role"); - } - } - } -} +using Domain.Entities; +using Microsoft.AspNetCore.Identity; + +namespace Web.Startup; + +public static class SeedData +{ + public static async Task Initialize(IServiceProvider serviceProvider, IConfigurationManager config) + { + var userManager = serviceProvider.GetRequiredService>(); + var roleManager = serviceProvider.GetRequiredService>(); + + var id = config["RootUser:Id"]!; + var roleName = config["RootUser:RoleName"]!; + var userName = config["RootUser:UserName"]!; + var email = config["RootUser:Email"]; + var password = config["RootUser:Password"]!; + + // Check if the root user already exists + var rootUser = await userManager.FindByIdAsync(id); + if (rootUser == null) + { + // Create the root user + rootUser = new AppUser + { + Id = id, + UserName = userName, + Email = email, + EmailConfirmed = true + }; + var result = await userManager.CreateAsync(rootUser, password); + + if (!result.Succeeded) + { + throw new Exception("Failed to create root user"); + } + + var roleResult = await userManager.AddToRoleAsync(rootUser, roleName); + if (!roleResult.Succeeded) + { + throw new Exception("Failed to add to role"); + } + } + } +} diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 24a4eda..f8bdcca 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -1,27 +1,27 @@ - - - - net8.0 - enable - enable - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - + + + + net8.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/src/Web/appsettings.Development.json b/src/Web/appsettings.Development.json index 0c208ae..ff66ba6 100644 --- a/src/Web/appsettings.Development.json +++ b/src/Web/appsettings.Development.json @@ -1,8 +1,8 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/Web/appsettings.json b/src/Web/appsettings.json index 1004e11..d89dd5b 100644 --- a/src/Web/appsettings.json +++ b/src/Web/appsettings.json @@ -1,24 +1,24 @@ -{ - "ConnectionStrings": { - "DefaultConnection": "Server=127.0.0.1;Port=5432;Database=KakaSiah;User Id=postgres;Password=postgres;" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*", - "JwtSettings": { - "Issuer": "http://localhost:5000", - "Audience": "http://localhost:5000", - "Key": "sjmcabnishcpasichquwh108hd29dh12wcf1hni1nci9vh9p920u1dhx08122hiokasnx89" - }, - "RootUser": { - "Id": "d2228d10-5be9-40dd-9c20-6a19343a963a", - "RoleName": "Admin", - "UserName": "root", - "Email": "root@example.com", - "Password": "Root@123" - } +{ + "ConnectionStrings": { + "DefaultConnection": "Server=127.0.0.1;Port=5432;Database=KakaSiah;User Id=postgres;Password=postgres;" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "JwtSettings": { + "Issuer": "http://localhost:5000", + "Audience": "http://localhost:5000", + "Key": "sjmcabnishcpasichquwh108hd29dh12wcf1hni1nci9vh9p920u1dhx08122hiokasnx89" + }, + "RootUser": { + "Id": "d2228d10-5be9-40dd-9c20-6a19343a963a", + "RoleName": "Admin", + "UserName": "root", + "Email": "root@example.com", + "Password": "Root@123" + } } \ No newline at end of file