mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-11-03 04:27:16 -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
|
||||
/posts.db
|
||||
|
@ -1,6 +1,8 @@
|
||||
package aggregator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"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 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 {
|
||||
sysPosts, err := (*sys).ListPosts(idx)
|
||||
if err != nil {
|
||||
@ -35,6 +48,12 @@ func (a *Aggregator) ListPosts() ([]post.Post, []error) {
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user