diff --git a/Infrastructure/AppDbContext.cs b/Infrastructure/AppDbContext.cs index bd251a6..aa2e6ef 100644 --- a/Infrastructure/AppDbContext.cs +++ b/Infrastructure/AppDbContext.cs @@ -1,10 +1,12 @@ using Domain.AggregateModel.AppAggregate; using Domain.AggregateModel.LinkAggregate; using Domain.SeedWork; +using Infrastructure.EntityConfigurations; using MediatR; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Storage; +using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using System; using System.Collections.Generic; using System.Data; @@ -34,13 +36,8 @@ namespace Infrastructure } protected override void OnModelCreating(ModelBuilder modelBuilder) { - //modelBuilder.ApplyConfiguration(new ClientRequestEntityTypeConfiguration()); - //modelBuilder.ApplyConfiguration(new PaymentMethodEntityTypeConfiguration()); - //modelBuilder.ApplyConfiguration(new OrderEntityTypeConfiguration()); - //modelBuilder.ApplyConfiguration(new OrderItemEntityTypeConfiguration()); - //modelBuilder.ApplyConfiguration(new CardTypeEntityTypeConfiguration()); - //modelBuilder.ApplyConfiguration(new OrderStatusEntityTypeConfiguration()); - //modelBuilder.ApplyConfiguration(new BuyerEntityTypeConfiguration()); + modelBuilder.ApplyConfiguration(new AppEntityTypeConfiguration()); + modelBuilder.ApplyConfiguration(new LinkEntityTypeConfiguration()); } @@ -114,7 +111,16 @@ namespace Infrastructure public AppDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder() - .UseMySql("Server=localhost;Database=qrcode;Uid=root;Pwd=root;"); + .UseMySql( + "server=localhost;user=root;password=root;database=qrcode", + // For common usages, see pull request #1233. + new MariaDbServerVersion(new Version(10, 5, 9)), // use MariaDbServerVersion for MariaDB + mySqlOptions => mySqlOptions + .CharSetBehavior(CharSetBehavior.NeverAppend) + .MigrationsAssembly("QRCodeService")) + // Everything from this point on is optional but helps with debugging. + .EnableSensitiveDataLogging() + .EnableDetailedErrors(); return new AppDbContext(optionsBuilder.Options, new NoMediator()); } diff --git a/Infrastructure/EntityConfigurations/LinkEntityTypeConfiguration.cs b/Infrastructure/EntityConfigurations/LinkEntityTypeConfiguration.cs index d3caaec..2887e0c 100644 --- a/Infrastructure/EntityConfigurations/LinkEntityTypeConfiguration.cs +++ b/Infrastructure/EntityConfigurations/LinkEntityTypeConfiguration.cs @@ -14,9 +14,11 @@ namespace Infrastructure.EntityConfigurations public void Configure(EntityTypeBuilder builder) { builder.ToTable("Link"); - builder.HasKey(l => l.ShortCode); + builder.HasKey(l => l.Id); + builder.HasIndex(l => l.ShortCode).IsUnique(); builder.Ignore(l => l.DomainEvents); builder.Property(l => l.AppId).IsRequired(); + builder.Property(l => l.ShortCode).HasMaxLength(11); } } } diff --git a/Infrastructure/Infrastructure.csproj b/Infrastructure/Infrastructure.csproj index 0196593..cf14200 100644 --- a/Infrastructure/Infrastructure.csproj +++ b/Infrastructure/Infrastructure.csproj @@ -11,11 +11,12 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + + - + \ No newline at end of file diff --git a/QRCodeService/Controllers/AppController.cs b/QRCodeService/Controllers/AppController.cs new file mode 100644 index 0000000..c75a6f4 --- /dev/null +++ b/QRCodeService/Controllers/AppController.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QRCodeService.Controllers +{ + [Route("api/v1/[controller]")] + public class AppController:ControllerBase + { + + } +} diff --git a/QRCodeService/Migrations/20210224014442_InitialCreate.Designer.cs b/QRCodeService/Migrations/20210224014442_InitialCreate.Designer.cs new file mode 100644 index 0000000..a28fa63 --- /dev/null +++ b/QRCodeService/Migrations/20210224014442_InitialCreate.Designer.cs @@ -0,0 +1,73 @@ +// +using System; +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace QRCodeService.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20210224014442_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("Domain.AggregateModel.AppAggregate.App", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppKey") + .HasColumnType("longtext"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("Remarks") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Apps"); + }); + + modelBuilder.Entity("Domain.AggregateModel.LinkAggregate.Link", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppId") + .HasColumnType("int"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("FullUrl") + .HasColumnType("longtext"); + + b.Property("ShortCode") + .HasColumnType("longtext"); + + b.Property("SuffixUrl") + .HasColumnType("longtext"); + + b.Property("Time") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.ToTable("Links"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/QRCodeService/Migrations/20210224014442_InitialCreate.cs b/QRCodeService/Migrations/20210224014442_InitialCreate.cs new file mode 100644 index 0000000..a0ba1ac --- /dev/null +++ b/QRCodeService/Migrations/20210224014442_InitialCreate.cs @@ -0,0 +1,54 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace QRCodeService.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Apps", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + AppKey = table.Column(type: "longtext", nullable: true), + BaseUrl = table.Column(type: "longtext", nullable: true), + Remarks = table.Column(type: "longtext", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Apps", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Links", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + ShortCode = table.Column(type: "longtext", nullable: true), + BaseUrl = table.Column(type: "longtext", nullable: true), + SuffixUrl = table.Column(type: "longtext", nullable: true), + FullUrl = table.Column(type: "longtext", nullable: true), + AppId = table.Column(type: "int", nullable: false), + Time = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Links", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Apps"); + + migrationBuilder.DropTable( + name: "Links"); + } + } +} diff --git a/QRCodeService/Migrations/20210224015439_AddConfiguration.Designer.cs b/QRCodeService/Migrations/20210224015439_AddConfiguration.Designer.cs new file mode 100644 index 0000000..1643455 --- /dev/null +++ b/QRCodeService/Migrations/20210224015439_AddConfiguration.Designer.cs @@ -0,0 +1,72 @@ +// +using System; +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace QRCodeService.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20210224015439_AddConfiguration")] + partial class AddConfiguration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("Domain.AggregateModel.AppAggregate.App", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppKey") + .HasColumnType("longtext"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("Remarks") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("App"); + }); + + modelBuilder.Entity("Domain.AggregateModel.LinkAggregate.Link", b => + { + b.Property("ShortCode") + .HasColumnType("varchar(255)"); + + b.Property("AppId") + .HasColumnType("int"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("FullUrl") + .HasColumnType("longtext"); + + b.Property("Id") + .HasColumnType("int"); + + b.Property("SuffixUrl") + .HasColumnType("longtext"); + + b.Property("Time") + .HasColumnType("datetime(6)"); + + b.HasKey("ShortCode"); + + b.ToTable("Link"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/QRCodeService/Migrations/20210224015439_AddConfiguration.cs b/QRCodeService/Migrations/20210224015439_AddConfiguration.cs new file mode 100644 index 0000000..7efc560 --- /dev/null +++ b/QRCodeService/Migrations/20210224015439_AddConfiguration.cs @@ -0,0 +1,102 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace QRCodeService.Migrations +{ + public partial class AddConfiguration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Links", + table: "Links"); + + migrationBuilder.DropPrimaryKey( + name: "PK_Apps", + table: "Apps"); + + migrationBuilder.RenameTable( + name: "Links", + newName: "Link"); + + migrationBuilder.RenameTable( + name: "Apps", + newName: "App"); + + migrationBuilder.AlterColumn( + name: "ShortCode", + table: "Link", + type: "varchar(255)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Link", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_Link", + table: "Link", + column: "ShortCode"); + + migrationBuilder.AddPrimaryKey( + name: "PK_App", + table: "App", + column: "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Link", + table: "Link"); + + migrationBuilder.DropPrimaryKey( + name: "PK_App", + table: "App"); + + migrationBuilder.RenameTable( + name: "Link", + newName: "Links"); + + migrationBuilder.RenameTable( + name: "App", + newName: "Apps"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Links", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "ShortCode", + table: "Links", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "varchar(255)"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Links", + table: "Links", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Apps", + table: "Apps", + column: "Id"); + } + } +} diff --git a/QRCodeService/Migrations/20210224015858_SetProperty.Designer.cs b/QRCodeService/Migrations/20210224015858_SetProperty.Designer.cs new file mode 100644 index 0000000..8010dfd --- /dev/null +++ b/QRCodeService/Migrations/20210224015858_SetProperty.Designer.cs @@ -0,0 +1,77 @@ +// +using System; +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace QRCodeService.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20210224015858_SetProperty")] + partial class SetProperty + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("Domain.AggregateModel.AppAggregate.App", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppKey") + .HasColumnType("longtext"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("Remarks") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("App"); + }); + + modelBuilder.Entity("Domain.AggregateModel.LinkAggregate.Link", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppId") + .HasColumnType("int"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("FullUrl") + .HasColumnType("longtext"); + + b.Property("ShortCode") + .HasMaxLength(11) + .HasColumnType("varchar(11)"); + + b.Property("SuffixUrl") + .HasColumnType("longtext"); + + b.Property("Time") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("ShortCode") + .IsUnique(); + + b.ToTable("Link"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/QRCodeService/Migrations/20210224015858_SetProperty.cs b/QRCodeService/Migrations/20210224015858_SetProperty.cs new file mode 100644 index 0000000..8895332 --- /dev/null +++ b/QRCodeService/Migrations/20210224015858_SetProperty.cs @@ -0,0 +1,80 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace QRCodeService.Migrations +{ + public partial class SetProperty : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Link", + table: "Link"); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Link", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "ShortCode", + table: "Link", + type: "varchar(11)", + maxLength: 11, + nullable: true, + oldClrType: typeof(string), + oldType: "varchar(255)"); + + migrationBuilder.AddPrimaryKey( + name: "PK_Link", + table: "Link", + column: "Id"); + + migrationBuilder.CreateIndex( + name: "IX_Link_ShortCode", + table: "Link", + column: "ShortCode", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Link", + table: "Link"); + + migrationBuilder.DropIndex( + name: "IX_Link_ShortCode", + table: "Link"); + + migrationBuilder.AlterColumn( + name: "ShortCode", + table: "Link", + type: "varchar(255)", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "varchar(11)", + oldMaxLength: 11, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Id", + table: "Link", + type: "int", + nullable: false, + oldClrType: typeof(int), + oldType: "int") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_Link", + table: "Link", + column: "ShortCode"); + } + } +} diff --git a/QRCodeService/Migrations/AppDbContextModelSnapshot.cs b/QRCodeService/Migrations/AppDbContextModelSnapshot.cs new file mode 100644 index 0000000..6213d5e --- /dev/null +++ b/QRCodeService/Migrations/AppDbContextModelSnapshot.cs @@ -0,0 +1,75 @@ +// +using System; +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace QRCodeService.Migrations +{ + [DbContext(typeof(AppDbContext))] + partial class AppDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("Domain.AggregateModel.AppAggregate.App", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppKey") + .HasColumnType("longtext"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("Remarks") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("App"); + }); + + modelBuilder.Entity("Domain.AggregateModel.LinkAggregate.Link", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AppId") + .HasColumnType("int"); + + b.Property("BaseUrl") + .HasColumnType("longtext"); + + b.Property("FullUrl") + .HasColumnType("longtext"); + + b.Property("ShortCode") + .HasMaxLength(11) + .HasColumnType("varchar(11)"); + + b.Property("SuffixUrl") + .HasColumnType("longtext"); + + b.Property("Time") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("ShortCode") + .IsUnique(); + + b.ToTable("Link"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/QRCodeService/QRCodeService.csproj b/QRCodeService/QRCodeService.csproj index fe86347..3ef2f5f 100644 --- a/QRCodeService/QRCodeService.csproj +++ b/QRCodeService/QRCodeService.csproj @@ -21,8 +21,16 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - + diff --git a/QRCodeService/Startup.cs b/QRCodeService/Startup.cs index 734409d..9b46b95 100644 --- a/QRCodeService/Startup.cs +++ b/QRCodeService/Startup.cs @@ -45,7 +45,7 @@ namespace QRCodeService services.AddTransient(typeof(IPipelineBehavior<,>), typeof(TransactionBehaviour<,>)); //EFCore - services.AddDbContextPool( + services.AddDbContext( dbContextOptions => dbContextOptions .UseMySql( "server=localhost;user=root;password=root;database=qrcode",