Add synced user notes

This commit is contained in:
hz
2026-07-18 22:22:29 -05:00
parent a232e18c46
commit d0bb271b14
22 changed files with 930 additions and 2 deletions
+49
View File
@@ -0,0 +1,49 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace QuestionsApi.Models;
public sealed class UserNotepad
{
[BsonId, BsonRepresentation(BsonType.ObjectId)] public string? Id { get; set; }
public string UserId { get; set; } = "";
public string Content { get; set; } = "";
public long Revision { get; set; }
public DateTime CreatedUtc { get; set; } = DateTime.UtcNow;
public DateTime UpdatedUtc { get; set; } = DateTime.UtcNow;
}
public sealed class UpdateUserNotepadRequest
{
public string Content { get; set; } = "";
public long ExpectedRevision { get; set; }
}
public sealed class UserNotepadResponse
{
public string Content { get; set; } = "";
public long Revision { get; set; }
public DateTime? UpdatedUtc { get; set; }
public static UserNotepadResponse Empty() => new();
public static UserNotepadResponse FromModel(UserNotepad note) => new()
{
Content = note.Content,
Revision = note.Revision,
UpdatedUtc = note.UpdatedUtc
};
}
public static class UserNotepadValidator
{
public const int MaxContentLength = 50_000;
public static string? Validate(UpdateUserNotepadRequest request)
{
if (request.ExpectedRevision < 0) return "expectedRevision cannot be negative";
if ((request.Content ?? "").Length > MaxContentLength)
return $"content must be {MaxContentLength} characters or fewer";
return null;
}
}