Path: redb/redb.Templates/templates/redb-identity-app/RedbIdentityApp.Module/Controllers/NotesController.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-identity-app/RedbIdentityApp.Module/Controllers/NotesController.cs ---- using redb.Core.Models.Entities; using redb.Route.Controllers.Attributes; using RedbIdentityApp.Contracts; using RedbIdentityApp.Module.Props; namespace RedbIdentityApp.Module.Controllers; /// /// The notes of the signed-in user. Every query is filtered by the token's subject: a user never reaches /// another user's note, not even by its id. /// [Route("/api/notes")] public sealed class NotesController : ApiController { /// GET /api/notes: the caller's notes, newest first. [HttpGet] public async Task List() { if (!IsUser) return Status(403, new ApiError { Message = "Notes belong to users; a client token has none." }); var owner = Subject; var notes = await Redb.Query() .Where(n => n.Owner == owner) .OrderByDescendingRedb(n => n.DateCreate) .Take(100) .ToListAsync(); return notes.Select(ToDto).ToList(); } /// POST /api/notes: a new note of the caller. [HttpPost] public async Task Create([FromBody] NoteDto note) { if (!IsUser) return Status(403, new ApiError { Message = "Notes belong to users; a client token has none." }); if (Invalid(note) is { } invalid) return invalid; var saved = new RedbObject { Name = note.Title.Trim(), Props = new Note { Owner = Subject, Text = note.Text }, }; await Redb.SaveAsync(saved); return Status(201, ToDto(saved)); } /// DELETE /api/notes/{id}: only a note of the caller; any other id is "not found". [HttpDelete("{id}")] public async Task Delete(long id) { var note = await Redb.LoadAsync(id); if (note is null || note.Props.Owner != Subject) return NotFound("No such note."); return await Redb.DeleteAsync(id) ? null : NotFound("No such note."); } private static NoteDto ToDto(RedbObject note) => new() { Id = note.Id, Title = note.Name ?? "", Text = note.Props.Text, CreatedAt = note.DateCreate, }; }