From 3db1340cce75a3a9c386dec0fcc20f8a934ce6a1 Mon Sep 17 00:00:00 2001 From: Joakim Date: Thu, 11 Sep 2025 16:36:42 +0200 Subject: [PATCH] feat: implement single POST upsert API with automatic ID generation - Replace separate POST/PUT endpoints with unified POST upsert - Add automatic content ID generation from element context when no ID provided - Implement version history preservation before content updates - Add element context support for backend ID generation - Update frontend to use single endpoint for all content operations - Enhanced demo site with latest database content including proper content IDs --- cmd/serve.go | 2 +- demo-site/about.html | 32 ++++++++--------- demo-site/index.html | 38 ++++++++++---------- internal/api/handlers.go | 72 +++----------------------------------- internal/api/models.go | 6 ---- lib/src/core/api-client.js | 31 +--------------- lib/src/core/editor.js | 35 ++++++++---------- lib/src/core/insertr.js | 26 +++++--------- 8 files changed, 65 insertions(+), 177 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 0388355..d0e8064 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -130,7 +130,7 @@ func runServe(cmd *cobra.Command, args []string) { contentRouter := apiRouter.PathPrefix("/content").Subrouter() contentRouter.HandleFunc("/bulk", contentHandler.GetBulkContent).Methods("GET") contentRouter.HandleFunc("/{id}", contentHandler.GetContent).Methods("GET") - contentRouter.HandleFunc("/{id}", contentHandler.UpdateContent).Methods("PUT") + contentRouter.HandleFunc("", contentHandler.GetAllContent).Methods("GET") contentRouter.HandleFunc("", contentHandler.CreateContent).Methods("POST") diff --git a/demo-site/about.html b/demo-site/about.html index f440a15..88af869 100644 --- a/demo-site/about.html +++ b/demo-site/about.html @@ -9,7 +9,7 @@