first commit
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ApplicationDbContext: DbContext, IDataProtectionKeyContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
var itemInWarehouseClaims = modelBuilder.Entity<ItemInWarehouseClaims>();
|
||||
itemInWarehouseClaims.HasOne(e => e.Item)
|
||||
.WithMany(e => e.ItemInWarehouseClaims)
|
||||
.HasForeignKey(e => e.ItemId);
|
||||
itemInWarehouseClaims.HasIndex(ic => new { ic.ItemId, ic.ClaimType })
|
||||
.IsUnique();
|
||||
|
||||
var wrehouseClaims = modelBuilder.Entity<WarehouseClaims>();
|
||||
wrehouseClaims.HasOne(e => e.Warehouse)
|
||||
.WithMany(e => e.Claims)
|
||||
.HasForeignKey(e => e.WarehouseId);
|
||||
wrehouseClaims.HasIndex(ic => new { ic.WarehouseId, ic.ClaimType })
|
||||
.IsUnique();
|
||||
|
||||
var itemClaims = modelBuilder.Entity<ItemClaims>();
|
||||
itemClaims.HasIndex(ic => new { ic.ItemId, ic.ClaimType })
|
||||
.IsUnique();
|
||||
itemClaims.HasOne(ic => ic.Item)
|
||||
.WithMany(i => i.ItemClaims)
|
||||
.HasForeignKey(ic => ic.ItemId);
|
||||
|
||||
var itemTag = modelBuilder.Entity<ItemCategoryTag>();
|
||||
itemTag.HasOne(e => e.ParentTag)
|
||||
.WithMany(e => e.ListOfChildrenTag)
|
||||
.HasForeignKey(e => e.ParentTagId);
|
||||
itemTag.HasIndex(ic => new { ic.Name })
|
||||
.IsUnique();
|
||||
|
||||
var item = modelBuilder.Entity<Item>();
|
||||
item.HasOne(e => e.Producer)
|
||||
.WithMany(e => e.Items)
|
||||
.HasForeignKey(e => e.ProducerId)
|
||||
.IsRequired(true);
|
||||
item.HasIndex(ic => new { ic.Name, ic.ProducerId })
|
||||
.IsUnique();
|
||||
item.Navigation(ic => ic.ItemClaims)
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Property);
|
||||
|
||||
var producers = modelBuilder.Entity<Producers>();
|
||||
producers.HasIndex(ic => new { ic.Name })
|
||||
.IsUnique();
|
||||
producers.Navigation(ic => ic.Claims)
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Property);
|
||||
|
||||
var producerClaims = modelBuilder.Entity<ProducerClaims>();
|
||||
producerClaims.HasOne(e => e.Producer)
|
||||
.WithMany(e => e.Claims)
|
||||
.HasForeignKey(e => e.ProducerId);
|
||||
producerClaims.HasIndex(ic => new { ic.ProducerId, ic.ClaimType })
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<ServiceClaims>()
|
||||
.HasIndex(ic => ic.ClaimType)
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<ItemInWarehouse>()
|
||||
.Navigation(ic => ic.ItemInWarehouseClaims)
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Property);
|
||||
|
||||
modelBuilder.Entity<Warehouse>()
|
||||
.Navigation(ic => ic.Claims)
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Property);
|
||||
|
||||
}
|
||||
|
||||
public DbSet<Image> Images { get; init; }
|
||||
public DbSet<Item> Items { get; init; }
|
||||
public DbSet<ItemCategoryTag> ItemCategoryTags { get; init; }
|
||||
public DbSet<ItemClaims> ItemClaims { get; init; }
|
||||
public DbSet<ItemInWarehouse> ItemInWarehouses { get; init; }
|
||||
public DbSet<ItemInWarehouseClaims> ItemInWarehousesClaims { get; init; }
|
||||
public DbSet<Producers> Producers { get; init; }
|
||||
public DbSet<ProducerClaims> ProducerClaims { get; init; }
|
||||
public DbSet<Warehouse> Warehouses { get; init; }
|
||||
public DbSet<WarehouseClaims> WarehouseClaims { get; init; }
|
||||
public DbSet<ServiceClaims> ServiceClaims { get; init; }
|
||||
public DbSet<DataProtectionKey> DataProtectionKeys { get; init; }
|
||||
public DbSet<TaskStatusTable> TaskStatus { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
|
||||
|
||||
{
|
||||
public ApplicationDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
||||
optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
|
||||
|
||||
return new ApplicationDbContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Claim = System.Security.Claims.Claim;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ClaimBase
|
||||
{
|
||||
[Required]
|
||||
public string? ClaimType { get; set; }
|
||||
[Required]
|
||||
public string? ClaimValue { get; set; }
|
||||
public string? ClaimIssuer { get; set; }
|
||||
|
||||
|
||||
[NotMapped]
|
||||
public Claim Claim {
|
||||
get
|
||||
{
|
||||
return new Claim(ClaimType ?? throw new Exception("Null exemption")
|
||||
, ClaimValue ?? throw new Exception("Null exemption")
|
||||
, ClaimIssuer ?? "Local");
|
||||
}
|
||||
set
|
||||
{
|
||||
ClaimType = value.Type;
|
||||
ClaimValue = value.Value;
|
||||
ClaimIssuer = value.Issuer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class Image
|
||||
{
|
||||
[Key]
|
||||
public Guid? Id { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class Item
|
||||
{
|
||||
[Key]
|
||||
public Guid? Id { get; set; }
|
||||
[Required, MaxLength(30), MinLength(4)]
|
||||
public string? Name { get; set; }
|
||||
public Image Image { get; set; }
|
||||
[Required]
|
||||
public Producers? Producer { get; set; }
|
||||
[Required]
|
||||
public Guid? ProducerId { get; set; }
|
||||
|
||||
public List<ItemCategoryTag>? ItemCategoryTags { get; set; }
|
||||
|
||||
public List<ItemClaims>? ItemClaims { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ItemCategoryTag
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
[Required]
|
||||
[MinLength(4),MaxLength(30)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
public ItemCategoryTag? ParentTag { get; set; }
|
||||
public Guid? ParentTagId { get; set; }
|
||||
|
||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||
public List<ItemCategoryTag>? ListOfChildrenTag { get; set; }
|
||||
|
||||
public List<Item>? Items { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Claim = System.Security.Claims.Claim;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ItemClaims() : ClaimBase
|
||||
{
|
||||
public ItemClaims(Item item, Claim claim) : this()
|
||||
{
|
||||
Item = item;
|
||||
ClaimType = claim.Type;
|
||||
ClaimValue = claim.Value;
|
||||
}
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
[Required, MaxLength(30)]
|
||||
public Guid? ItemId { get; set; }
|
||||
public Item? Item { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ItemInWarehouse()
|
||||
{
|
||||
public ItemInWarehouse(List<ItemInWarehouseClaims>? itemInWarehouses = null) : this()
|
||||
{
|
||||
if (itemInWarehouses != null)
|
||||
ItemInWarehouseClaims = itemInWarehouses;
|
||||
else
|
||||
ItemInWarehouseClaims = new List<ItemInWarehouseClaims>();
|
||||
}
|
||||
|
||||
public ItemInWarehouse(Item item, string positions, List<ItemInWarehouseClaims> itemInWarehouses) : this(itemInWarehouses)
|
||||
{
|
||||
Item = item;
|
||||
Positions = positions;
|
||||
ItemInWarehouseClaims = itemInWarehouses;
|
||||
}
|
||||
|
||||
[Key]
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public Item? Item { get; set; }
|
||||
|
||||
[Required, MaxLength(30)]
|
||||
public string? Positions { get; set; }
|
||||
|
||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||
public List<ItemInWarehouseClaims>? ItemInWarehouseClaims { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ItemInWarehouseClaims : ClaimBase
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
[Required]
|
||||
public Guid? ItemId { get; set; }
|
||||
public ItemInWarehouse? Item { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Claim = System.Security.Claims.Claim;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ProducerClaims() : ClaimBase
|
||||
{
|
||||
|
||||
public ProducerClaims(Producers producer, Claim claim) : this()
|
||||
{
|
||||
this.Producer = producer;
|
||||
ClaimType = claim.Type;
|
||||
ClaimValue = claim.Value;
|
||||
}
|
||||
|
||||
[Key]
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
[Required, MaxLength(100)]
|
||||
public Guid? ProducerId { get; set; }
|
||||
public Producers? Producer { get; set; }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class Producers
|
||||
{
|
||||
[Key]
|
||||
public Guid? Id { get; set; }
|
||||
public Image? Image { get; set; }
|
||||
[Required, MaxLength(50)]
|
||||
public string? Name { get; set; }
|
||||
[Required, MaxLength(60)]
|
||||
public string? FiestLineAdress { get; set; }
|
||||
[MaxLength(60)]
|
||||
public string? SecondLineAdress { get; set; }
|
||||
[EmailAddress, MaxLength(40)]
|
||||
public string? Email { get; set; }
|
||||
[Phone, MaxLength(15)]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[DeleteBehavior(DeleteBehavior.SetNull)]
|
||||
public List<Item>? Items { get; set; }
|
||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||
public List<ProducerClaims>? Claims { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Claim = System.Security.Claims.Claim;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class ServiceClaims
|
||||
{
|
||||
[Key, Required, MinLength(3), MaxLength(40)]
|
||||
public string? ClaimType { get; set; }
|
||||
[Required, MinLength(3), MaxLength(40)]
|
||||
public string? ClaimValue { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Claim Claim
|
||||
{
|
||||
get =>
|
||||
new(ClaimType ??
|
||||
throw new InvalidOperationException(),
|
||||
ClaimValue ?? throw new InvalidOperationException());
|
||||
set
|
||||
{
|
||||
ClaimType = value.Type;
|
||||
ClaimValue = value.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class TaskStatusTable
|
||||
{
|
||||
[Required, Key]
|
||||
public Guid TaskId { get; init; }
|
||||
[MaxLength(50)]
|
||||
public string? Actor { get; init; }
|
||||
[MaxLength(20), Required]
|
||||
public string? Status { get; set; }
|
||||
[Required]
|
||||
public DateTime CreatedAt { get; init; }
|
||||
[Required]
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Warehouse
|
||||
{
|
||||
[Key]
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
[Required, MinLength(4), MaxLength(30)]
|
||||
public string? Name { get; set; }
|
||||
[Required, MinLength(4), MaxLength(40)]
|
||||
public string? FiestLineAdress { get; set; }
|
||||
[MinLength(0), MaxLength(40)]
|
||||
public string? SecondLineAdress { get; set; }
|
||||
|
||||
public Image? Image { get; set; }
|
||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||
public List<WarehouseClaims>? Claims { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Claim = System.Security.Claims.Claim;
|
||||
|
||||
namespace OpenWarehouse.warehouse.api.Data;
|
||||
|
||||
public class WarehouseClaims() : ClaimBase
|
||||
{
|
||||
public WarehouseClaims(Warehouse warehouse, Claim claim) : this()
|
||||
{
|
||||
Warehouse = warehouse;
|
||||
ClaimType = claim.Type;
|
||||
ClaimValue = claim.Value;
|
||||
ClaimIssuer = claim.Issuer;
|
||||
|
||||
}
|
||||
|
||||
public Claim GetClaim()
|
||||
{
|
||||
return new Claim(ClaimType ?? "Uknow", ClaimValue ?? "Uknow");
|
||||
}
|
||||
|
||||
[Key, MaxLength(100)]
|
||||
public Guid? Id { get; set; }
|
||||
[Required, MaxLength(100)]
|
||||
public Guid? WarehouseId { get; set; }
|
||||
public Warehouse? Warehouse { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user