newsbot-api/database/sources.go
James Tombleson 2b959e140c
Features/reddit and dto (#2)
* updated db calls to new endpoints.  Not all are finished yet

* updated models to use the new dto objects to hide orm values

* updated reddit to build articles based on what type of post it is

* getting reddit ready to post the articles to the db

* Now able to post to the db under the new DTO object

* moved the reddit model to articles model to the struct and out of main
2022-04-07 14:53:40 -07:00

38 lines
764 B
Go

package database
import (
"encoding/json"
"fmt"
"log"
"github.com/jtom38/newsbot/collector/domain/model"
)
type SourcesClient struct {
rootUri string
}
func (sb *SourcesClient) List() ([]model.Sources, error) {
var items []model.Sources
url := fmt.Sprintf("%v/api/v1/sources", sb.rootUri)
resp, err := getContent(url)
if err != nil { return items, err }
err = json.Unmarshal(resp, &items)
if err != nil { return []model.Sources{}, err }
return items, nil
}
func (sb *SourcesClient) FindBySource(SourceType string) ([]model.Sources, error) {
items, err := sb.List()
if err != nil { log.Panicln(err) }
var res []model.Sources
for _, item := range(items) {
if item.Source == SourceType {
res = append(res, item)
}
}
return res, nil
}