Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Analysim.Core/Entities/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class Project
// Comments
public ICollection<ProjectComment> ProjectComments { get; set; } = new List<ProjectComment>();

// Logs
public ICollection<ProjectLog> ProjectLogs { get; set; } = new List<ProjectLog>();
public ICollection<Publication> Publications { get; set; } = new List<Publication>();

public int ForkedFromProjectID { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/Analysim.Core/Entities/ProjectComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
public int ProjectID { get; set; }
public Project Project{ get; set; } = null!;

// Is this comment linked to a Project Log?
[ForeignKey("ProjectLog")]
public int? ProjectLogID { get; set; }
public ProjectLog? ProjectLog { get; set; }

Check warning on line 27 in src/Analysim.Core/Entities/ProjectComment.cs

View workflow job for this annotation

GitHub Actions / backend-smoke-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

// Is this comment a reply?
[ForeignKey("ParentComment")]
public int? ParentCommentID { get; set; }
public ProjectComment? ParentComment { get; set; }

Check warning on line 32 in src/Analysim.Core/Entities/ProjectComment.cs

View workflow job for this annotation

GitHub Actions / backend-smoke-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

// Comment content
public string Content { get; set; } = string.Empty;
Expand Down
46 changes: 46 additions & 0 deletions src/Analysim.Core/Entities/ProjectLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Core.Entities
{
public class ProjectLog
{
// PK
[KeyAttribute]
public int LogID { get; set; }

// Project Log Author
[ForeignKey("User")]
public int UserID { get; set; }
public User User { get; set; } = null!;

// Project Log is linked to
[ForeignKey("Project")]
public int ProjectID { get; set; }
public Project Project{ get; set; } = null!;

// Project Log Title
public string? Title { get; set; }

Check warning on line 25 in src/Analysim.Core/Entities/ProjectLog.cs

View workflow job for this annotation

GitHub Actions / backend-smoke-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

// Project Log Image
public int? BlobFileID { get; set; }
public BlobFile? BlobFile { get; set; }

Check warning on line 29 in src/Analysim.Core/Entities/ProjectLog.cs

View workflow job for this annotation

GitHub Actions / backend-smoke-test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

// Project Log Content
[Required]
public string Content { get; set; } = string.Empty;

// Soft Delete
public bool IsDeleted { get; set; }

// Timestamps
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
public DateTime? ExpiresAt { get; set; }

// Replies to this Project Log
public ICollection<ProjectComment> Comments { get; set; } = new List<ProjectComment>();
}
}
3 changes: 3 additions & 0 deletions src/Analysim.Core/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class User : IdentityUser<int>
public ICollection<ProjectCommentLike> CommentLikes { get; set; } = new List<ProjectCommentLike>();
public ICollection<ProjectCommentFlag> CommentFlags { get; set; } = new List<ProjectCommentFlag>();

// Logs
public ICollection<ProjectLog> ProjectLogs { get; set; } = new List<ProjectLog>();

public string RegistrationSurvey {get; set;}

}
Expand Down
42 changes: 42 additions & 0 deletions src/Analysim.Infrastructure/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,47 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

#endregion

#region Project Logs

// One To Many Relationship (Project -> ProjectLog)
modelBuilder.Entity<Project>()
.HasMany(p => p.ProjectLogs)
.WithOne(pl => pl.Project)
.HasForeignKey(pl => pl.ProjectID)
.OnDelete(DeleteBehavior.Cascade);

// One To Many Relationship (User -> ProjectLog)
modelBuilder.Entity<User>()
.HasMany(u => u.ProjectLogs)
.WithOne(pl => pl.User)
.HasForeignKey(pl => pl.UserID)
.OnDelete(DeleteBehavior.Restrict);

// Optional One To Many Relationship (BlobFile -> ProjectLog)
modelBuilder.Entity<ProjectLog>()
.HasOne(pl => pl.BlobFile)
.WithMany()
.HasForeignKey(pl => pl.BlobFileID)
.OnDelete(DeleteBehavior.SetNull);

// One To Many Relationship (ProjectLog -> ProjectComment)
modelBuilder.Entity<ProjectLog>()
.HasMany(pl => pl.Comments)
.WithOne(pc => pc.ProjectLog)
.HasForeignKey(pc => pc.ProjectLogID)
.OnDelete(DeleteBehavior.Restrict);

