Sync proclamations when entering proclamation list

This commit is contained in:
NeilClack
2026-04-23 17:29:20 -05:00
parent 32648377ce
commit b6bf0f1873
3 changed files with 14 additions and 8 deletions
+8 -5
View File
@@ -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)