feat: added GetAllSources

This commit is contained in:
SoXX 2024-05-15 15:44:34 +02:00
parent 9f2ebe90ee
commit 1cce71e330
3 changed files with 47 additions and 0 deletions

View File

@ -33,3 +33,43 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
return nil 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
}

View File

@ -107,4 +107,7 @@ type OtterSpace interface {
// GetAllTags returns a list of Tags that the user hs favorites through a post // GetAllTags returns a list of Tags that the user hs favorites through a post
GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error)
// GetAllSources returns a list of Sources in the database
GetAllSources(ctx context.Context) ([]models.AnthroveSource, error)
} }

View File

@ -108,6 +108,10 @@ func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFreq
return internal.GetTags(ctx, g.driver) 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) { func logger(graphDebug bool) func(config *config.Config) {
return func(config *config.Config) { return func(config *config.Config) {
config.Log = internal.NewGraphLogger(graphDebug) config.Log = internal.NewGraphLogger(graphDebug)