feat(source): added deletion
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
a61c300b74
commit
3e4560768b
@ -35,6 +35,30 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSourceNode will delete a node with a given Domain
|
||||
func DeleteSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error {
|
||||
query := `
|
||||
MERGE (sourceNode:Source {domain: $domain})
|
||||
DELETE sourceNode
|
||||
`
|
||||
params := map[string]any{
|
||||
"domain": anthroveSource.Domain,
|
||||
}
|
||||
|
||||
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
||||
if err != nil {
|
||||
return fmt.Errorf("graph: %w", err)
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"node_source_url": anthroveSource.Domain,
|
||||
"node_source_displayName": anthroveSource.DisplayName,
|
||||
"node_source_icon": anthroveSource.Icon,
|
||||
}).Trace("graph: created source node")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]models.AnthroveSource, error) {
|
||||
var sources []models.AnthroveSource
|
||||
|
||||
|
@ -10,6 +10,8 @@ type Source interface {
|
||||
|
||||
// CreateSource will always create a new node, it checks if a node with the same url exits and merges it.
|
||||
CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||
|
||||
// DeleteSource will delete a node with a given Domain
|
||||
DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||
|
||||
// GetSourceByURL returns the Source Node based on the URL
|
||||
|
@ -13,9 +13,9 @@ func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *mode
|
||||
return source.CreateSourceNode(ctx, g.driver, anthroveSource)
|
||||
}
|
||||
|
||||
// DeleteSource will delete a node with a given Domain
|
||||
func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
return source.DeleteSourceNode(ctx, g.driver, anthroveSource)
|
||||
}
|
||||
|
||||
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
|
||||
|
Reference in New Issue
Block a user