feat(dashboard): implement Phase 4 API handlers for Carousel-style dashboard
Add dashboard API endpoints with handler layer: Step 1: Add SectionData to collections.go - SectionData struct represents dashboard section (carousel of books) - Used by: Dashboard handler, Templates (SSR), API JSON responses - Shared type from collections.go (no duplicate definitions) - Fields: ID, IsSystem, Title, Description, Icon, Items, ViewAllURL, Priority Step 2: Create dashboard.go handler - DashboardHandler struct with injected database and dashboard service - GetSections: Returns dashboard sections as JSON (mobile apps, web UI TypeScript, plugins) * Validates library_id parameter * Fetches user dashboard preferences * Configurable limit (default 20, max 100) * Calls service layer for business logic * Converts service types to handler types for JSON serialization - UpdatePreferences: Saves dashboard preferences * Validates library_id * Upserts user dashboard preferences - RestoreSystemCollection: Resets system collection to defaults * Validates collection_name against allowed system collections * Deletes user's copy (system collection reappears automatically) - BuildSections: Converts service DashboardSection to handler SectionData * Converts database.MediaItems to handlers.BookInfo * Uses shared types from collections.go - getViewAllURL: Maps system collections to their view-all URLs - Reuses existing textToString helper from collections.go Architecture Compliance: - Generic API handler for reuse by SSR, mobile, plugins - Uses shared types from collections.go (SectionData, BookInfo) - IsSystem bool matches database field (no string conversion) - Single service method returns structured data (simpler, less bugs) - Handler just converts types (no matching logic needed) - Reusable by mobile apps, web UI, plugins
This commit is contained in:
@@ -70,6 +70,17 @@ type BookInfo struct {
|
||||
CoverImagePath string `json:"cover_image_path"`
|
||||
}
|
||||
|
||||
type SectionData struct {
|
||||
ID string `json:"id"`
|
||||
IsSystem bool `json:"is_system"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Items []BookInfo `json:"items"`
|
||||
ViewAllURL string `json:"view_all_url"`
|
||||
Priority int `json:"priority"`
|
||||
}
|
||||
|
||||
func (h *CollectionHandler) CreateCollection(c echo.Context) error {
|
||||
user := c.Get("user").(database.Users)
|
||||
userUUID := uuid.UUID(user.ID.Bytes)
|
||||
|
||||
Reference in New Issue
Block a user