🗃️ Chat room modeling
This commit is contained in:
parent
e4031478b5
commit
b675b0550b
@ -50,6 +50,9 @@ public class AppDatabase(
|
||||
|
||||
public DbSet<Realm.Realm> Realms { get; set; }
|
||||
public DbSet<Realm.RealmMember> RealmMembers { get; set; }
|
||||
|
||||
public DbSet<Chat.ChatRoom> ChatRooms { get; set; }
|
||||
public DbSet<Chat.ChatMember> ChatMembers { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@ -165,7 +168,20 @@ public class AppDatabase(
|
||||
.WithMany(p => p.Members)
|
||||
.HasForeignKey(pm => pm.RealmId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<Post.PublisherMember>()
|
||||
modelBuilder.Entity<Realm.RealmMember>()
|
||||
.HasOne(pm => pm.Account)
|
||||
.WithMany()
|
||||
.HasForeignKey(pm => pm.AccountId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<Chat.ChatMember>()
|
||||
.HasKey(pm => new { pm.ChatRoom, pm.AccountId });
|
||||
modelBuilder.Entity<Chat.ChatMember>()
|
||||
.HasOne(pm => pm.ChatRoom)
|
||||
.WithMany(p => p.Members)
|
||||
.HasForeignKey(pm => pm.ChatRoomId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<Chat.ChatMember>()
|
||||
.HasOne(pm => pm.Account)
|
||||
.WithMany()
|
||||
.HasForeignKey(pm => pm.AccountId)
|
||||
|
15
DysonNetwork.Sphere/Chat/ChatController.cs
Normal file
15
DysonNetwork.Sphere/Chat/ChatController.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using DysonNetwork.Sphere.Account;
|
||||
using DysonNetwork.Sphere.Realm;
|
||||
using DysonNetwork.Sphere.Chat;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DysonNetwork.Sphere.Chat;
|
||||
|
||||
[ApiController]
|
||||
[Route("/chat")]
|
||||
public class ChatController(AppDatabase db) : ControllerBase
|
||||
{
|
||||
}
|
48
DysonNetwork.Sphere/Chat/ChatRoom.cs
Normal file
48
DysonNetwork.Sphere/Chat/ChatRoom.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Sphere.Chat;
|
||||
|
||||
public enum ChatRoomType
|
||||
{
|
||||
Group,
|
||||
DirectMessage
|
||||
}
|
||||
|
||||
public class ChatRoom : ModelBase
|
||||
{
|
||||
public long Id { get; set; }
|
||||
[MaxLength(1024)] public string Name { get; set; } = string.Empty;
|
||||
[MaxLength(4096)] public string Description { get; set; } = string.Empty;
|
||||
public ChatRoomType Type { get; set; }
|
||||
public bool IsPublic { get; set; }
|
||||
|
||||
public CloudFile? Picture { get; set; }
|
||||
public CloudFile? Background { get; set; }
|
||||
|
||||
[JsonIgnore] public ICollection<ChatMember> Members { get; set; } = new List<ChatMember>();
|
||||
|
||||
public long? RealmId { get; set; }
|
||||
public Realm.Realm? Realm { get; set; }
|
||||
}
|
||||
|
||||
public enum ChatMemberRole
|
||||
{
|
||||
Owner = 100,
|
||||
Moderator = 50,
|
||||
Normal = 0
|
||||
}
|
||||
|
||||
public class ChatMember : ModelBase
|
||||
{
|
||||
public long ChatRoomId { get; set; }
|
||||
[JsonIgnore] public ChatRoom ChatRoom { get; set; } = null!;
|
||||
public long AccountId { get; set; }
|
||||
[JsonIgnore] public Account.Account Account { get; set; } = null!;
|
||||
|
||||
public ChatMemberRole Role { get; set; }
|
||||
public Instant? JoinedAt { get; set; }
|
||||
public bool IsBot { get; set; } = false;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
using DysonNetwork.Sphere.Chat;
|
||||
using DysonNetwork.Sphere.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
@ -22,9 +23,10 @@ public class Realm : ModelBase
|
||||
public CloudFile? Background { get; set; }
|
||||
|
||||
[JsonIgnore] public ICollection<RealmMember> Members { get; set; } = new List<RealmMember>();
|
||||
[JsonIgnore] public ICollection<ChatRoom> ChatRooms { get; set; } = new List<ChatRoom>();
|
||||
|
||||
public long AccountId { get; set; }
|
||||
[JsonIgnore] public Account.Account Account { get; set; }
|
||||
[JsonIgnore] public Account.Account Account { get; set; } = null!;
|
||||
}
|
||||
|
||||
public enum RealmMemberRole
|
||||
|
Loading…
x
Reference in New Issue
Block a user