The MessageSystem is based on Subject instead of Content (just semantics)
This commit is contained in:
@@ -3,11 +3,9 @@
|
||||
public class Message
|
||||
{
|
||||
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 DateTime CreatedAt { get; }
|
||||
|
||||
public Guid ParentId { get; init; }
|
||||
|
||||
public string Value { get; init; } = null!;
|
||||
}
|
||||
|
||||
@@ -11,18 +11,18 @@ public class GetMessages(
|
||||
public override void Configure()
|
||||
{
|
||||
Tags("Messages");
|
||||
Get("/api/messages/{ContentId:guid}");
|
||||
Get("/api/messages/{SubjectId:guid}");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(
|
||||
CancellationToken ct)
|
||||
{
|
||||
var contentId = Route<Guid>("ContentId");
|
||||
var subjectId = Route<Guid>("SubjectId");
|
||||
|
||||
var comments = await context
|
||||
.Messages
|
||||
.Where(c => c.ContentId == contentId)
|
||||
.Where(c => c.SubjectId == subjectId)
|
||||
.ToListAsync(cancellationToken: ct);
|
||||
|
||||
await SendAsync(comments, cancellation: ct);
|
||||
|
||||
@@ -5,7 +5,7 @@ using Hutopy.Web.Messages.Data;
|
||||
namespace Hutopy.Web.Messages.Handlers;
|
||||
|
||||
public record PostMessageRequest(
|
||||
Guid ContentId,
|
||||
Guid SubjectId,
|
||||
string Message);
|
||||
|
||||
public class PostMessage(
|
||||
@@ -25,7 +25,7 @@ public class PostMessage(
|
||||
{
|
||||
await context.Messages.AddAsync(
|
||||
new Message {
|
||||
ContentId = req.ContentId,
|
||||
SubjectId = req.SubjectId,
|
||||
CreatedBy = User.GetUserId(),
|
||||
Value = req.Message },
|
||||
ct);
|
||||
|
||||
@@ -5,7 +5,7 @@ using Hutopy.Web.Messages.Data;
|
||||
namespace Hutopy.Web.Messages.Handlers;
|
||||
|
||||
public record PostReplyMessageRequest(
|
||||
Guid ContentId,
|
||||
Guid SubjectId,
|
||||
Guid ParentId,
|
||||
string Message);
|
||||
|
||||
@@ -26,7 +26,7 @@ public sealed class PostReplyMessage(
|
||||
await context.Messages.AddAsync(
|
||||
new Message
|
||||
{
|
||||
ContentId = req.ContentId,
|
||||
SubjectId = req.SubjectId,
|
||||
ParentId = req.ParentId,
|
||||
CreatedBy = User.GetUserId(),
|
||||
Value = req.Message
|
||||
|
||||
58
src/Web/Migrations/20240707023204_UseSubjectId_InsteadOfContentId.Designer.cs
generated
Normal file
58
src/Web/Migrations/20240707023204_UseSubjectId_InsteadOfContentId.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user