Skip to content

Commit

Permalink
feat: configuring product table
Browse files Browse the repository at this point in the history
  • Loading branch information
abubakrmirgiyasov committed Apr 5, 2024
1 parent 9d55011 commit 3ed39c3
Show file tree
Hide file tree
Showing 33 changed files with 581 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
{ // Admin Identity
"UpstreamPathTemplate": "/a/identity/{everything}",
"UpstreamHttpMethod": [ "POST", "DELETE" ],
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ],
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
Expand Down
2 changes: 1 addition & 1 deletion src/Mint.Domain/Models/Admin/Categories/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Category : Entity<Guid>

public List<CategoryTag>? CategoryTags { get; set; }

public List<Product>? Products { get; set; }
public List<ProductCategory>? ProductCategories { get; set; }

public List<StoreCategory>? StoreCategories { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Mint.Domain/Models/Admin/Products/Discount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public class Discount : Entity<Guid>

public bool IsExpired { get; set; }

public List<Product>? Products { get; set; }
public List<ProductDiscount>? ProductDiscounts { get; set; }
}
29 changes: 21 additions & 8 deletions src/Mint.Domain/Models/Admin/Products/Product.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mint.Domain.Models.Admin.Categories;
using Mint.Domain.Models.Admin.Manufactures;
using Mint.Domain.Models.Admin.Manufactures;
using Mint.Domain.Models.Admin.Stores;
using Mint.Domain.Models.Base;
using System.ComponentModel.DataAnnotations;
Expand All @@ -18,10 +17,10 @@ public class Product : Entity<Guid>
public required string LongName { get; set; }

[Required(ErrorMessage = "Заполните обязательное поле.")]
public required long Sku { get; set; }
public required string Sku { get; set; }

[StringLength(255, ErrorMessage = "Превышено макс. длина строки (255).")]
public string? Gtin { get; set; }
public long? Gtin { get; set; }

[Required(ErrorMessage = "Заполните обязательное поле.")]
[StringLength(800, ErrorMessage = "Превышено макс. длина строки (800).")]
Expand All @@ -39,6 +38,8 @@ public class Product : Entity<Guid>

public bool ShowOnHomePage { get; set; } = false;

public bool DisableBuyButton { get; set; }

public string? CountryOfOrigin { get; set; }

[Required(ErrorMessage = "Заполните обязательное поле.")]
Expand All @@ -51,6 +52,18 @@ public class Product : Entity<Guid>
[MinLength(2, ErrorMessage = "Мин. длина строки (2).")]
public decimal? OldPrice { get; set; } = 0;

public bool CustomerEntersPrice { get; set; } = false;

public decimal? MinCustomerEntersPrice { get; set; }

public decimal? MaxCustomerEntersPrice { get; set; }

public decimal? SpecialPrice { get; set; }

public DateTimeOffset? SpecialPriceStartDateTimeUtc { get; set; }

public DateTimeOffset? SpecialPriceEndDateTimeUtc { get; set; }

public bool IsPublished { get; set; } = false;

public bool? IsFreeTax { get; set; } = false;
Expand All @@ -73,10 +86,6 @@ public class Product : Entity<Guid>

public Manufacture? Manufacture { get; set; }

public Guid? CategoryId { get; set; }

public Category? Category { get; set; }

public Guid? StoreId { get; set; }

public Store? Store { get; set; }
Expand All @@ -96,4 +105,8 @@ public class Product : Entity<Guid>
public List<Storage>? Storages { get; set; }

public List<ProductReview>? ProductReviews { get; set; }

public List<ProductCategory>? ProductCategories { get; set; }

public List<ProductDiscount>? ProductDiscounts { get; set; }
}
16 changes: 16 additions & 0 deletions src/Mint.Domain/Models/Admin/Products/ProductCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Mint.Domain.Models.Admin.Categories;

namespace Mint.Domain.Models.Admin.Products;

public class ProductCategory
{
public int DisplayOrder { get; set; }

public Guid CategoryId { get; set; }

public Category Category { get; set; } = default!;

public Guid ProductId { get; set; }

public Product Product { get; set; } = default!;
}
12 changes: 12 additions & 0 deletions src/Mint.Domain/Models/Admin/Products/ProductDiscount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Mint.Domain.Models.Admin.Products;

public class ProductDiscount
{
public Guid DiscountId { get; set; }

public Discount Discount { get; set; } = default!;

public Guid ProductId { get; set; }

public Product Product { get; set; } = default!;
}
87 changes: 0 additions & 87 deletions src/Mint.Domain/Models/Product.cs

This file was deleted.

5 changes: 5 additions & 0 deletions src/Mint.Infrastructure/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
/// </summary>
public DbSet<ProductCharacteristic> ProductCharacteristics => Set<ProductCharacteristic>();

/// <summary>
/// Product Categories Table
/// </summary>
public DbSet<ProductCategory> ProductCategories => Set<ProductCategory>();

/// <summary>
/// Stores Table
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mint.Domain.Models.Admin.Products;

namespace Mint.Infrastructure.Configurations.Admin.Products;

internal sealed class ProductCategoryConfiguration : IEntityConfiguration<ProductCategory>
{
public void Configure(EntityTypeBuilder<ProductCategory> builder)
{
builder
.HasKey(x => new
{
x.ProductId,
x.CategoryId,
});

builder
.HasOne(x => x.Category)
.WithMany(x => x.ProductCategories)
.HasForeignKey(x => x.CategoryId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne(x => x.Product)
.WithMany(x => x.ProductCategories)
.HasForeignKey(x => x.ProductId)
.OnDelete(DeleteBehavior.Cascade);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,5 @@ public void Configure(EntityTypeBuilder<Product> builder)
.WithMany(x => x.Products)
.HasForeignKey(x => x.ManufactureId)
.OnDelete(DeleteBehavior.NoAction);

builder
.HasOne(x => x.Category)
.WithMany(x => x.Products)
.HasForeignKey(x => x.CategoryId)
.OnDelete(DeleteBehavior.NoAction);

builder
.HasOne(x => x.Discount)
.WithMany(x => x.Products)
.HasForeignKey(x => x.DiscountId)
.OnDelete(DeleteBehavior.SetNull);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Mint.Domain.Models.Admin.Products;

namespace Mint.Infrastructure.Configurations.Admin.Products;

internal sealed class ProductDiscountConfiguration : IEntityConfiguration<ProductDiscount>
{
public void Configure(EntityTypeBuilder<ProductDiscount> builder)
{
builder
.HasKey(x => new
{
x.ProductId,
x.DiscountId
});

builder
.HasOne(x => x.Discount)
.WithMany(x => x.ProductDiscounts)
.HasForeignKey(x => x.DiscountId)
.OnDelete(DeleteBehavior.Cascade);

builder
.HasOne(x => x.Product)
.WithMany(x => x.ProductDiscounts)
.HasForeignKey(x => x.ProductId)
.OnDelete(DeleteBehavior.Cascade);
}
}
Loading

0 comments on commit 3ed39c3

Please sign in to comment.