2022-12-28 22:22:36 -05:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-01-06 19:46:41 -05:00
|
|
|
"github.com/mrusme/neonmodem/models/forum"
|
|
|
|
"github.com/mrusme/neonmodem/models/post"
|
|
|
|
"github.com/mrusme/neonmodem/models/reply"
|
|
|
|
"github.com/mrusme/neonmodem/system/adapter"
|
|
|
|
"github.com/mrusme/neonmodem/system/all"
|
|
|
|
"github.com/mrusme/neonmodem/system/discourse"
|
|
|
|
"github.com/mrusme/neonmodem/system/hackernews"
|
|
|
|
"github.com/mrusme/neonmodem/system/lemmy"
|
|
|
|
"github.com/mrusme/neonmodem/system/lobsters"
|
2022-12-29 22:03:38 -05:00
|
|
|
"go.uber.org/zap"
|
2022-12-28 22:22:36 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type System interface {
|
2023-01-01 22:51:16 -05:00
|
|
|
SetID(id int)
|
|
|
|
GetID() int
|
2022-12-29 14:34:05 -05:00
|
|
|
GetConfig() map[string]interface{}
|
|
|
|
SetConfig(cfg *map[string]interface{})
|
2022-12-29 22:03:38 -05:00
|
|
|
SetLogger(logger *zap.SugaredLogger)
|
2023-01-05 00:23:25 -05:00
|
|
|
GetCapabilities() adapter.Capabilities
|
2022-12-28 22:22:36 -05:00
|
|
|
|
2023-01-04 21:41:41 -05:00
|
|
|
FilterValue() string
|
|
|
|
Title() string
|
|
|
|
Description() string
|
|
|
|
|
2022-12-29 17:46:59 -05:00
|
|
|
Connect(sysURL string) error
|
2022-12-28 22:22:36 -05:00
|
|
|
Load() error
|
|
|
|
|
2023-01-05 11:43:52 -05:00
|
|
|
ListForums() ([]forum.Forum, error)
|
|
|
|
ListPosts(forumID string) ([]post.Post, error)
|
2022-12-30 02:48:53 -05:00
|
|
|
LoadPost(p *post.Post) error
|
2023-01-01 22:51:16 -05:00
|
|
|
CreatePost(p *post.Post) error
|
|
|
|
CreateReply(r *reply.Reply) error
|
2022-12-28 22:22:36 -05:00
|
|
|
}
|
|
|
|
|
2022-12-29 22:03:38 -05:00
|
|
|
func New(
|
|
|
|
sysType string,
|
|
|
|
sysConfig *map[string]interface{},
|
|
|
|
logger *zap.SugaredLogger,
|
|
|
|
) (System, error) {
|
2022-12-28 22:22:36 -05:00
|
|
|
var sys System
|
|
|
|
|
|
|
|
switch sysType {
|
|
|
|
case "discourse":
|
|
|
|
sys = new(discourse.System)
|
|
|
|
case "lemmy":
|
|
|
|
sys = new(lemmy.System)
|
2023-01-05 14:57:01 -05:00
|
|
|
case "lobsters":
|
|
|
|
sys = new(lobsters.System)
|
2022-12-31 12:30:26 -05:00
|
|
|
case "hackernews":
|
|
|
|
sys = new(hackernews.System)
|
2023-01-04 23:59:37 -05:00
|
|
|
case "all":
|
|
|
|
sys = new(all.System)
|
2022-12-28 22:22:36 -05:00
|
|
|
default:
|
|
|
|
return nil, errors.New("No such system")
|
|
|
|
}
|
|
|
|
|
2022-12-29 14:34:05 -05:00
|
|
|
sys.SetConfig(sysConfig)
|
2022-12-29 22:03:38 -05:00
|
|
|
sys.SetLogger(logger)
|
2022-12-28 22:22:36 -05:00
|
|
|
err := sys.Load()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sys, nil
|
|
|
|
}
|