Update bookv1.0.0 · JSON Schema
Updates an existing book listing, including optional image and catalog relationships.
1. Update Book Details with Optimistic Concurrency (If-Match)
A backoffice catalog manager updates the promotional price and description of “The Left Hand of Darkness” while passing the If-Match ETag header for optimistic concurrency control.
Payload details
id: Required book UUID.name,description,price,priceSale,categoryId,publisherId,authorIds: Updated book fields sent asmultipart/form-data.isRemoveImage: Optional boolean (trueremoves the existing cover image).
Using this example
Returns 204 No Content (or 412 Precondition Failed if If-Match is stale), updates the book in PostgreSQL, invalidates FusionCache, and queues a vector embedding refresh.
using BookWorm.Chassis.Utilities.Configurations;using BookWorm.Constants.Aspire;using Refit;
public interface ICatalogApiClient{ [Multipart] [Put("/api/v1/books")] Task UpdateBookAsync( [AliasAs("id")] Guid id, [AliasAs("name")] string name, [AliasAs("description")] string description, [AliasAs("price")] decimal price, [AliasAs("priceSale")] decimal? priceSale, [AliasAs("categoryId")] Guid categoryId, [AliasAs("publisherId")] Guid publisherId, [AliasAs("authorIds")] IEnumerable<Guid> authorIds, [AliasAs("isRemoveImage")] bool isRemoveImage = false, [Header("If-Match")] string? ifMatch = null, CancellationToken cancellationToken = default );}
// DI registration following BookWorm.Chassis Refit patternbuilder.Services .AddRefitGeneratedClient<ICatalogApiClient>(settings, Services.Catalog) .ConfigureHttpClient(client => client.BaseAddress = new($"https+http://{Services.Catalog}")) .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(5) } );
// Typed invocationawait catalogApiClient.UpdateBookAsync( id: Guid.Parse("01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a10"), name: "The Left Hand of Darkness (50th Anniversary Edition)", description: "Anniversary edition with introduction by Neil Gaiman.", price: 21.99m, priceSale: 16.99m, categoryId: Guid.Parse("01960a1b-1000-7000-8a9b-0c1d2e3f4a01"), publisherId: Guid.Parse("01960a1b-2000-7000-8a9b-0c1d2e3f4a02"), authorIds: [Guid.Parse("01960a1b-3000-7000-8a9b-0c1d2e3f4a03")], isRemoveImage: false, ifMatch: "\"1\"", cancellationToken: cancellationToken);import booksApiClient from "@workspace/api-client/catalog/books";import useUpdateBook from "@workspace/api-hooks/catalog/books/useUpdateBook";
const request = { id: "01960a1b-2c3d-7e4f-8a9b-0c1d2e3f4a10", name: "The Left Hand of Darkness (50th Anniversary Edition)", description: "Anniversary edition with introduction by Neil Gaiman.", price: 21.99, priceSale: 16.99, categoryId: "01960a1b-1000-7000-8a9b-0c1d2e3f4a01", publisherId: "01960a1b-2000-7000-8a9b-0c1d2e3f4a02", authorIds: ["01960a1b-3000-7000-8a9b-0c1d2e3f4a03"], isRemoveImage: false,};
// 1. Direct @workspace/api-client (Axios multipart/form-data) callawait booksApiClient.update(request, { ifMatch: '"1"' });
// 2. React / TanStack Query hook (@workspace/api-hooks)const { mutate: updateBook, isPending } = useUpdateBook({ onSuccess: () => { console.log("Book updated"); },});
updateBook({ request, ifMatch: '"1"' });1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "title": "UpdateBook",
4 "description": "Multipart payload for updating a book listing.",
5 "type": "object",
6 "additionalProperties": false,
7 "required": ["id", "name", "price", "categoryId", "publisherId", "authorIds"],
8 "properties": {
9 "id": {
10 "type": "string",
11 "format": "uuid",
12 "description": "Book UUID to update."
13 },
14 "name": {
15 "type": "string",
16 "minLength": 1
17 },
18 "description": {
19 "type": "string"
20 },
21 "image": {
22 "type": ["string", "null"],
23 "contentEncoding": "base64"
24 },
25 "price": {
26 "type": "number",
27 "minimum": 0
28 },
29 "priceSale": {
30 "type": ["number", "null"],
31 "minimum": 0
32 },
33 "categoryId": {
34 "type": "string",
35 "format": "uuid",
36 "description": "A UUID identifying the resource."
37 },
38 "publisherId": {
39 "type": "string",
40 "format": "uuid",
41 "description": "A UUID identifying the resource."
42 },
43 "authorIds": {
44 "type": "array",
45 "items": {
46 "type": "string",
47 "format": "uuid",
48 "description": "A UUID identifying the resource."
49 }
50 },
51 "isRemoveImage": {
52 "type": "boolean",
53 "description": "Remove the existing cover when true."
54 }
55 }
56}
57