mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-12-04 14:46:37 -05:00
Implemented LoadPost, minor fixes, restructuring
This commit is contained in:
parent
6ed8922303
commit
e0539b4954
@ -79,7 +79,7 @@ var rootCmd = &cobra.Command{
|
||||
c := ctx.New(&CFG, LOG)
|
||||
_ = loadSystems(&c) // TODO: Handle errs
|
||||
|
||||
posts, err := (*c.Systems[1]).ListPosts()
|
||||
posts, err := (*c.Systems[0]).ListPosts()
|
||||
fmt.Println("-----------------------")
|
||||
fmt.Printf("%v\n", posts)
|
||||
fmt.Printf("%v\n", err)
|
||||
|
@ -1,11 +1,17 @@
|
||||
package reply
|
||||
|
||||
import "github.com/mrusme/gobbs/models/author"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/mrusme/gobbs/models/author"
|
||||
)
|
||||
|
||||
type Reply struct {
|
||||
ID string
|
||||
|
||||
Body string
|
||||
|
||||
CreatedAt time.Time
|
||||
|
||||
Author author.Author
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/mrusme/gobbs/models/author"
|
||||
"github.com/mrusme/gobbs/models/post"
|
||||
"github.com/mrusme/gobbs/models/reply"
|
||||
"github.com/mrusme/gobbs/system/adapter"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@ -31,6 +32,25 @@ func (sys *System) SetLogger(logger *zap.SugaredLogger) {
|
||||
sys.logger = logger
|
||||
}
|
||||
|
||||
func (sys *System) GetCapabilities() []adapter.Capability {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "posts",
|
||||
Name: "Posts",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "groups",
|
||||
Name: "Groups",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "search",
|
||||
Name: "Search",
|
||||
})
|
||||
|
||||
return caps
|
||||
}
|
||||
|
||||
func (sys *System) Load() error {
|
||||
url := sys.config["url"]
|
||||
if url == nil {
|
||||
@ -52,25 +72,6 @@ func (sys *System) Load() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sys *System) GetCapabilities() []adapter.Capability {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "posts",
|
||||
Name: "Posts",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "groups",
|
||||
Name: "Groups",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "search",
|
||||
Name: "Search",
|
||||
})
|
||||
|
||||
return caps
|
||||
}
|
||||
|
||||
func (sys *System) ListPosts() ([]post.Post, error) {
|
||||
items, err := sys.client.Topics.ListLatest(context.Background())
|
||||
if err != nil {
|
||||
@ -118,3 +119,36 @@ func (sys *System) ListPosts() ([]post.Post, error) {
|
||||
|
||||
return models, nil
|
||||
}
|
||||
|
||||
func (sys *System) LoadPost(p *post.Post) error {
|
||||
item, err := sys.client.Topics.Show(context.Background(), p.ID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for idx, i := range item.PostStream.Posts {
|
||||
if idx == 0 {
|
||||
p.Body = i.Cooked // TODO: Clean Cooked
|
||||
continue
|
||||
}
|
||||
|
||||
createdAt, err := dateparse.ParseAny(i.CreatedAt)
|
||||
if err != nil {
|
||||
createdAt = time.Now() // TODO: Errrrrr
|
||||
}
|
||||
p.Replies = append(p.Replies, reply.Reply{
|
||||
ID: strconv.Itoa(i.ID),
|
||||
|
||||
Body: i.Cooked, // TODO: Clean Cooked
|
||||
|
||||
CreatedAt: createdAt,
|
||||
|
||||
Author: author.Author{
|
||||
ID: strconv.Itoa(i.UserID),
|
||||
Name: i.Name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/mrusme/gobbs/models/author"
|
||||
"github.com/mrusme/gobbs/models/post"
|
||||
"github.com/mrusme/gobbs/models/reply"
|
||||
"github.com/mrusme/gobbs/system/adapter"
|
||||
"go.arsenm.dev/go-lemmy"
|
||||
"go.arsenm.dev/go-lemmy/types"
|
||||
@ -32,6 +33,25 @@ func (sys *System) SetLogger(logger *zap.SugaredLogger) {
|
||||
sys.logger = logger
|
||||
}
|
||||
|
||||
func (sys *System) GetCapabilities() []adapter.Capability {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "posts",
|
||||
Name: "Posts",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "groups",
|
||||
Name: "Groups",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "search",
|
||||
Name: "Search",
|
||||
})
|
||||
|
||||
return caps
|
||||
}
|
||||
|
||||
func (sys *System) Load() error {
|
||||
var err error
|
||||
|
||||
@ -111,21 +131,37 @@ func (sys *System) ListPosts() ([]post.Post, error) {
|
||||
return models, nil
|
||||
}
|
||||
|
||||
func (sys *System) GetCapabilities() []adapter.Capability {
|
||||
var caps []adapter.Capability
|
||||
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "posts",
|
||||
Name: "Posts",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "groups",
|
||||
Name: "Groups",
|
||||
})
|
||||
caps = append(caps, adapter.Capability{
|
||||
ID: "search",
|
||||
Name: "Search",
|
||||
})
|
||||
|
||||
return caps
|
||||
func (sys *System) LoadPost(p *post.Post) error {
|
||||
pid, err := strconv.Atoi(p.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := sys.client.Comments(context.Background(), types.GetComments{
|
||||
PostID: types.NewOptional(pid),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, i := range resp.Comments {
|
||||
createdAt, err := dateparse.ParseAny(i.Comment.Published)
|
||||
if err != nil {
|
||||
createdAt = time.Now() // TODO: Errrrr
|
||||
}
|
||||
|
||||
p.Replies = append(p.Replies, reply.Reply{
|
||||
ID: strconv.Itoa(i.Comment.ID),
|
||||
|
||||
Body: i.Comment.Content,
|
||||
|
||||
CreatedAt: createdAt,
|
||||
|
||||
Author: author.Author{
|
||||
ID: strconv.Itoa(i.Comment.CreatorID),
|
||||
Name: i.Creator.Name,
|
||||
},
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ type System interface {
|
||||
Load() error
|
||||
|
||||
ListPosts() ([]post.Post, error)
|
||||
LoadPost(p *post.Post) error
|
||||
}
|
||||
|
||||
func New(
|
||||
|
Loading…
Reference in New Issue
Block a user