James Tombleson
75b66dd625
* Using sqlc to generate queries and goose for migrations. The intial tests look good. * moving the old calls away for now. Might use this in a package later on. * Added postgres driver * Updated the dockerfile to support sql migrations * added sqlc config file * updated schema and starting a seed script * updated models to use the database ones * updated reddit cron to talk to the db * added env for sql connection string * got the reddit source working with the db and posting articles * added sql packages * added rule to ignore dev sql file * added migration down statement for rolling back * updated cron for reddit and youtube * Updated reddit to follow a new standard pattern * updated youtube to follow new patterns * updated tests and brought them to the standard * updated the seed migration * all cron tasks should feed the db now * updated app init * bumped docker to 1.18.3 * disabled remote tests given secrets and lack of interfaces currently to run tests
38 lines
768 B
Go
38 lines
768 B
Go
package databaseRest
|
|
|
|
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
|
|
} |