Преглед на файлове

🐛 fix(console-setting): ensure announcements are returned in newest-first order

Summary
• Added stable, descending sort to `GetAnnouncements()` so that the API always returns the latest announcements first.
• Introduced helper `getPublishTime()` to safely parse `publishDate` (RFC 3339) and fall back to zero value on failure.
• Switched to `sort.SliceStable` for deterministic ordering when timestamps are identical.
• Imported the standard `sort` package and removed redundant, duplicate date parsing.

Impact
Front-end no longer needs to perform client-side sorting; the latest announcement is guaranteed to appear at the top on all platforms and clients.
Apple\Apple преди 6 месеца
родител
ревизия
d5c96cb036
променени са 1 файла, в които са добавени 17 реда и са изтрити 1 реда
  1. 17 1
      setting/console_setting/validation.go

+ 17 - 1
setting/console_setting/validation.go

@@ -7,6 +7,7 @@ import (
     "regexp"
     "strings"
     "time"
+    "sort"
 )
 
 var (
@@ -210,8 +211,23 @@ func validateFAQ(faqStr string) error {
     return nil
 }
 
+func getPublishTime(item map[string]interface{}) time.Time {
+    if v, ok := item["publishDate"]; ok {
+        if s, ok2 := v.(string); ok2 {
+            if t, err := time.Parse(time.RFC3339, s); err == nil {
+                return t
+            }
+        }
+    }
+    return time.Time{}
+}
+
 func GetAnnouncements() []map[string]interface{} {
-    return getJSONList(GetConsoleSetting().Announcements)
+    list := getJSONList(GetConsoleSetting().Announcements)
+    sort.SliceStable(list, func(i, j int) bool {
+        return getPublishTime(list[i]).After(getPublishTime(list[j]))
+    })
+    return list
 }
 
 func GetFAQ() []map[string]interface{} {