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
43 changes: 43 additions & 0 deletions src/Analysim.Core/Entities/Notification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Core.Entities
{
public enum NotificationType
{
ProjectInvitation,
NewFollower,
SecurityAlert
}

public class Notification
{
[Key]
public int Id { get; set; }

[Required]
public int UserId { get; set; }

[ForeignKey(nameof(UserId))]
public User User { get; set; }

[Required]
[MaxLength(200)]
public string Title { get; set; }

[Required]
[MaxLength(1000)]
public string Message { get; set; }

[Required]
public NotificationType Type { get; set; }

public bool IsRead { get; set; } = false;

[MaxLength(500)]
public string LinkUrl { get; set; }

public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
}
}
3 changes: 3 additions & 0 deletions src/Analysim.Core/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public class User : IdentityUser<int>
public ICollection<UserUser> Following { get; } = new List<UserUser>();
public ICollection<ProjectUser> ProjectUsers { get; } = new List<ProjectUser>();
public ICollection<BlobFile> BlobFiles { get; } = new List<BlobFile>();
public ICollection<Notification> Notifications { get; } = new List<Notification>();

public string RegistrationSurvey {get; set;}

public string LastLoginIp { get; set; }

}
}
10 changes: 10 additions & 0 deletions src/Analysim.Core/Interfaces/INotificationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Core.Entities;
using System.Threading.Tasks;

namespace Core.Interfaces
{
public interface INotificationService
{
Task SendNotificationAsync(int userId, string title, string message, NotificationType type, string linkUrl);
}
}
8 changes: 8 additions & 0 deletions src/Analysim.Infrastructure/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.WithMany(n=>n.observableNotebookDatasets)
.HasForeignKey(d=>d.NotebookID)
.OnDelete(DeleteBehavior.Cascade);

// One To Many Relationship (User -> Notifications)
modelBuilder.Entity<User>()
.HasMany(u => u.Notifications)
.WithOne(n => n.User)
.HasForeignKey(n => n.UserId)
.OnDelete(DeleteBehavior.Cascade);
}


Expand All @@ -121,6 +128,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
public DbSet<ObservableNotebookDataset> ObservableNotebookDataset { get;set;}
public DbSet<NotebookContent> NotebookContent { get; set; }
public DbSet<BlobFileContent> BlobFileContent { get; set; }
public DbSet<Notification> Notifications { get; set; }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,47 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Notebook");
});

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

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

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

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

b.Property<string>("LinkUrl")
.HasMaxLength(500)
.HasColumnType("character varying(500)");

b.Property<string>("Message")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("character varying(1000)");

b.Property<string>("Title")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");

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

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

b.HasKey("Id");

b.HasIndex("UserId");

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

modelBuilder.Entity("Core.Entities.ObservableNotebookDataset", b =>
{
b.Property<int>("ID")
Expand Down Expand Up @@ -328,6 +369,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");

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

b.Property<DateTimeOffset>("LastOnline")
.HasColumnType("timestamp with time zone");

Expand Down Expand Up @@ -428,21 +472,21 @@ protected override void BuildModel(ModelBuilder modelBuilder)
new
{
Id = 1,
ConcurrencyStamp = "ebd0169f-30be-4ab7-9fb9-038a9de20efb",
ConcurrencyStamp = "b4bb5161-16f0-43aa-9033-b01d1a7a2474",
Name = "Admin",
NormalizedName = "ADMIN"
},
new
{
Id = 2,
ConcurrencyStamp = "371acb40-c941-4714-9c2c-bc9de9bff144",
ConcurrencyStamp = "f4a579fd-f47f-4ec4-8b67-3dce047786c0",
Name = "Customer",
NormalizedName = "CUSTOMER"
},
new
{
Id = 3,
ConcurrencyStamp = "7ee39326-5034-4323-85cc-6da801861458",
ConcurrencyStamp = "6050bbb3-a5ad-439a-9eac-7149501bc57d",
Name = "Moderator",
NormalizedName = "MODERATOR"
});
Expand Down Expand Up @@ -601,6 +645,17 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Navigation("Project");
});

modelBuilder.Entity("Core.Entities.Notification", b =>
{
b.HasOne("Core.Entities.User", "User")
.WithMany("Notifications")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

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

modelBuilder.Entity("Core.Entities.ObservableNotebookDataset", b =>
{
b.HasOne("Core.Entities.Notebook", "notebook")
Expand Down Expand Up @@ -756,6 +811,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("Following");

b.Navigation("Notifications");

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