The MessageSystem is based on Subject instead of Content (just semantics)

This commit is contained in:
Jonathan Bourdon
2024-07-06 22:36:22 -04:00
parent 256fa3df91
commit ca94dba08d
6 changed files with 88 additions and 10 deletions

View File

@@ -3,11 +3,9 @@
public class Message public class Message
{ {
public Guid Id { get; init; } public Guid Id { get; init; }
public Guid ContentId { get; init; } // works for any - VideoId, ChatId, RoomId, xxxId, ForumId public Guid SubjectId { get; init; }
public Guid CreatedBy { get; init; } public Guid CreatedBy { get; init; }
public DateTime CreatedAt { get; } public DateTime CreatedAt { get; }
public Guid ParentId { get; init; } public Guid ParentId { get; init; }
public string Value { get; init; } = null!; public string Value { get; init; } = null!;
} }

View File

@@ -11,18 +11,18 @@ public class GetMessages(
public override void Configure() public override void Configure()
{ {
Tags("Messages"); Tags("Messages");
Get("/api/messages/{ContentId:guid}"); Get("/api/messages/{SubjectId:guid}");
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync( public override async Task HandleAsync(
CancellationToken ct) CancellationToken ct)
{ {
var contentId = Route<Guid>("ContentId"); var subjectId = Route<Guid>("SubjectId");
var comments = await context var comments = await context
.Messages .Messages
.Where(c => c.ContentId == contentId) .Where(c => c.SubjectId == subjectId)
.ToListAsync(cancellationToken: ct); .ToListAsync(cancellationToken: ct);
await SendAsync(comments, cancellation: ct); await SendAsync(comments, cancellation: ct);

View File

@@ -5,7 +5,7 @@ using Hutopy.Web.Messages.Data;
namespace Hutopy.Web.Messages.Handlers; namespace Hutopy.Web.Messages.Handlers;
public record PostMessageRequest( public record PostMessageRequest(
Guid ContentId, Guid SubjectId,
string Message); string Message);
public class PostMessage( public class PostMessage(
@@ -25,7 +25,7 @@ public class PostMessage(
{ {
await context.Messages.AddAsync( await context.Messages.AddAsync(
new Message { new Message {
ContentId = req.ContentId, SubjectId = req.SubjectId,
CreatedBy = User.GetUserId(), CreatedBy = User.GetUserId(),
Value = req.Message }, Value = req.Message },
ct); ct);

View File

@@ -5,7 +5,7 @@ using Hutopy.Web.Messages.Data;
namespace Hutopy.Web.Messages.Handlers; namespace Hutopy.Web.Messages.Handlers;
public record PostReplyMessageRequest( public record PostReplyMessageRequest(
Guid ContentId, Guid SubjectId,
Guid ParentId, Guid ParentId,
string Message); string Message);
@@ -26,7 +26,7 @@ public sealed class PostReplyMessage(
await context.Messages.AddAsync( await context.Messages.AddAsync(
new Message new Message
{ {
ContentId = req.ContentId, SubjectId = req.SubjectId,
ParentId = req.ParentId, ParentId = req.ParentId,
CreatedBy = User.GetUserId(), CreatedBy = User.GetUserId(),
Value = req.Message Value = req.Message

View File

@@ -0,0 +1,58 @@
// <auto-generated />
using System;
using Hutopy.Web.Contents.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Hutopy.Web.Migrations
{
[DbContext(typeof(ContentDbContext))]
[Migration("20240707023204_UseSubjectId_InsteadOfContentId")]
partial class UseSubjectId_InsteadOfContentId
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Hutopy.Web.Contents.Data.Content", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime>("CreatedAt")
.ValueGeneratedOnAdd()
.HasColumnType("datetime2")
.HasDefaultValueSql("CURRENT_TIMESTAMP");
b.Property<Guid>("CreatedBy")
.HasColumnType("uniqueidentifier");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.HasColumnType("nvarchar(max)");
b.Property<string>("Uri")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Contents");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Hutopy.Web.Migrations
{
/// <inheritdoc />
public partial class UseSubjectId_InsteadOfContentId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}