Add client-side Notes page with API integration and shared contracts

This commit is contained in:
Chuck Smith
2026-02-22 15:24:56 -05:00
parent 9cf0cbadd6
commit 6a1aed8e13
17 changed files with 678 additions and 193 deletions

52
docs/ai/AI_CONTEXT.md Normal file
View File

@@ -0,0 +1,52 @@
# AI_CONTEXT.md
This repository is a Blazor sample that demonstrates a real-world “browser UI calls server API” architecture with PostgreSQL.
## Solution layout
- `Freman.Sample.Web` (Server / Host)
- ASP.NET Core host
- EF Core + PostgreSQL
- Minimal API endpoints under `/api/*`
- Applies migrations automatically in Development
- `Freman.Sample.Web.Client` (Client / Browser)
- Blazor WebAssembly UI
- Uses `HttpClient` to call server endpoints
- `/notes` page is WASM interactive with `prerender: false`
- Reusable UI components live under `Client/Components` (e.g., `ConfirmModal.razor`)
- `Freman.Sample.Web.Contracts` (Shared)
- DTOs + request models shared between server and client
- Examples: `NoteDto`, `CreateNoteRequest`
## Run modes (important)
This solution uses mixed render modes.
- Client pages that inject `HttpClient` should run in the browser:
- `@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))`
- Server-only pages can use:
- `@rendermode InteractiveServer`
Why `prerender: false`?
- Without it, the component may be instantiated on the server during prerender, where client-only DI services (like the WASM `HttpClient`) are not available.
## How to run (happy path)
- Create `.env` next to `compose.yaml`:
- `POSTGRES_PASSWORD=...`
- Run:
- `docker compose up --build`
- Navigate to:
- `/notes`
## API
- `GET /api/notes`
- `POST /api/notes`
- `DELETE /api/notes/{id}`
## Data access
- EF Core DbContext: `AppDbContext` (server)
- Entities are server-only (do not share with Client)
- Contracts are shared via `Freman.Sample.Web.Contracts`
## Conventions
- Server endpoints live in `Freman.Sample.Web/Endpoints/*` and are mapped from `Program.cs`
- Prefer small, feature-scoped endpoint files (e.g., `NotesEndpoints.cs`)
- Avoid duplicating DTOs in Client; use `Freman.Sample.Web.Contracts` instead

47
docs/ai/AI_TASKS.md Normal file
View File

@@ -0,0 +1,47 @@
# AI_TASKS.md
Quick task cookbook for common changes in this repo.
## Add a new API endpoint group
1) Create `Freman.Sample.Web/Endpoints/<Feature>Endpoints.cs`
2) Add an extension method:
- `public static IEndpointRouteBuilder Map<Feature>Endpoints(this IEndpointRouteBuilder app)`
3) Call it from `Freman.Sample.Web/Program.cs`:
- `app.Map<Feature>Endpoints();`
## Add a new Client page that calls the API
1) Create page in `Freman.Sample.Web.Client/Pages/<Page>.razor`
2) Ensure it runs as WASM and avoids server prerender DI issues:
- `@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))`
3) Inject `HttpClient`:
- `@inject HttpClient Http`
4) Call server endpoints under `/api/*`
## Add shared request/response models
1) Add to `Freman.Sample.Web.Contracts`
2) Reference contracts project from Server + Client
3) Use contracts types in endpoints + client code (avoid duplicates)
## Add an EF Core migration
From solution root:
```
powershell dotnet tool restore
dotnet tool run dotnet-ef -- migrations add --project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj --startup-project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj ` --output-dir Data\Migrations
```
## Apply migrations manually (optional)
```
powershell dotnet tool run dotnet-ef -- database update --project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj --startup-project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj
```
## Add a confirmation step in the client
Use `Freman.Sample.Web.Client/Components/ConfirmModal.razor` and call:
- `await _confirmModal.ShowAsync("Title", "Message")`