feat: added GetAllSources
This commit is contained in:
parent
9f2ebe90ee
commit
1cce71e330
@ -33,3 +33,43 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
|
||||
|
||||
return nil
|
||||
}
|
||||
func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]models.AnthroveSource, error) {
|
||||
var sources []models.AnthroveSource
|
||||
|
||||
query := `
|
||||
MATCH (s:Source)
|
||||
RETURN s as source
|
||||
`
|
||||
params := map[string]any{}
|
||||
|
||||
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(result.Records) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
for i := range result.Records {
|
||||
record := result.Records[i]
|
||||
|
||||
source, _, err := neo4j.GetRecordValue[neo4j.Node](record, "source")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sources = append(sources, models.AnthroveSource{
|
||||
DisplayName: source.Props["display_name"].(string),
|
||||
Domain: source.Props["domain"].(string),
|
||||
Icon: source.Props["icon"].(string),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tag_amount": len(sources),
|
||||
}).Trace("graph: created tag node")
|
||||
|
||||
return sources, nil
|
||||
}
|
||||
|
@ -107,4 +107,7 @@ type OtterSpace interface {
|
||||
|
||||
// GetAllTags returns a list of Tags that the user hs favorites through a post
|
||||
GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error)
|
||||
|
||||
// GetAllSources returns a list of Sources in the database
|
||||
GetAllSources(ctx context.Context) ([]models.AnthroveSource, error)
|
||||
}
|
||||
|
@ -108,6 +108,10 @@ func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFreq
|
||||
return internal.GetTags(ctx, g.driver)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
|
||||
return internal.GetAllSourceNodes(ctx, g.driver)
|
||||
}
|
||||
|
||||
func logger(graphDebug bool) func(config *config.Config) {
|
||||
return func(config *config.Config) {
|
||||
config.Log = internal.NewGraphLogger(graphDebug)
|
||||
|
Reference in New Issue
Block a user