Skip to content

Commit

Permalink
Add Entity Type Configuration for all entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadKarimi committed Jan 9, 2024
1 parent e59d905 commit b5d5947
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/SwiftLink.Domain/Entities/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinkVisit> LinkVisits { get; set; }
}
35 changes: 35 additions & 0 deletions src/SwiftLink.Infrastructure/Persistence/Config/LinkConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace SwiftLink.Infrastructure.Persistence.Config;

public class LinkConfig : IEntityTypeConfiguration<Link>
{
public void Configure(EntityTypeBuilder<Link> 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);
}
}
22 changes: 22 additions & 0 deletions src/SwiftLink.Infrastructure/Persistence/Config/LinkVisitConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace SwiftLink.Infrastructure.Persistence.Config;

public class LinkVisitConfig : IEntityTypeConfiguration<LinkVisit>
{
public void Configure(EntityTypeBuilder<LinkVisit> 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();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace SwiftLink.Infrastructure.Persistence.Config;

public class SubscriberConfig : IEntityTypeConfiguration<Subscriber>
{
public void Configure(EntityTypeBuilder<Subscriber> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<ApplicationDbContext> options) : DbContext(options), IApplicationDbContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SwiftLink.Domain.Common;
using System.Reflection;

namespace SwiftLink.Infrastructure.Extensions;
namespace SwiftLink.Infrastructure.Persistence.Extensions;

/// <summary>
/// This extention is programmed for registering Entities that are defined the EntityAttribute .
Expand Down
4 changes: 0 additions & 4 deletions src/SwiftLink.Infrastructure/SwiftLink.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@
<ProjectReference Include="..\SwiftLink.Application\SwiftLink.Application.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Config\" />
</ItemGroup>

</Project>

0 comments on commit b5d5947

Please sign in to comment.