The smart-collection editor at /collections/:id/rules now hosts the SAME builder island as All-Books (FilterBuilderRows — the rows markup extracted into one shared templ both mounts render; the shared filterBuilderExtra component). One vocabulary, one engine, one row UI; the collection differences are exactly three: the payload is the collection's scope (episode trees get the episode fields — books trees hide them), Apply writes the tree to the collection (PUT filter_tree through the validated write path), and a legacy rules array preloads as its CONVERTED tree (RulesToFilterTree rendered server-side) so the upgrade lands at the first Apply — read-compat never mutates data silently. Retired with the page: the per-rule CRUD endpoints and test-rules (their handler bodies, routes, api-docs rows, and the dead collections.ts island functions — the file's LIVE halves, the collection modal/navigate/ grid-refresh, stay; the dead rules half went). match-mode endpoint and preview survive (legacy channel + the dashboard custom-section-builder, flagged for its own migration). Contract-pin changelog documents the deletions per the asymmetry rule. The builder component gains collection mounts: scopeKey (the row universe for counts/apply), data-tree prefill, treeJSON (the apply wire with scope riding the top level), and an apply hook (the page owns the write; All-Books never sets one). ensureReadyRule defaults to the scope's first field instead of hardcoding author. Tests migrated onto trees: TestSmartCollections' live-membership / reject-mutations / include-auto / system-collection subtests now drive TREE collections; the deleted-endpoint subtests die with them.
36 lines
1.7 KiB
Go
36 lines
1.7 KiB
Go
package router
|
|
|
|
func registerCollectionsRoutes(cfg *Config) {
|
|
e := cfg.Echo
|
|
|
|
// JWT middleware for protected routes
|
|
jwtMiddleware := createJWTMiddleware(cfg)
|
|
protected := e.Group("/api", jwtMiddleware)
|
|
|
|
// Collections API routes
|
|
collections := protected.Group("/collections")
|
|
collections.GET("", cfg.CollectionHandler.GetCollections)
|
|
collections.POST("", cfg.CollectionHandler.CreateCollection)
|
|
collections.GET("/:id", cfg.CollectionHandler.GetCollection)
|
|
collections.PUT("/:id", cfg.CollectionHandler.UpdateCollection)
|
|
collections.DELETE("/:id", cfg.CollectionHandler.DeleteCollection)
|
|
collections.GET("/:id/books", cfg.CollectionHandler.GetBookCollections)
|
|
collections.POST("/:id/books", cfg.CollectionHandler.AddBooks)
|
|
collections.PUT("/:id/items/order", cfg.CollectionHandler.ReorderItems)
|
|
collections.PUT("/:id/match-mode", cfg.CollectionHandler.SetMatchMode)
|
|
collections.DELETE("/:id/books/:bookId", cfg.CollectionHandler.RemoveBook)
|
|
collections.POST("/:id/books/bulk-remove", cfg.CollectionHandler.BulkRemoveBooks)
|
|
collections.POST("/bulk-add-books", cfg.CollectionHandler.HandleBulkAddBooks)
|
|
collections.POST("/preview", cfg.CollectionHandler.PreviewCollection)
|
|
|
|
// Smart collection rule CRUD (the rules builder persists through
|
|
// these; type follows rules presence — first rule = smart).
|
|
|
|
// Device shelf mapping routes
|
|
deviceCollections := protected.Group("/devices/:id/collections")
|
|
deviceCollections.GET("", cfg.CollectionHandler.GetDeviceMappings)
|
|
deviceCollections.POST("", cfg.CollectionHandler.CreateDeviceMapping)
|
|
deviceCollections.PUT("/:collectionId", cfg.CollectionHandler.UpdateDeviceMapping)
|
|
deviceCollections.DELETE("/:collectionId", cfg.CollectionHandler.DeleteDeviceMapping)
|
|
}
|