Sync proclamations when entering proclamation list
This commit is contained in:
@@ -154,8 +154,8 @@ func Run() {
|
||||
})
|
||||
|
||||
// Sync the proclamations from the API to the Database
|
||||
sync.SyncProclamations(apiURL, DB)
|
||||
sync.SyncCategories(apiURL, DB)
|
||||
sync.SyncProclamations(DB)
|
||||
sync.SyncCategories(DB)
|
||||
|
||||
app.runEventLoop()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"rhemawavetech.com/rhemawave/internal/fontManager"
|
||||
"rhemawavetech.com/rhemawave/internal/logger"
|
||||
"rhemawavetech.com/rhemawave/internal/shaderManager"
|
||||
"rhemawavetech.com/rhemawave/internal/sync"
|
||||
)
|
||||
|
||||
// Scrollbar Visuals
|
||||
@@ -78,10 +79,12 @@ func (p *ProclamationOptions) Init(ctx *PageCtx) error {
|
||||
p.allItems = []*FlatItem{}
|
||||
p.scrollOffset = 0
|
||||
p.isSearchActive = false
|
||||
|
||||
p.scrollTrackWidth = 30
|
||||
p.scrollTrackX = p.ScreenWidth - p.scrollTrackWidth
|
||||
|
||||
// Syncronize proclamations first
|
||||
sync.SyncProclamations(ctx.DbPtr)
|
||||
|
||||
fm := fontManager.Get()
|
||||
font, _ := fm.GetFont("Roboto-Regular")
|
||||
p.font = font
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -14,8 +13,9 @@ var htmlRegex = regexp.MustCompile(`<[^>]*>`)
|
||||
|
||||
// SyncProclamations fetches data from the API, cleans it, and updates the local DB.
|
||||
// It returns the slice of proclamations so the UI can update immediately.
|
||||
func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, error) {
|
||||
fullURL := fmt.Sprintf("%s/proclamations", apiURL)
|
||||
func SyncProclamations(database *gorm.DB) ([]db.Proclamation, error) {
|
||||
fullURL := "https://portal.rhemawavetech.com/api/v1/proclamations"
|
||||
logger.Debug("Syncronizing proclamations. URL: %s", fullURL)
|
||||
|
||||
// 1. Fetch from API
|
||||
proclamations, err := netreq.GetJSON[db.Proclamation](fullURL)
|
||||
@@ -25,6 +25,7 @@ func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, err
|
||||
logger.Error("Proclamation sync failed, skipping update: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
logger.Debug("Request Granted")
|
||||
|
||||
// 2. Data Transformation (Cleaning)
|
||||
for i := range proclamations {
|
||||
@@ -40,6 +41,8 @@ func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, err
|
||||
return nil
|
||||
})
|
||||
|
||||
logger.Debug("Proclamations stored to database")
|
||||
|
||||
if err != nil {
|
||||
logger.Error("Failed to save synced proclamations: %v", err)
|
||||
return nil, err
|
||||
@@ -49,8 +52,8 @@ func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, err
|
||||
return proclamations, nil
|
||||
}
|
||||
|
||||
func SyncCategories(apiURL string, database *gorm.DB) ([]db.ProclamationCategory, error) {
|
||||
fullURL := fmt.Sprintf("%s/categories", apiURL)
|
||||
func SyncCategories(database *gorm.DB) ([]db.ProclamationCategory, error) {
|
||||
fullURL := "https://portal.rhemawavetech.com/api/v1/categories"
|
||||
categories, err := netreq.GetJSON[db.ProclamationCategory](fullURL)
|
||||
if err != nil {
|
||||
logger.Error("Category sync failed, skipping update: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user