Aanbod: RESTful routes zonder /admin, één OfferingDto en herordenen via PUT /offerings/order
Admin en bezoeker gebruiken dezelfde resource; alleen GET is anoniem, de rest vereist AdminOnly. OfferingAdminDto vervalt (displayOrder zit nu in OfferingDto), move-up/move-down zijn vervangen door de order-route die een onbekende of onvolledige lijst met 400 afwijst. De admin-frontend en alle tests zijn mee aangepast. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
# CMS-U0 offerings-restful-routes: code summary
|
||||
|
||||
## Routes (all under /api/v1/offerings)
|
||||
GET (anonymous, rate limit offerings-public), POST (201 + Location), PUT {id:guid}, DELETE {id:guid}, PUT order {orderedIds}. All except GET are AdminOnly. No /admin segment; move-up/move-down removed. Order route returns 400 (ProblemDetails) unless the list holds every existing offering exactly once.
|
||||
|
||||
## DTO (decision A)
|
||||
One OfferingDto for everybody, now including displayOrder; OfferingAdminDto removed. Handoff for the SLP site: displayOrder is an additive field on the public response and is ignored by the site (as is categoryId later); array order is still the display order.
|
||||
|
||||
## Backend files
|
||||
Modules.Offerings: OfferingsController, IOfferingsService/OfferingsService (GetOfferingsAsync, validated ReorderAsync), OfferingOrderInvalidException, OfferingDto, repository (GetPrevious/GetNext removed).
|
||||
Tests: route-table test (only GET anonymous, class AdminOnly, no admin segment, exact route set), 201+Location, order 400 (controller and service: unknown, incomplete, duplicate ids), displayOrder in DTO.
|
||||
|
||||
## Frontend (frontend/src/features/offerings)
|
||||
Services use the new URLs; OfferingAdminDto renamed OfferingDto; useMoveOffering computes the new order from the cached list and calls PUT /offerings/order; msw handlers and tests updated, plus a test that move-down sends the full new order.
|
||||
|
||||
## Verification (real output)
|
||||
dotnet build SlpModularCms.sln: 0 errors. Offerings.Tests 52 passed; Core.Tests 196 passed; Availability.Tests 82 passed; Identity.Tests 37 passed; Master.Tests 57 passed; Api.Tests 4 passed (with a local MariaDB container; without a database 4 fail with connection refused, also on clean master d9cc539). Frontend: vitest 41 files / 260 tests passed; eslint clean; tsc -b clean. prettier --check reports pre-existing style warnings on untouched files (not addressed).
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
# Code Generation Plan — CMS-U0 offerings-restful-routes
|
||||
|
||||
Decision (Bryan via Redesign - SLS): no `/admin` segment in API routes; admin uses the same resource with the same verbs, access via authorization (`AdminOnly`), public endpoints via `[PublicSiteEndpoint]` (CMS-U2). Applies now to Offerings, in this feature, before the category units. API and admin frontend are deployed together, so **no old routes are kept**.
|
||||
|
||||
## Unit context
|
||||
- **Phase 1**, base master `d9cc539`, first unit. No data model change, no migration.
|
||||
- **Touches**: `Modules.Offerings` (controller, service, DTOs, tests) and `frontend/src/features/offerings` (api calls, mocks, tests). Does **not** touch Core, Availability, Identity, ASF-owned areas (auth/refresh, users, theme assets).
|
||||
|
||||
## Route mapping
|
||||
| Today | New | Auth |
|
||||
|---|---|---|
|
||||
| `GET /offerings` (public DTO) | `GET /offerings` (single DTO, see below) | anonymous (rate limit `offerings-public` unchanged; `[PublicSiteEndpoint]` added in CMS-U2) |
|
||||
| `GET /offerings/admin` | removed (same `GET /offerings`) | |
|
||||
| `POST /offerings/admin` | `POST /offerings` | AdminOnly, 201 + `Location: /api/v1/offerings/{id}` |
|
||||
| `PUT /offerings/admin/{id}` | `PUT /offerings/{id:guid}` | AdminOnly |
|
||||
| `DELETE /offerings/admin/{id}` | `DELETE /offerings/{id:guid}` | AdminOnly (soft delete unchanged) |
|
||||
| `PUT /offerings/admin/reorder` | `PUT /offerings/order` body `{ "orderedIds": [...] }` | AdminOnly (collection action, `order` cannot clash with `{id:guid}`) |
|
||||
| `POST .../{id}/move-up`, `.../move-down` | removed | UI computes the new order and calls `PUT /offerings/order` |
|
||||
|
||||
`PATCH` is not introduced (no partial-update use case); `PUT` keeps its current full-replace semantics.
|
||||
|
||||
## Design question: public vs admin DTO on one URL
|
||||
Today the admin DTO differs from the public DTO by exactly one field: `displayOrder`.
|
||||
- **Recommended (A)**: one URL, **one DTO for everybody**, `OfferingDto` gains `displayOrder` (additive, harmless to the SLS frontend which already relies on array order). No auth-dependent response => no `Vary: Authorization`, no cache split, a single OpenAPI schema, `OfferingAdminDto` is deleted.
|
||||
- Alternative (B): auth-dependent DTO on the same URL: needs `Vary: Authorization`/no shared caching, an OpenAPI `oneOf`, and hides nothing sensitive. Alternative (C): `?view=admin` query switch: not RESTful-pure, adds a parameter for one integer.
|
||||
- Other side effects of (A): the `offerings-public` limiter (120/min) now also covers admin list calls (fine).
|
||||
Needs your OK; default is A.
|
||||
|
||||
## Steps
|
||||
- [x] **Step 1 — DTO**: `OfferingDto` gets `int DisplayOrder` (appended); delete `OfferingAdminDto`; service `GetPublicOfferingsAsync`/`GetAllForAdminAsync` collapse into `GetOfferingsAsync`.
|
||||
- [x] **Step 2 — Controller routes**: rewrite `OfferingsController` per the table; class stays `[Authorize(Policy = "AdminOnly")]` with `[AllowAnonymous]` only on `GET`; `Create` returns `Created("/api/v1/offerings/{id}", dto)`; remove `MoveUp`/`MoveDown` actions and `IOfferingsService.MoveUpAsync/MoveDownAsync` (+ repository `GetPreviousAsync/GetNextAsync` if unused elsewhere); reorder route `order`.
|
||||
- [x] **Step 3 — Backend tests**: update `OfferingsControllerTests`, `OfferingsServiceTests`, repository tests (removed methods); add a route-table test (reflection over `OfferingsController` action routes + auth attributes: only `GET` is anonymous, all other actions inherit `AdminOnly`, no route contains `admin`).
|
||||
- [x] **Step 4 — Frontend**: change URLs in `useOfferings`, `useCreateOffering`, `useUpdateOffering`, `useDeleteOffering`, `useReorderOfferings`; `useMoveOffering` computes the new id order client-side and calls `PUT /offerings/order` (keeps the UI buttons); `types.ts`: `OfferingAdminDto` becomes `OfferingDto` incl. `displayOrder` (or alias); update `mocks/handlers.ts` and tests (`OfferingsListPage.test.tsx`, `OfferingFormPage.test.tsx`, any others that assert URLs).
|
||||
- [x] **Step 5 — Build + test (automatic)**: `dotnet build` solution; `dotnet test` Offerings.Tests (and Core.Tests/Availability.Tests as regression); `Api.Tests` need a local MySQL (they fail here with "connection refused" independent of this change; will be reported as such); frontend: lint + type-check + unit tests (`npm`/`pnpm` scripts as in `frontend/package.json`). Report real output.
|
||||
- [x] **Step 6 — Docs**: summary in `construction/cms-u0-offerings-restful-routes/code/summary.md`, incl. the handoff note for the SLS site: `GET /api/v1/offerings` unchanged except the additive `displayOrder`.
|
||||
- [x] **Step 7 — Commit** (one commit, Dutch message, Co-Authored-By line). No push.
|
||||
|
||||
## Explicitly NOT touched
|
||||
Core, Availability (incl. `POST admin/status`, see below), Identity, Master, host config, `[PublicSiteEndpoint]` (CMS-U2), OpenAPI export (CMS-U3), category work (CMS-U1), ASF-owned frontend areas.
|
||||
|
||||
## Findings for other controllers (report only)
|
||||
- Only `AvailabilityController` has another `admin` segment: `POST /availability/admin/status`. Per your instruction it becomes `PUT /availability/status` (AdminOnly; `GET /availability/status` stays public) **in Phase 2, after the ASF merge**, checking callers: Master/SlaveStatus, poll client, frontend.
|
||||
- No other controller has an `admin` segment. Several are verb-style RPC routes (`Auth/login`, `Auth/revoke`, `Master/register`, `Master/status` POST, `CmsInstance/{id}/status` PUT) — not changed; flagged for your later RESTful review.
|
||||
|
||||
## Traceability
|
||||
Bryan's route decision (SLS message), contract § 6/§ 7 (to be aligned by SLS); Security: authorization unchanged in effect (only `GET` anonymous), covered by the route-table test.
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
# Code Generation Plan — CMS-U1 offerings-category (REVISED v2: categories are CMS data)
|
||||
|
||||
Supersedes v1 (appsettings list, `OfferingsOptions`, `offerings/admin/categories`). Decision (Bryan via Redesign - SLS): categories are data managed in the CMS as part of Offerings (sub-section/dialog, not a new page); Bryan creates "Websites" and "Onderhoud" himself — **nothing is seeded in code**. Contract § 7 updated by SLS. Builds on CMS-U0 (RESTful routes, single `OfferingDto`).
|
||||
|
||||
## What v1 had already been done (now stashed, not committed)
|
||||
Built and green (74 Offerings tests) but based on `offerings/admin` routes and the appsettings list: `Offering.Category` string column + migration `AddOfferingCategory`, `OfferingsOptions`, `Offerings:Categories` in `Api.SlpSoftware/appsettings.json`, service validation + legacy-value rule, tests. Parked in `git stash` ("cms-u1-v1-…"). Reused: test scaffolding patterns only. Dropped: `OfferingsOptions`, appsettings key, legacy-value rule, string column and its migration.
|
||||
|
||||
## Data model
|
||||
- `OfferingCategory`: `Id` (Guid), `Name` (varchar 100, required, trimmed), `SortOrder` (int), `CreatedAt`, `UpdatedAt`. Unique index on `Name` (MySQL default collation is case-insensitive; the service also checks case-insensitively because InMemory tests do not enforce the index).
|
||||
- `Offering.CategoryId` (Guid?, nullable) FK -> `OfferingCategory`, `DeleteBehavior.Restrict`.
|
||||
- Migration `AddOfferingCategories` (Offerings context): new table + nullable column + FK + index. Additive; `Down` drops them. Generated with `dotnet ef` (the tool worked in v1: 9.0.19 produced a clean EF 10 migration).
|
||||
|
||||
## Routes (`/api/v1/offerings/categories`, all AdminOnly, no `/admin`)
|
||||
| Route | Behaviour |
|
||||
|---|---|
|
||||
| `GET /offerings/categories` | list ordered by `SortOrder`, `Name`; each item `{ id, name, sortOrder, offeringCount }` (count of non-deleted offerings, for the UI) |
|
||||
| `POST /offerings/categories` | body `{ name }`; 201 + Location; duplicate name (case-insensitive) => 409 ProblemDetails; blank/too long => 400 |
|
||||
| `PUT /offerings/categories/{id:guid}` | rename (`{ name }`); duplicate => 409; unknown id => 404; offerings follow automatically (FK) |
|
||||
| `DELETE /offerings/categories/{id:guid}` | 409 ProblemDetails while non-deleted offerings use it ("move the offerings first"); otherwise deleted (soft-deleted offerings that still point to it get `CategoryId = null` in the same transaction); unknown id => 404 |
|
||||
Route `categories` cannot clash with `{id:guid}` on `/offerings`. Ordering/reordering of categories: **not in this unit** (order = creation order via `SortOrder`; reorder endpoint can be added cheaply later: `PUT /offerings/categories/order`).
|
||||
|
||||
## Offering changes
|
||||
- `CreateOfferingRequest`/`UpdateOfferingRequest` gain `Guid? CategoryId`; if given it must exist => else `400` ValidationProblemDetails `errors.categoryId = ["invalid"]`; `null` clears the category.
|
||||
- Single `OfferingDto` (from CMS-U0) gains `CategoryId` (Guid?, string in JSON like `Id`) and `Category` (name | null). Public JSON therefore carries `category` as the name or `null` (unchanged shape for the SLS frontend) plus the additive `categoryId`/`displayOrder`.
|
||||
|
||||
## Steps
|
||||
- [ ] **Step 1 — Revert v1 leftovers**: confirm the working tree only contains CMS-U0 (stash holds v1); delete nothing committed.
|
||||
- [ ] **Step 2 — Entities + DbContext**: `OfferingCategory`, `Offering.CategoryId` + navigation, mapping, unique index, FK Restrict; `Include` the category in `OfferingRepository` reads.
|
||||
- [ ] **Step 3 — Repository**: `IOfferingCategoryRepository` (list with usage counts, get, add, remove, exists-by-name case-insensitive, clear category on soft-deleted offerings); transaction support as in `OfferingRepository`.
|
||||
- [ ] **Step 4 — Services**: `IOfferingCategoriesService` (list/create/rename/delete with the rules above; exceptions `OfferingCategoryNameConflictException`, `OfferingCategoryInUseException`); `OfferingsService` validates `CategoryId` exists and maps `CategoryId`/`Category` into `OfferingDto`.
|
||||
- [ ] **Step 5 — Controllers**: `OfferingCategoriesController` (route `offerings/categories`, class-level `AdminOnly`) with ProblemDetails mapping (409 conflict, 409 in-use, 404, 400); `OfferingsController` handles invalid `categoryId` as 400.
|
||||
- [ ] **Step 6 — Migration** `AddOfferingCategories`.
|
||||
- [ ] **Step 7 — Tests (Offerings.Tests)**: category service (create trims, duplicate case-insensitive => conflict, rename conflict, rename unknown, delete in use => in-use, delete unused ok, delete clears soft-deleted references, list with counts and order); offering service (unknown `categoryId` => invalid, null clears, DTO carries id+name, rename visible through DTO); controller mapping (201/404/409/400); repository (FK round trip, case-insensitive exists); route-table test from CMS-U0 extended (all `categories` actions AdminOnly, none anonymous).
|
||||
- [ ] **Step 8 — Build + test (automatic)**: solution build; Offerings.Tests, Core.Tests, Availability.Tests; `Api.Tests` needs a local MySQL (fails here with "connection refused" regardless of the change). Report real output.
|
||||
- [ ] **Step 9 — Docs/handoff**: summary + handoff note for the SLS frontend (public `category` = name|null; additive `categoryId`) and for CMS-U1b (route list above).
|
||||
- [ ] **Step 10 — Commit** (one commit, no push).
|
||||
|
||||
## Explicitly NOT touched
|
||||
Core, Availability, Identity, host config/appsettings (no `Offerings:Categories` anymore), the marker (CMS-U2), OpenAPI export (CMS-U3), frontend (CMS-U1b).
|
||||
|
||||
## CMS-U1b outline (own plan after U1 is done)
|
||||
Categorieën sub-section/dialog inside the Offerings admin (list with offering counts, add, rename, delete with the 409 message), plus a select in `OfferingForm` (`categoryId`, "geen categorie" option); services/hooks/mocks/tests under `frontend/src/features/offerings` only; ASF-owned frontend areas untouched.
|
||||
Reference in New Issue
Block a user