From ef5f23f3a526fec1e8d2bd08f53a9d5f2c1e0add Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 8 Jun 2025 23:24:45 +0400 Subject: [PATCH] =?UTF-8?q?2=20=D1=87=D0=B0=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApplicationSystem.Contracts.csproj | 9 + .../Models/UserRequests/LoginRequest.cs | 23 ++ .../Models/UserRequests/LogoutRequest.cs | 6 + .../Models/UserRequests/RegisterRequest.cs | 25 ++ .../ApplicationSystem.Identity.csproj | 4 - .../Database/Context/IdentityContext.cs | 4 + .../20250608181053_InitDatabase.Designer.cs | 279 ++++++++++++++++++ .../Migrations/20250608181053_InitDatabase.cs | 254 ++++++++++++++++ .../IdentityContextModelSnapshot.cs | 276 +++++++++++++++++ .../ApplicationSystem.MediatRHelper.csproj | 13 + .../Models/IRequestModel.cs | 11 + .../Models/IRequestModelWP.cs | 11 + .../Models/ResponseModel.cs | 13 + .../Models/ResponseModelWP.cs | 15 + ApplicationSystem.sln | 14 +- ApplicationSystem/ApplicationSystem.csproj | 6 + ...ontroller.cs => ApplicationsController.cs} | 2 +- .../Controllers/UsersController.cs | 18 ++ .../Models/Queries/LoginQuery.cs | 11 + 19 files changed, 988 insertions(+), 6 deletions(-) create mode 100644 ApplicationSystem.Contracts/ApplicationSystem.Contracts.csproj create mode 100644 ApplicationSystem.Contracts/Models/UserRequests/LoginRequest.cs create mode 100644 ApplicationSystem.Contracts/Models/UserRequests/LogoutRequest.cs create mode 100644 ApplicationSystem.Contracts/Models/UserRequests/RegisterRequest.cs create mode 100644 ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.Designer.cs create mode 100644 ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.cs create mode 100644 ApplicationSystem.Identity/Database/Migrations/IdentityContextModelSnapshot.cs create mode 100644 ApplicationSystem.MediatrHelper/ApplicationSystem.MediatRHelper.csproj create mode 100644 ApplicationSystem.MediatrHelper/Models/IRequestModel.cs create mode 100644 ApplicationSystem.MediatrHelper/Models/IRequestModelWP.cs create mode 100644 ApplicationSystem.MediatrHelper/Models/ResponseModel.cs create mode 100644 ApplicationSystem.MediatrHelper/Models/ResponseModelWP.cs rename ApplicationSystem/Controllers/{ApplicationController.cs => ApplicationsController.cs} (95%) create mode 100644 ApplicationSystem/Controllers/UsersController.cs create mode 100644 ApplicationSystem/Models/Queries/LoginQuery.cs diff --git a/ApplicationSystem.Contracts/ApplicationSystem.Contracts.csproj b/ApplicationSystem.Contracts/ApplicationSystem.Contracts.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/ApplicationSystem.Contracts/ApplicationSystem.Contracts.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/ApplicationSystem.Contracts/Models/UserRequests/LoginRequest.cs b/ApplicationSystem.Contracts/Models/UserRequests/LoginRequest.cs new file mode 100644 index 0000000..789a4ca --- /dev/null +++ b/ApplicationSystem.Contracts/Models/UserRequests/LoginRequest.cs @@ -0,0 +1,23 @@ +using ApplicationSystem.MediatRHelper.Models; +using System.ComponentModel.DataAnnotations; + +namespace ApplicationSystem.Contracts.Models.UserRequests +{ + /// + /// Запрос на вход + /// + public record LoginRequest + { + /// + /// Логин пользователя + /// + [Required(AllowEmptyStrings = false)] + public string Email { get; init; } = null!; + + /// + /// Пароль пользователя + /// + [Required(AllowEmptyStrings = false)] + public string Password { get; init; } = null!; + } +} diff --git a/ApplicationSystem.Contracts/Models/UserRequests/LogoutRequest.cs b/ApplicationSystem.Contracts/Models/UserRequests/LogoutRequest.cs new file mode 100644 index 0000000..781a65f --- /dev/null +++ b/ApplicationSystem.Contracts/Models/UserRequests/LogoutRequest.cs @@ -0,0 +1,6 @@ +namespace ApplicationSystem.Contracts.Models.UserRequests +{ + public class LogoutRequest + { + } +} diff --git a/ApplicationSystem.Contracts/Models/UserRequests/RegisterRequest.cs b/ApplicationSystem.Contracts/Models/UserRequests/RegisterRequest.cs new file mode 100644 index 0000000..f98818e --- /dev/null +++ b/ApplicationSystem.Contracts/Models/UserRequests/RegisterRequest.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; + +namespace ApplicationSystem.Contracts.Models.UserRequests +{ + public class RegisterRequest + { + /// + /// Логин пользователя + /// + [Required(AllowEmptyStrings = false)] + public string Email { get; init; } = null!; + + /// + /// Пароль пользователя + /// + [Required(AllowEmptyStrings = false)] + public string Password { get; init; } = null!; + + /// + /// Имя пользователя + /// + [Required(AllowEmptyStrings = false)] + public string UserName { get; init; } = null!; + } +} diff --git a/ApplicationSystem.Identity/ApplicationSystem.Identity.csproj b/ApplicationSystem.Identity/ApplicationSystem.Identity.csproj index 945bd1c..c14053e 100644 --- a/ApplicationSystem.Identity/ApplicationSystem.Identity.csproj +++ b/ApplicationSystem.Identity/ApplicationSystem.Identity.csproj @@ -7,10 +7,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all diff --git a/ApplicationSystem.Identity/Database/Context/IdentityContext.cs b/ApplicationSystem.Identity/Database/Context/IdentityContext.cs index 72bf614..9bc1364 100644 --- a/ApplicationSystem.Identity/Database/Context/IdentityContext.cs +++ b/ApplicationSystem.Identity/Database/Context/IdentityContext.cs @@ -15,6 +15,10 @@ namespace ApplicationSystem.Identity.Database.Context IdentityRoleClaim, IdentityUserToken> { + public IdentityContext(DbContextOptions options) : base(options) + { + } + protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); diff --git a/ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.Designer.cs b/ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.Designer.cs new file mode 100644 index 0000000..cd407e0 --- /dev/null +++ b/ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.Designer.cs @@ -0,0 +1,279 @@ +// +using System; +using ApplicationSystem.Identity.Database.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ApplicationSystem.Identity.Database.Migrations +{ + [DbContext(typeof(IdentityContext))] + [Migration("20250608181053_InitDatabase")] + partial class InitDatabase + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("identity") + .HasAnnotation("ProductVersion", "8.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ApplicationSystem.Identity.Database.Models.ApplicationSystemRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("role", "identity"); + }); + + modelBuilder.Entity("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("user", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("role_claim", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_claim", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("user_login", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("user_role", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("user_token", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.cs b/ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.cs new file mode 100644 index 0000000..d35cd28 --- /dev/null +++ b/ApplicationSystem.Identity/Database/Migrations/20250608181053_InitDatabase.cs @@ -0,0 +1,254 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ApplicationSystem.Identity.Database.Migrations +{ + /// + public partial class InitDatabase : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "identity"); + + migrationBuilder.CreateTable( + name: "role", + schema: "identity", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + schema: "identity", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "bit", nullable: false), + PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), + SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), + TwoFactorEnabled = table.Column(type: "bit", nullable: false), + LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), + LockoutEnabled = table.Column(type: "bit", nullable: false), + AccessFailedCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_claim", + schema: "identity", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_role_claim", x => x.Id); + table.ForeignKey( + name: "FK_role_claim_role_RoleId", + column: x => x.RoleId, + principalSchema: "identity", + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_claim", + schema: "identity", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "uniqueidentifier", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_user_claim", x => x.Id); + table.ForeignKey( + name: "FK_user_claim_user_UserId", + column: x => x.UserId, + principalSchema: "identity", + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_login", + schema: "identity", + columns: table => new + { + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), + ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_login", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_user_login_user_UserId", + column: x => x.UserId, + principalSchema: "identity", + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + schema: "identity", + columns: table => new + { + UserId = table.Column(type: "uniqueidentifier", nullable: false), + RoleId = table.Column(type: "uniqueidentifier", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_role_RoleId", + column: x => x.RoleId, + principalSchema: "identity", + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalSchema: "identity", + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_token", + schema: "identity", + columns: table => new + { + UserId = table.Column(type: "uniqueidentifier", nullable: false), + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(450)", nullable: false), + Value = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_user_token", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_user_token_user_UserId", + column: x => x.UserId, + principalSchema: "identity", + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + schema: "identity", + table: "role", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_role_claim_RoleId", + schema: "identity", + table: "role_claim", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + schema: "identity", + table: "user", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + schema: "identity", + table: "user", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_user_claim_UserId", + schema: "identity", + table: "user_claim", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_login_UserId", + schema: "identity", + table: "user_login", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_role_RoleId", + schema: "identity", + table: "user_role", + column: "RoleId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "role_claim", + schema: "identity"); + + migrationBuilder.DropTable( + name: "user_claim", + schema: "identity"); + + migrationBuilder.DropTable( + name: "user_login", + schema: "identity"); + + migrationBuilder.DropTable( + name: "user_role", + schema: "identity"); + + migrationBuilder.DropTable( + name: "user_token", + schema: "identity"); + + migrationBuilder.DropTable( + name: "role", + schema: "identity"); + + migrationBuilder.DropTable( + name: "user", + schema: "identity"); + } + } +} diff --git a/ApplicationSystem.Identity/Database/Migrations/IdentityContextModelSnapshot.cs b/ApplicationSystem.Identity/Database/Migrations/IdentityContextModelSnapshot.cs new file mode 100644 index 0000000..86c9314 --- /dev/null +++ b/ApplicationSystem.Identity/Database/Migrations/IdentityContextModelSnapshot.cs @@ -0,0 +1,276 @@ +// +using System; +using ApplicationSystem.Identity.Database.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ApplicationSystem.Identity.Database.Migrations +{ + [DbContext(typeof(IdentityContext))] + partial class IdentityContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("identity") + .HasAnnotation("ProductVersion", "8.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ApplicationSystem.Identity.Database.Models.ApplicationSystemRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("role", "identity"); + }); + + modelBuilder.Entity("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("user", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("role_claim", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_claim", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("user_login", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("user_role", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("user_token", "identity"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("ApplicationSystem.Identity.Database.Models.ApplicationSystemUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ApplicationSystem.MediatrHelper/ApplicationSystem.MediatRHelper.csproj b/ApplicationSystem.MediatrHelper/ApplicationSystem.MediatRHelper.csproj new file mode 100644 index 0000000..ec79322 --- /dev/null +++ b/ApplicationSystem.MediatrHelper/ApplicationSystem.MediatRHelper.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/ApplicationSystem.MediatrHelper/Models/IRequestModel.cs b/ApplicationSystem.MediatrHelper/Models/IRequestModel.cs new file mode 100644 index 0000000..5bd7a6e --- /dev/null +++ b/ApplicationSystem.MediatrHelper/Models/IRequestModel.cs @@ -0,0 +1,11 @@ +using MediatR; + +namespace ApplicationSystem.MediatRHelper.Models +{ + /// + /// Запрос к медиатору + /// + public interface IRequestModel : IRequest + { + } +} diff --git a/ApplicationSystem.MediatrHelper/Models/IRequestModelWP.cs b/ApplicationSystem.MediatrHelper/Models/IRequestModelWP.cs new file mode 100644 index 0000000..bd8d68b --- /dev/null +++ b/ApplicationSystem.MediatrHelper/Models/IRequestModelWP.cs @@ -0,0 +1,11 @@ +using MediatR; + +namespace ApplicationSystem.MediatRHelper.Models +{ + /// + /// Запрос к медиатору без параметров + /// + public interface IRequestModelWP : IRequest + { + } +} diff --git a/ApplicationSystem.MediatrHelper/Models/ResponseModel.cs b/ApplicationSystem.MediatrHelper/Models/ResponseModel.cs new file mode 100644 index 0000000..9e6ea74 --- /dev/null +++ b/ApplicationSystem.MediatrHelper/Models/ResponseModel.cs @@ -0,0 +1,13 @@ +namespace ApplicationSystem.MediatRHelper.Models +{ + /// + /// Модель результата выполнения запроса с возвращаемым значением + /// + public class ResponseModel : ResponseModel + { + /// + /// Результат успешного выполнения запроса + /// + public TResponse? Response { get; set; } + } +} diff --git a/ApplicationSystem.MediatrHelper/Models/ResponseModelWP.cs b/ApplicationSystem.MediatrHelper/Models/ResponseModelWP.cs new file mode 100644 index 0000000..4fccc94 --- /dev/null +++ b/ApplicationSystem.MediatrHelper/Models/ResponseModelWP.cs @@ -0,0 +1,15 @@ +using System.Net; + +namespace ApplicationSystem.MediatRHelper.Models +{ + /// + /// Модель результата выполнения запроса + /// + public class ResponseModel + { + /// + /// Код результата обработки запроса + /// + public HttpStatusCode ResponseStatusCode; + } +} diff --git a/ApplicationSystem.sln b/ApplicationSystem.sln index 1e1b274..00d936e 100644 --- a/ApplicationSystem.sln +++ b/ApplicationSystem.sln @@ -9,7 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationSystem.Database" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationSystem.Identity", "ApplicationSystem.Identity\ApplicationSystem.Identity.csproj", "{73E95BBE-82B6-4DD6-BA95-BC3A52E79394}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationSystem.Configurations", "ApplicationSystem.Configurations\ApplicationSystem.Configurations.csproj", "{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationSystem.Configurations", "ApplicationSystem.Configurations\ApplicationSystem.Configurations.csproj", "{F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationSystem.Contracts", "ApplicationSystem.Contracts\ApplicationSystem.Contracts.csproj", "{353055EF-FE25-4DA2-9B6F-A6E8757C18A1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationSystem.MediatRHelper", "ApplicationSystem.MediatrHelper\ApplicationSystem.MediatRHelper.csproj", "{13F17CD8-F011-4C5F-9052-674E9CA73C81}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +37,14 @@ Global {F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Debug|Any CPU.Build.0 = Debug|Any CPU {F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Release|Any CPU.ActiveCfg = Release|Any CPU {F8BF79B4-B8C9-4A31-A9C7-4C1AB4C66E76}.Release|Any CPU.Build.0 = Release|Any CPU + {353055EF-FE25-4DA2-9B6F-A6E8757C18A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {353055EF-FE25-4DA2-9B6F-A6E8757C18A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {353055EF-FE25-4DA2-9B6F-A6E8757C18A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {353055EF-FE25-4DA2-9B6F-A6E8757C18A1}.Release|Any CPU.Build.0 = Release|Any CPU + {13F17CD8-F011-4C5F-9052-674E9CA73C81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13F17CD8-F011-4C5F-9052-674E9CA73C81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13F17CD8-F011-4C5F-9052-674E9CA73C81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13F17CD8-F011-4C5F-9052-674E9CA73C81}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ApplicationSystem/ApplicationSystem.csproj b/ApplicationSystem/ApplicationSystem.csproj index e91f630..35deb01 100644 --- a/ApplicationSystem/ApplicationSystem.csproj +++ b/ApplicationSystem/ApplicationSystem.csproj @@ -9,10 +9,16 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/ApplicationSystem/Controllers/ApplicationController.cs b/ApplicationSystem/Controllers/ApplicationsController.cs similarity index 95% rename from ApplicationSystem/Controllers/ApplicationController.cs rename to ApplicationSystem/Controllers/ApplicationsController.cs index 9b47366..d9b9b8b 100644 --- a/ApplicationSystem/Controllers/ApplicationController.cs +++ b/ApplicationSystem/Controllers/ApplicationsController.cs @@ -6,7 +6,7 @@ namespace ApplicationSystem.Controllers [ApiController] [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/[controller]")] - public class ApplicationController : ControllerBase + public class ApplicationsController : ControllerBase { [HttpPost] public async Task CreateApplicationAsync() diff --git a/ApplicationSystem/Controllers/UsersController.cs b/ApplicationSystem/Controllers/UsersController.cs new file mode 100644 index 0000000..a6d8e33 --- /dev/null +++ b/ApplicationSystem/Controllers/UsersController.cs @@ -0,0 +1,18 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Mvc; + +namespace ApplicationSystem.Controllers +{ + [ApiController] + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]")] + public class UsersController : ControllerBase + { + [HttpPost("login")] + public async Task LoginAsync() + { + await Task.Delay(100); + return Ok(); + } + } +} diff --git a/ApplicationSystem/Models/Queries/LoginQuery.cs b/ApplicationSystem/Models/Queries/LoginQuery.cs new file mode 100644 index 0000000..84cbe4c --- /dev/null +++ b/ApplicationSystem/Models/Queries/LoginQuery.cs @@ -0,0 +1,11 @@ +using ApplicationSystem.MediatRHelper.Models; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.Data; + +namespace ApplicationSystem.Models.Queries +{ + public record LoginQuery : IRequestModel + { + public LoginRequest LoginRequest { get; init; } = null!; + } +}