feat: add geography entities with countries, states and cities
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
using CMSMicroservice.Domain.Entities.Geography;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Geography;
|
||||
|
||||
public class CityConfiguration : IEntityTypeConfiguration<City>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<City> builder)
|
||||
{
|
||||
builder.ToTable("Cities", "GMS");
|
||||
|
||||
builder.HasKey(c => c.Id);
|
||||
|
||||
builder.Property(c => c.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
builder.Property(c => c.ExternalId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(c => c.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(c => c.Latitude)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(c => c.Longitude)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(c => c.Native)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasDefaultValue("");
|
||||
|
||||
builder.Property(c => c.IsDeleted)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
builder.Property(c => c.StateId)
|
||||
.IsRequired();
|
||||
|
||||
// Index
|
||||
builder.HasIndex(c => c.StateId)
|
||||
.HasDatabaseName("IX_Cities_StateId");
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(c => c.State)
|
||||
.WithMany(s => s.Cities)
|
||||
.HasForeignKey(c => c.StateId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
using CMSMicroservice.Domain.Entities.Geography;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Geography;
|
||||
|
||||
public class CountryConfiguration : IEntityTypeConfiguration<Country>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Country> builder)
|
||||
{
|
||||
builder.ToTable("Countries", "GMS");
|
||||
|
||||
builder.HasKey(c => c.Id);
|
||||
|
||||
builder.Property(c => c.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
builder.Property(c => c.ExternalId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(c => c.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(c => c.Iso3)
|
||||
.IsRequired()
|
||||
.HasMaxLength(3);
|
||||
|
||||
builder.Property(c => c.Iso2)
|
||||
.IsRequired()
|
||||
.HasMaxLength(2);
|
||||
|
||||
builder.Property(c => c.NumericCode)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(c => c.PhoneCode)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(c => c.Capital)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(c => c.Currency)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(c => c.CurrencyName)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(c => c.CurrencySymbol)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(c => c.Tld)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(c => c.Native)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(c => c.Region)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(c => c.Subregion)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(c => c.Latitude)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(c => c.Longitude)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(c => c.Emoji)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(c => c.EmojiU)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(c => c.IsDeleted)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
// Relationships
|
||||
builder.HasMany(c => c.States)
|
||||
.WithOne(s => s.Country)
|
||||
.HasForeignKey(s => s.CountryId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
using CMSMicroservice.Domain.Entities.Geography;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Configurations.Geography;
|
||||
|
||||
public class StateConfiguration : IEntityTypeConfiguration<State>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<State> builder)
|
||||
{
|
||||
builder.ToTable("States", "GMS");
|
||||
|
||||
builder.HasKey(s => s.Id);
|
||||
|
||||
builder.Property(s => s.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
builder.Property(s => s.ExternalId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(s => s.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(s => s.StateCode)
|
||||
.IsRequired()
|
||||
.HasMaxLength(10);
|
||||
|
||||
builder.Property(s => s.Latitude)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(s => s.Longitude)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(s => s.Type)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(s => s.Native)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasDefaultValue("");
|
||||
|
||||
builder.Property(s => s.IsDeleted)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
builder.Property(s => s.CountryId)
|
||||
.IsRequired();
|
||||
|
||||
// Index
|
||||
builder.HasIndex(s => s.CountryId)
|
||||
.HasDatabaseName("IX_States_CountryId");
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(s => s.Country)
|
||||
.WithMany(c => c.States)
|
||||
.HasForeignKey(s => s.CountryId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(s => s.Cities)
|
||||
.WithOne(c => c.State)
|
||||
.HasForeignKey(c => c.StateId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user