From 2510d9e36e45aef8955b7c4f6a40be1b589501a7 Mon Sep 17 00:00:00 2001 From: Michael Chus Date: Tue, 3 Feb 2026 07:19:43 +0300 Subject: [PATCH] feat: show local pricelists in offline mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem:** Pricelist page showed empty list in offline mode even though local pricelists existed in SQLite cache. **Solution:** Modified PricelistHandler.List() to fallback to local pricelists: 1. Check if server list is empty (offline) 2. Load from localDB.GetLocalPricelists() 3. Convert LocalPricelist to summary format 4. Add "synced_from": "local" field 5. Add "offline": true flag **Response format:** ```json { "offline": true, "total": 4, "pricelists": [ { "version": "2026-02-02-002", "created_by": "sync", "synced_from": "local", "is_active": true } ] } ``` **Impact:** - ✅ Local pricelists visible in offline mode - ✅ UI can show cached pricelist versions - ✅ Users can browse pricelists without connection - ✅ Clear indication of local/remote source Part of Phase 2.5: Full Offline Mode Co-Authored-By: Claude Sonnet 4.5 --- internal/handlers/pricelist.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/handlers/pricelist.go b/internal/handlers/pricelist.go index 19c2b40..f6dc2f5 100644 --- a/internal/handlers/pricelist.go +++ b/internal/handlers/pricelist.go @@ -29,6 +29,36 @@ func (h *PricelistHandler) List(c *gin.Context) { return } + // If offline (empty list), fallback to local pricelists + if total == 0 && h.localDB != nil { + localPLs, err := h.localDB.GetLocalPricelists() + if err == nil && len(localPLs) > 0 { + // Convert to PricelistSummary format + summaries := make([]map[string]interface{}, len(localPLs)) + for i, lpl := range localPLs { + summaries[i] = map[string]interface{}{ + "id": lpl.ServerID, + "version": lpl.Version, + "created_by": "sync", + "item_count": 0, // Not tracked + "usage_count": 0, // Not tracked in local + "is_active": true, + "created_at": lpl.CreatedAt, + "synced_from": "local", + } + } + + c.JSON(http.StatusOK, gin.H{ + "pricelists": summaries, + "total": len(summaries), + "page": page, + "per_page": perPage, + "offline": true, + }) + return + } + } + c.JSON(http.StatusOK, gin.H{ "pricelists": pricelists, "total": total,