Skip to content

Commit

Permalink
feature: add Category to migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Eschechola committed Oct 4, 2023
1 parent 9c5f1de commit 7e111ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/StorEsc.Infrastructure/Context/StorEscContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public StorEscContext(DbContextOptions<StorEscContext> options) : base(options)
public DbSet<Wallet> Recharges { get; set; }
public DbSet<Payment> Payments { get; set; }
public DbSet<Administrator> Administrators { get; set; }
public DbSet<Category> Categories { get; set; }

#endregion

Expand All @@ -37,6 +38,7 @@ public StorEscContext(DbContextOptions<StorEscContext> options) : base(options)
protected override void OnModelCreating(ModelBuilder builder)
{
builder.ApplyConfiguration(new CustomerMap());
builder.ApplyConfiguration(new CategoryMap());
builder.ApplyConfiguration(new OrderMap());
builder.ApplyConfiguration(new OrderItemMap());
builder.ApplyConfiguration(new ProductMap());
Expand Down
24 changes: 24 additions & 0 deletions src/StorEsc.Infrastructure/Maps/CategoryMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using StorEsc.Domain.Entities;

namespace StorEsc.Infrastructure.Maps;

public class CategoryMap : BaseMap<Category>
{
public override void Configure(EntityTypeBuilder<Category> builder)
{
builder.ToTable("Category", "ste");

base.Configure(builder);

builder.Property(category => category.Name)
.IsRequired()
.HasColumnName("Name")
.HasColumnType("VARCHAR(120)");

builder.HasMany(category => category.Products)
.WithOne(product => product.Category)
.HasForeignKey(product => product.CategoryId);
}
}
4 changes: 4 additions & 0 deletions src/StorEsc.Infrastructure/Maps/ProductMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public override void Configure(EntityTypeBuilder<Product> builder)

base.Configure(builder);

builder.Property(product => product.CategoryId)
.IsRequired()
.HasColumnType("VARCHAR(36)");

builder.Property(product => product.Name)
.IsRequired()
.HasColumnType("VARCHAR(200)")
Expand Down

0 comments on commit 7e111ef

Please sign in to comment.