From a8c22a0e94f21733ec2517a168d86ff38c66d70a Mon Sep 17 00:00:00 2001 From: code liturgy Date: Fri, 2 Dec 2022 02:31:11 +0000 Subject: [PATCH] Add methods for site and environments --- .../ApplicationUser/ApplicationUser.cs | 1 + .../Sites/SiteEnvironmentCreate.cs | 1 - .../Controllers/EnvironmentController.cs | 17 + CodeLiturgy.Views/DbContexts/SiteDbContext.cs | 2 + .../SiteDb/20221202020527_init2.Designer.cs | 323 ++++++++++++++++++ .../Migrations/SiteDb/20221202020527_init2.cs | 19 ++ .../SiteDb/SiteDbContextModelSnapshot.cs | 2 + .../Models/ModelBuilderExtensions.cs | 11 +- CodeLiturgy.Views/Startup.cs | 2 +- 9 files changed, 375 insertions(+), 3 deletions(-) create mode 100644 CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.Designer.cs create mode 100644 CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.cs diff --git a/CodeLiturgy.Views/Application/ApplicationUser/ApplicationUser.cs b/CodeLiturgy.Views/Application/ApplicationUser/ApplicationUser.cs index 3a19d2b..9a95499 100644 --- a/CodeLiturgy.Views/Application/ApplicationUser/ApplicationUser.cs +++ b/CodeLiturgy.Views/Application/ApplicationUser/ApplicationUser.cs @@ -17,6 +17,7 @@ namespace CodeLiturgy.Data.Application.Users [UseUpdate] public partial class ApplicationUser : IdentityUser { + public new string Id { get; set; } public List Environments { get; set; } public List Sites { get; set; } diff --git a/CodeLiturgy.Views/Application/Sites/SiteEnvironmentCreate.cs b/CodeLiturgy.Views/Application/Sites/SiteEnvironmentCreate.cs index 5221e42..2dae3a3 100644 --- a/CodeLiturgy.Views/Application/Sites/SiteEnvironmentCreate.cs +++ b/CodeLiturgy.Views/Application/Sites/SiteEnvironmentCreate.cs @@ -8,6 +8,5 @@ namespace CodeLiturgy.Data.Application public partial class SiteEnvironmentCreate { public string Name { get; set; } - public List Sites { get; set; } } } \ No newline at end of file diff --git a/CodeLiturgy.Views/Controllers/EnvironmentController.cs b/CodeLiturgy.Views/Controllers/EnvironmentController.cs index 832d149..de91ddf 100644 --- a/CodeLiturgy.Views/Controllers/EnvironmentController.cs +++ b/CodeLiturgy.Views/Controllers/EnvironmentController.cs @@ -1,3 +1,4 @@ +using CodeLiturgy.Data.Application; using CodeLiturgy.Data.Auth.Context.Users; using CodeLiturgy.Domain; using Microsoft.AspNetCore.Authorization; @@ -36,7 +37,23 @@ namespace CodeLiturgy.Views.Controllers } + [HttpPost("/api/environments")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public ActionResult AddEnvironment(SiteEnvironmentCreate siteEnvironmentCreate) + { + var (success, result) = _siteDbContext.AddSiteEnvironment(siteEnvironmentCreate); + + if (success) + { + return Ok(result); + } + + return BadRequest(); + } + + /// /// Get Country by Id /// diff --git a/CodeLiturgy.Views/DbContexts/SiteDbContext.cs b/CodeLiturgy.Views/DbContexts/SiteDbContext.cs index e5e7ad3..6cfcb8a 100644 --- a/CodeLiturgy.Views/DbContexts/SiteDbContext.cs +++ b/CodeLiturgy.Views/DbContexts/SiteDbContext.cs @@ -11,12 +11,14 @@ namespace CodeLiturgy.Domain [EfGetOneBy(nameof(Site.Id), typeof(SiteUnique))] [EfGetOne(typeof(SiteUnique))] [EfGetMany(typeof(SiteUnique))] + [EfAddMethods(typeof(SiteCreate), typeof(SiteUnique))] public DbSet Sites { get; set; } [EfGetOneBy(nameof(SiteEnvironment.Id), typeof(SiteEnvironmentUnique))] [EfGetOne(typeof(SiteEnvironmentUnique))] [EfGetMany(typeof(SiteEnvironmentUnique))] + [EfAddMethods(typeof(SiteEnvironmentCreate), typeof(SiteEnvironmentUnique))] public DbSet Environments { get; set; } /// diff --git a/CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.Designer.cs b/CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.Designer.cs new file mode 100644 index 0000000..720510e --- /dev/null +++ b/CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.Designer.cs @@ -0,0 +1,323 @@ +// +using System; +using CodeLiturgy.Domain; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace CodeLiturgy.Views.Migrations.SiteDb +{ + [DbContext(typeof(SiteDbContext))] + [Migration("20221202020527_init2")] + partial class init2 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Site", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("text"); + + b.Property("CreatedDate") + .HasColumnType("timestamp with time zone"); + + b.Property("Domain") + .HasColumnType("text"); + + b.Property("EnvironmentId") + .HasColumnType("text"); + + b.Property("LastChanged") + .HasColumnType("timestamp with time zone"); + + b.Property("SiteType") + .HasColumnType("integer"); + + b.Property("UrlAddress") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("EnvironmentId"); + + b.HasIndex("UserId"); + + b.ToTable("Sites"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Environments"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationRole", 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("Roles", (string)null); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicationRoleId") + .HasColumnType("text"); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationRoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("RoleClaims", (string)null); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasColumnType("text"); + + b.Property("NormalizedUserName") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("ApplicationUser", (string)null); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicationUserId") + .HasColumnType("text"); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicationUserId"); + + b.ToTable("ApplicationUserClaim"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.Property("ApplicationRoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("ApplicationRoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("UserRole", (string)null); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Site", b => + { + b.HasOne("CodeLiturgy.Data.Application.SiteEnvironment", "Environment") + .WithMany("Sites") + .HasForeignKey("EnvironmentId"); + + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationUser", "User") + .WithMany("Sites") + .HasForeignKey("UserId"); + + b.Navigation("Environment"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b => + { + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationUser", "User") + .WithMany("Environments") + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationRoleClaim", b => + { + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationRole", "ApplicationRole") + .WithMany() + .HasForeignKey("ApplicationRoleId"); + + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationRole"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUserClaim", b => + { + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationUser", "ApplicationUser") + .WithMany() + .HasForeignKey("ApplicationUserId"); + + b.Navigation("ApplicationUser"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUserRole", b => + { + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationRole", "ApplicationRole") + .WithMany() + .HasForeignKey("ApplicationRoleId"); + + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CodeLiturgy.Data.Application.Users.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ApplicationRole"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b => + { + b.Navigation("Sites"); + }); + + modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUser", b => + { + b.Navigation("Environments"); + + b.Navigation("Sites"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.cs b/CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.cs new file mode 100644 index 0000000..bf46020 --- /dev/null +++ b/CodeLiturgy.Views/Migrations/SiteDb/20221202020527_init2.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CodeLiturgy.Views.Migrations.SiteDb +{ + public partial class init2 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/CodeLiturgy.Views/Migrations/SiteDb/SiteDbContextModelSnapshot.cs b/CodeLiturgy.Views/Migrations/SiteDb/SiteDbContextModelSnapshot.cs index eea8a23..bf9b997 100644 --- a/CodeLiturgy.Views/Migrations/SiteDb/SiteDbContextModelSnapshot.cs +++ b/CodeLiturgy.Views/Migrations/SiteDb/SiteDbContextModelSnapshot.cs @@ -61,6 +61,7 @@ namespace CodeLiturgy.Views.Migrations.SiteDb modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("text"); b.Property("Name") @@ -135,6 +136,7 @@ namespace CodeLiturgy.Views.Migrations.SiteDb modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUser", b => { b.Property("Id") + .ValueGeneratedOnAdd() .HasColumnType("text"); b.Property("AccessFailedCount") diff --git a/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs b/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs index 9913000..32179b9 100644 --- a/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs +++ b/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs @@ -99,7 +99,16 @@ namespace CodeLiturgy.Domain.Model private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder) { - // FinanceOp + modelBuilder.Entity(x => x.HasKey(x => x.Id)); + modelBuilder.Entity().Property(x => x.Id).ValueGeneratedOnAdd(); + + modelBuilder.Entity(x => x.HasKey(x => x.Id)); + modelBuilder.Entity().Property(x => x.Id).ValueGeneratedOnAdd(); + + modelBuilder.Entity(x => x.HasKey(x => x.Id)); + modelBuilder.Entity().Property(x => x.Id).ValueGeneratedOnAdd(); + + return modelBuilder; diff --git a/CodeLiturgy.Views/Startup.cs b/CodeLiturgy.Views/Startup.cs index bed83c8..20a36d5 100644 --- a/CodeLiturgy.Views/Startup.cs +++ b/CodeLiturgy.Views/Startup.cs @@ -80,7 +80,7 @@ public class Startup app.UseSwaggerUI(c => { - c.RoutePrefix = "swagger"; + c.RoutePrefix = "api/swagger"; c.SwaggerEndpoint("/swagger/v1/swagger.json", "CodeLiturgy.Views v1"); });