Skip to content

Commit

Permalink
[#31] Create initial Link Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphoeninger committed Oct 18, 2024
1 parent 1719024 commit c536c05
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
37 changes: 37 additions & 0 deletions DAL/MODELS.FileSharing/Entities/Configuration/LinkConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace MODELS.FileSharing.Entities.Configuration;

public class LinkConfiguration : IEntityTypeConfiguration<Link>
{
public void Configure(EntityTypeBuilder<Link> builder)
{
// query filters

// properties
builder.Property(l => l.CreatedAt).HasDefaultValueSql("GetDate()");
builder.Property(l => l.Display)
.HasComputedColumnSql("[Name]", stored: true);

// relationships
builder.HasOne(l => l.FileItemNavigation)
.WithMany(f => f.Links)
.HasForeignKey(l => l.FileItemId)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("FK_Links_FileItem");

builder.HasOne(l => l.UserNavigation)
.WithMany(u => u.Links)
.HasForeignKey(l => l.UserId)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("FK_Links_User");

builder.HasIndex(l => l.url, "IX_Links_Url").IsUnique();

// temporal
builder.ToTable(b => b.IsTemporal(tb =>
{
tb.HasPeriodEnd("ValidTo");
tb.HasPeriodStart("ValidFrom");
tb.UseHistoryTable("FileItemsAudit");
}));
}
}
3 changes: 3 additions & 0 deletions DAL/MODELS.FileSharing/Entities/FileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public partial class FileItem : BaseEntity
[InverseProperty(nameof(ParentNavigation))]
public virtual IEnumerable<FileItem> FileItems { get; set; } = new List<FileItem>();

[InverseProperty(nameof(Link.FileItemNavigation))]
public virtual IEnumerable<Link> Links { get; set; } = new List<Link>();

private bool? _isFolder;
[DisplayName("Is Folder")]
public bool IsFolder
Expand Down
60 changes: 60 additions & 0 deletions DAL/MODELS.FileSharing/Entities/Link.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace MODELS.FileSharing.Entities;

[Table("Links", Schema = "dbo")]
[EntityTypeConfiguration(typeof(LinkConfiguration))]
public partial class Link : BaseEntity
{
#region fields
[Required]
public string url { get; set; }

[Required]
[DisplayName("File Item")]
public int FileItemId { get; set; }

[ForeignKey(nameof(FileItemId))]
[InverseProperty(nameof(FileItem.Links))]
public virtual FileItem FileItemNavigation { get; set; }

[Required]
public DateTime CreatedAt { get; set; }

[Required]
public DateTime ValidTo { get; set; }

[Required]
public DateTime LastChanged { get; set; }

[Required]
[DisplayName("Owner")]
public int UserId { get; set; }

[ForeignKey(nameof(UserId))]
[InverseProperty(nameof(User.Links))]
public virtual User UserNavigation { get; set; }

public bool IsActive { get; set; }

[StringLength(200)]
public string? Name { get; set; }

public string? Description { get; set; }

[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string? Display { get; set; }
#endregion

#region ctors
public Link()
{
// TODO
}
#endregion

#region methods
public override string ToString()
{
return $"{Name} is a Link from {UserNavigation.UserName} with ID {Id}";
}
#endregion
}
2 changes: 2 additions & 0 deletions DAL/MODELS.FileSharing/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public class User : IdentityUser
{
[InverseProperty(nameof(Link.UserNavigation))]
public virtual IEnumerable<Link> Links { get; set; } = new List<Link>();
}

0 comments on commit c536c05

Please sign in to comment.