Add methods for site and environments

This commit is contained in:
code liturgy 2022-12-02 02:31:11 +00:00
parent fc33b23559
commit a8c22a0e94
9 changed files with 375 additions and 3 deletions

View File

@ -17,6 +17,7 @@ namespace CodeLiturgy.Data.Application.Users
[UseUpdate] [UseUpdate]
public partial class ApplicationUser : IdentityUser<string> public partial class ApplicationUser : IdentityUser<string>
{ {
public new string Id { get; set; }
public List<SiteEnvironment> Environments { get; set; } public List<SiteEnvironment> Environments { get; set; }
public List<Site> Sites { get; set; } public List<Site> Sites { get; set; }

View File

@ -8,6 +8,5 @@ namespace CodeLiturgy.Data.Application
public partial class SiteEnvironmentCreate public partial class SiteEnvironmentCreate
{ {
public string Name { get; set; } public string Name { get; set; }
public List<Site> Sites { get; set; }
} }
} }

View File

@ -1,3 +1,4 @@
using CodeLiturgy.Data.Application;
using CodeLiturgy.Data.Auth.Context.Users; using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Domain; using CodeLiturgy.Domain;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -36,6 +37,22 @@ 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();
}
/// <summary> /// <summary>
/// Get Country by Id /// Get Country by Id

View File

@ -11,12 +11,14 @@ namespace CodeLiturgy.Domain
[EfGetOneBy(nameof(Site.Id), typeof(SiteUnique))] [EfGetOneBy(nameof(Site.Id), typeof(SiteUnique))]
[EfGetOne(typeof(SiteUnique))] [EfGetOne(typeof(SiteUnique))]
[EfGetMany(typeof(SiteUnique))] [EfGetMany(typeof(SiteUnique))]
[EfAddMethods(typeof(SiteCreate), typeof(SiteUnique))]
public DbSet<Site> Sites { get; set; } public DbSet<Site> Sites { get; set; }
[EfGetOneBy(nameof(SiteEnvironment.Id), typeof(SiteEnvironmentUnique))] [EfGetOneBy(nameof(SiteEnvironment.Id), typeof(SiteEnvironmentUnique))]
[EfGetOne(typeof(SiteEnvironmentUnique))] [EfGetOne(typeof(SiteEnvironmentUnique))]
[EfGetMany(typeof(SiteEnvironmentUnique))] [EfGetMany(typeof(SiteEnvironmentUnique))]
[EfAddMethods(typeof(SiteEnvironmentCreate), typeof(SiteEnvironmentUnique))]
public DbSet<SiteEnvironment> Environments { get; set; } public DbSet<SiteEnvironment> Environments { get; set; }
/// <summary> /// <summary>

View File

@ -0,0 +1,323 @@
// <auto-generated />
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<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text");
b.Property<DateTime>("CreatedDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Domain")
.HasColumnType("text");
b.Property<string>("EnvironmentId")
.HasColumnType("text");
b.Property<DateTime>("LastChanged")
.HasColumnType("timestamp with time zone");
b.Property<int>("SiteType")
.HasColumnType("integer");
b.Property<string>("UrlAddress")
.HasColumnType("text");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("EnvironmentId");
b.HasIndex("UserId");
b.ToTable("Sites");
});
modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Environments");
});
modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApplicationRoleId")
.HasColumnType("text");
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("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<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.HasColumnType("text");
b.Property<string>("Email")
.HasColumnType("text");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasColumnType("text");
b.Property<string>("NormalizedUserName")
.HasColumnType("text");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("ApplicationUser", (string)null);
});
modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUserClaim", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApplicationUserId")
.HasColumnType("text");
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ApplicationUserId");
b.ToTable("ApplicationUserClaim");
});
modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUserRole", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

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

View File

@ -61,6 +61,7 @@ namespace CodeLiturgy.Views.Migrations.SiteDb
modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b => modelBuilder.Entity("CodeLiturgy.Data.Application.SiteEnvironment", b =>
{ {
b.Property<string>("Id") b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Name") b.Property<string>("Name")
@ -135,6 +136,7 @@ namespace CodeLiturgy.Views.Migrations.SiteDb
modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUser", b => modelBuilder.Entity("CodeLiturgy.Data.Application.Users.ApplicationUser", b =>
{ {
b.Property<string>("Id") b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text"); .HasColumnType("text");
b.Property<int>("AccessFailedCount") b.Property<int>("AccessFailedCount")

View File

@ -99,7 +99,16 @@ namespace CodeLiturgy.Domain.Model
private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder) private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder)
{ {
// FinanceOp modelBuilder.Entity<ApplicationUser>(x => x.HasKey(x => x.Id));
modelBuilder.Entity<ApplicationUser>().Property(x => x.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Site>(x => x.HasKey(x => x.Id));
modelBuilder.Entity<Site>().Property(x => x.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<SiteEnvironment>(x => x.HasKey(x => x.Id));
modelBuilder.Entity<SiteEnvironment>().Property(x => x.Id).ValueGeneratedOnAdd();
return return
modelBuilder; modelBuilder;

View File

@ -80,7 +80,7 @@ public class Startup
app.UseSwaggerUI(c => app.UseSwaggerUI(c =>
{ {
c.RoutePrefix = "swagger"; c.RoutePrefix = "api/swagger";
c.SwaggerEndpoint("/swagger/v1/swagger.json", "CodeLiturgy.Views v1"); c.SwaggerEndpoint("/swagger/v1/swagger.json", "CodeLiturgy.Views v1");
}); });