diff --git a/src/SwiftLink.Domain/Entities/Link.cs b/src/SwiftLink.Domain/Entities/Link.cs index b5cb999..c933463 100644 --- a/src/SwiftLink.Domain/Entities/Link.cs +++ b/src/SwiftLink.Domain/Entities/Link.cs @@ -15,4 +15,6 @@ public class Link: IEntity public DateTime ExpirationDate { get; set; } public bool IsBanned { get; set; } public string Password { get; set; } + + public ICollection LinkVisits { get; set; } } diff --git a/src/SwiftLink.Infrastructure/Persistence/Config/LinkConfig.cs b/src/SwiftLink.Infrastructure/Persistence/Config/LinkConfig.cs new file mode 100644 index 0000000..f788a22 --- /dev/null +++ b/src/SwiftLink.Infrastructure/Persistence/Config/LinkConfig.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace SwiftLink.Infrastructure.Persistence.Config; + +public class LinkConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(t => t.HasComment("Stores Original links and generated shortCode.")); + + builder.HasKey(t => t.Id) + .HasName("PK_Base_Link"); + + builder.Property(x => x.OriginalUrl) + .IsRequired() + .HasMaxLength(1500); + + builder.Property(x => x.Description) + .IsRequired() + .HasMaxLength(250); + + builder.Property(x => x.Password) + .IsRequired() + .HasMaxLength(25); + + builder.Property(x => x.ShortCode) + .IsRequired() + .HasMaxLength(16); + + builder.HasMany(x => x.LinkVisits) + .WithOne(x => x.Link) + .HasPrincipalKey(x => x.Id) + .HasForeignKey(x => x.LinkId); + } +} diff --git a/src/SwiftLink.Infrastructure/Persistence/Config/LinkVisitConfig.cs b/src/SwiftLink.Infrastructure/Persistence/Config/LinkVisitConfig.cs new file mode 100644 index 0000000..b98ba6f --- /dev/null +++ b/src/SwiftLink.Infrastructure/Persistence/Config/LinkVisitConfig.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace SwiftLink.Infrastructure.Persistence.Config; + +public class LinkVisitConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(t => t.HasComment("analytics, providing insights into the number of users who clicked on a shortened link.")); + + builder.HasKey(t => t.Id) + .HasName("PK_Base_LinkVisit"); + + builder.Property(x => x.ClientMetaData) + .IsRequired() + .HasMaxLength(500); + + builder.Property(x => x.Date) + .IsRequired(); + + } +} diff --git a/src/SwiftLink.Infrastructure/Persistence/Config/SubscriberConfig.cs b/src/SwiftLink.Infrastructure/Persistence/Config/SubscriberConfig.cs new file mode 100644 index 0000000..512cfe0 --- /dev/null +++ b/src/SwiftLink.Infrastructure/Persistence/Config/SubscriberConfig.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace SwiftLink.Infrastructure.Persistence.Config; + +public class SubscriberConfig : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(t => t.HasComment("Only these subscribers are allowed to insert a URL to obtain a shorter one.")); + + builder.HasKey(t => t.Id) + .HasName("PK_Base_Subscriber"); + + builder.Property(x => x.Name) + .IsRequired() + .HasMaxLength(50); + + builder.Property(x => x.Token) + .IsRequired(); + + builder.Property(x => x.IsActive) + .IsRequired(); + } +} diff --git a/src/SwiftLink.Infrastructure/Context/ApplicationDbContext.cs b/src/SwiftLink.Infrastructure/Persistence/Context/ApplicationDbContext.cs similarity index 92% rename from src/SwiftLink.Infrastructure/Context/ApplicationDbContext.cs rename to src/SwiftLink.Infrastructure/Persistence/Context/ApplicationDbContext.cs index 483fa38..19dea15 100644 --- a/src/SwiftLink.Infrastructure/Context/ApplicationDbContext.cs +++ b/src/SwiftLink.Infrastructure/Persistence/Context/ApplicationDbContext.cs @@ -1,8 +1,8 @@ using SwiftLink.Domain.Common; -using SwiftLink.Infrastructure.Extensions; +using SwiftLink.Infrastructure.Persistence.Extensions; using System.Reflection; -namespace SwiftLink.Infrastructure.Context; +namespace SwiftLink.Infrastructure.Persistence.Context; public class ApplicationDbContext(DbContextOptions options) : DbContext(options), IApplicationDbContext { diff --git a/src/SwiftLink.Infrastructure/Extensions/ModelBuilderExtentions.cs b/src/SwiftLink.Infrastructure/Persistence/Extensions/ModelBuilderExtentions.cs similarity index 93% rename from src/SwiftLink.Infrastructure/Extensions/ModelBuilderExtentions.cs rename to src/SwiftLink.Infrastructure/Persistence/Extensions/ModelBuilderExtentions.cs index dd9adb7..be803cf 100644 --- a/src/SwiftLink.Infrastructure/Extensions/ModelBuilderExtentions.cs +++ b/src/SwiftLink.Infrastructure/Persistence/Extensions/ModelBuilderExtentions.cs @@ -1,7 +1,7 @@ using SwiftLink.Domain.Common; using System.Reflection; -namespace SwiftLink.Infrastructure.Extensions; +namespace SwiftLink.Infrastructure.Persistence.Extensions; /// /// This extention is programmed for registering Entities that are defined the EntityAttribute . diff --git a/src/SwiftLink.Infrastructure/SwiftLink.Infrastructure.csproj b/src/SwiftLink.Infrastructure/SwiftLink.Infrastructure.csproj index 86223eb..c243884 100644 --- a/src/SwiftLink.Infrastructure/SwiftLink.Infrastructure.csproj +++ b/src/SwiftLink.Infrastructure/SwiftLink.Infrastructure.csproj @@ -15,8 +15,4 @@ - - - -