Implement complete collection REST API and fix critical server enhancement bug

• Add full collection REST API with CRUD operations for collections and items
• Implement collection models, handlers, and database integration with SQLite/PostgreSQL support
• Add collection endpoints: GET/POST/PUT/DELETE for collections and collection items
• Fix critical server enhancement bug by consolidating to engine.DatabaseClient
• Remove obsolete content.DatabaseClient that lacked collection support
• Enable proper collection reconstruction during server-side enhancement
• Collections now persist correctly and display new items after API modifications
This commit is contained in:
2025-09-22 20:12:34 +02:00
parent 2315ba4750
commit 09823d3e4d
4 changed files with 531 additions and 260 deletions

View File

@@ -110,7 +110,7 @@ func runServe(cmd *cobra.Command, args []string) {
}
// Initialize content client for site manager
contentClient := content.NewDatabaseClient(database)
contentClient := engine.NewDatabaseClient(database)
// Initialize site manager with auth provider
authProvider := &engine.AuthProvider{Type: authConfig.Provider}
@@ -227,6 +227,18 @@ func runServe(cmd *cobra.Command, args []string) {
contentRouter.Get("/{id}/versions", contentHandler.GetContentVersions)
contentRouter.Post("/{id}/rollback", contentHandler.RollbackContent)
})
// Collection endpoints
apiRouter.Route("/collections", func(collectionRouter chi.Router) {
collectionRouter.Get("/", contentHandler.GetAllCollections)
collectionRouter.Get("/{id}", contentHandler.GetCollection)
// Collection item endpoints
collectionRouter.Get("/{id}/items", contentHandler.GetCollectionItems)
collectionRouter.Post("/{id}/items", contentHandler.CreateCollectionItem)
collectionRouter.Put("/{id}/items/{item_id}", contentHandler.UpdateCollectionItem)
collectionRouter.Delete("/{id}/items/{item_id}", contentHandler.DeleteCollectionItem)
})
})
// Static site serving - serve registered sites at /sites/{site_id}
@@ -259,13 +271,21 @@ func runServe(cmd *cobra.Command, args []string) {
fmt.Printf("🌐 Server running at: http://localhost%s\n", addr)
fmt.Printf("💚 Health check: http://localhost%s/health\n", addr)
fmt.Printf("📊 API endpoints:\n")
fmt.Printf(" GET /api/content?site_id={site}\n")
fmt.Printf(" GET /api/content/{id}?site_id={site}\n")
fmt.Printf(" GET /api/content/bulk?site_id={site}&ids[]={id1}&ids[]={id2}\n")
fmt.Printf(" POST /api/content\n")
fmt.Printf(" PUT /api/content/{id}\n")
fmt.Printf(" GET /api/content/{id}/versions?site_id={site}\n")
fmt.Printf(" POST /api/content/{id}/rollback\n")
fmt.Printf(" Content:\n")
fmt.Printf(" GET /api/content?site_id={site}\n")
fmt.Printf(" GET /api/content/{id}?site_id={site}\n")
fmt.Printf(" GET /api/content/bulk?site_id={site}&ids[]={id1}&ids[]={id2}\n")
fmt.Printf(" POST /api/content\n")
fmt.Printf(" PUT /api/content/{id}\n")
fmt.Printf(" GET /api/content/{id}/versions?site_id={site}\n")
fmt.Printf(" POST /api/content/{id}/rollback\n")
fmt.Printf(" Collections:\n")
fmt.Printf(" GET /api/collections?site_id={site}\n")
fmt.Printf(" GET /api/collections/{id}?site_id={site}\n")
fmt.Printf(" GET /api/collections/{id}/items?site_id={site}\n")
fmt.Printf(" POST /api/collections/{id}/items\n")
fmt.Printf(" PUT /api/collections/{id}/items/{item_id}\n")
fmt.Printf(" DELETE /api/collections/{id}/items/{item_id}\n")
fmt.Printf("🌐 Static sites:\n")
for siteID, _ := range siteManager.GetAllSites() {
fmt.Printf(" %s: http://localhost%s/sites/%s/\n", siteID, addr, siteID)