1
0
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:
マリウス 2022-12-31 18:55:02 -05:00
parent 57d59ec27a
commit 2ab0c4be67
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 20 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/gobbs
/posts.db

View File

@ -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
}