modelBuilder.Entity<ProjectLog>()
.HasIndex(pl => pl.ProjectID);

modelBuilder.Entity<ProjectLog>()
.HasIndex(pl => pl.UserID);

modelBuilder.Entity<ProjectComment>()
.HasIndex(pc => pc.ProjectLogID);

#endregion

// One To Many Relationship (Project -> Publication)
modelBuilder.Entity<Project>()
.HasMany(p => p.Publications)
Expand All @@ -207,6 +248,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
public DbSet<ProjectComment> ProjectComments { get; set; }
public DbSet<ProjectCommentLike> ProjectCommentLikes { get; set; }
public DbSet<ProjectCommentFlag> ProjectCommentFlags { get; set; }
public DbSet<ProjectLog> ProjectLogs { get; set; }

public DbSet<Publication> Publications { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("ProjectID")
.HasColumnType("integer");

b.Property<int?>("ProjectLogID")
.HasColumnType("integer");

b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone");

Expand All @@ -280,6 +283,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("ProjectID");

b.HasIndex("ProjectLogID");

b.HasIndex("UserID");

b.ToTable("ProjectComments");
Expand Down Expand Up @@ -333,6 +338,53 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("ProjectCommentLikes");
});

modelBuilder.Entity("Core.Entities.ProjectLog", b =>
{
b.Property<int>("LogID")
.ValueGeneratedOnAdd()
.HasColumnType("integer");

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("LogID"));

b.Property<int?>("BlobFileID")
.HasColumnType("integer");

b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");

b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");

b.Property<DateTime?>("ExpiresAt")
.HasColumnType("timestamp with time zone");

b.Property<bool>("IsDeleted")
.HasColumnType("boolean");

b.Property<int>("ProjectID")
.HasColumnType("integer");

b.Property<string>("Title")
.HasColumnType("text");

b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone");

b.Property<int>("UserID")
.HasColumnType("integer");

b.HasKey("LogID");

b.HasIndex("BlobFileID");

b.HasIndex("ProjectID");

b.HasIndex("UserID");

b.ToTable("ProjectLogs");
});

modelBuilder.Entity("Core.Entities.ProjectTag", b =>
{
b.Property<int>("ProjectID")
Expand Down Expand Up @@ -761,6 +813,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("Core.Entities.ProjectLog", "ProjectLog")
.WithMany("Comments")
.HasForeignKey("ProjectLogID")
.OnDelete(DeleteBehavior.Restrict);

b.HasOne("Core.Entities.User", "User")
.WithMany("ProjectComments")
.HasForeignKey("UserID")
Expand All @@ -771,6 +828,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("Project");

b.Navigation("ProjectLog");

b.Navigation("User");
});

Expand Down Expand Up @@ -812,6 +871,32 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("User");
});

modelBuilder.Entity("Core.Entities.ProjectLog", b =>
{
b.HasOne("Core.Entities.BlobFile", "BlobFile")
.WithMany()
.HasForeignKey("BlobFileID")
.OnDelete(DeleteBehavior.SetNull);

b.HasOne("Core.Entities.Project", "Project")
.WithMany("ProjectLogs")
.HasForeignKey("ProjectID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("Core.Entities.User", "User")
.WithMany("ProjectLogs")
.HasForeignKey("UserID")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();

b.Navigation("BlobFile");

b.Navigation("Project");

b.Navigation("User");
});

modelBuilder.Entity("Core.Entities.ProjectTag", b =>
{
b.HasOne("Core.Entities.Project", "Project")
Expand Down Expand Up @@ -951,6 +1036,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("ProjectComments");

b.Navigation("ProjectLogs");

b.Navigation("ProjectTags");

b.Navigation("ProjectUsers");
Expand All @@ -967,6 +1054,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("Replies");
});

modelBuilder.Entity("Core.Entities.ProjectLog", b =>
{
b.Navigation("Comments");
});

modelBuilder.Entity("Core.Entities.Tag", b =>
{
b.Navigation("ProjectTags");
Expand All @@ -986,6 +1078,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("ProjectComments");

b.Navigation("ProjectLogs");

b.Navigation("ProjectUsers");
});
#pragma warning restore 612, 618
Expand Down
Loading
Loading