mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-01-03 14:56:41 -05:00
Implemented posts.db for testing
This commit is contained in:
parent
57d59ec27a
commit
2ab0c4be67
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/gobbs
|
/gobbs
|
||||||
|
/posts.db
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package aggregator
|
package aggregator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/mrusme/gobbs/models/post"
|
"github.com/mrusme/gobbs/models/post"
|
||||||
@ -22,6 +24,17 @@ func (a *Aggregator) ListPosts() ([]post.Post, []error) {
|
|||||||
var errs []error = make([]error, len(a.ctx.Systems))
|
var errs []error = make([]error, len(a.ctx.Systems))
|
||||||
var posts []post.Post
|
var posts []post.Post
|
||||||
|
|
||||||
|
// TODO: Clean up implementation
|
||||||
|
if os.Getenv("GOBBS_TEST") == "true" {
|
||||||
|
jsonPosts, err := os.ReadFile("posts.db")
|
||||||
|
if err == nil {
|
||||||
|
err = json.Unmarshal(jsonPosts, &posts)
|
||||||
|
if err == nil {
|
||||||
|
return posts, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for idx, sys := range a.ctx.Systems {
|
for idx, sys := range a.ctx.Systems {
|
||||||
sysPosts, err := (*sys).ListPosts(idx)
|
sysPosts, err := (*sys).ListPosts(idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -35,6 +48,12 @@ func (a *Aggregator) ListPosts() ([]post.Post, []error) {
|
|||||||
return posts[i].CreatedAt.After(posts[j].CreatedAt)
|
return posts[i].CreatedAt.After(posts[j].CreatedAt)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO: Clean up implementation
|
||||||
|
jsonPosts, err := json.Marshal(posts)
|
||||||
|
if err == nil {
|
||||||
|
os.WriteFile("posts.db", jsonPosts, 0600)
|
||||||
|
}
|
||||||
|
|
||||||
return posts, errs
|
return posts, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user