Skip to content

Commit

Permalink
NotificationSubs.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisMend12 committed Jan 26, 2025
1 parent 1c737ec commit 7979406
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Valour/Database/NotificationSubscription.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Valour.Shared.Models;

namespace Valour.Database;
Expand Down Expand Up @@ -36,4 +37,44 @@ public class NotificationSubscription : ISharedNotificationSubscription

[Column("auth")]
public string Auth { get; set; }

public static void SetUpDbModel(ModelBuilder builder)
{
builder.Entity<NotificationSubscription>(e =>
{
// ToTable
e.ToTable("notification_subscriptions");

// Key
e.HasKey(x => x.Id);

// Properties
e.Property(x => x.Id)
.HasColumnName("id");

e.Property(x => x.UserId)
.HasColumnName("user_id");

e.Property(x => x.Key)
.HasColumnName("key");

e.Property(x => x.Auth)
.HasColumnName("auth");

// Relationships

e.HasOne(x => x.User)
.WithMany(x => x.NotificationSubscriptions)
.HasForeignKey(x => x.UserId);

// Indices

e.HasIndex(x => x.UserId)
.IsUnique();

e.HasIndex(x => x.Id)
.IsUnique();

});
}
}
5 changes: 5 additions & 0 deletions Valour/Database/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class User : ISharedUser
/// </summary>
public virtual ICollection<Referral> Rewards { get; set; }

/// <summary>
/// Notification of Subscriptions for this user.
/// </summary>
public virtual ICollection<NotificationSubscription> NotificationSubscriptions { get; set; }


///////////////////////
// Entity Properties //
Expand Down

0 comments on commit 7979406

Please sign in to comment.