feat(source): added deletion

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-05-31 15:33:48 +02:00
parent a61c300b74
commit 3e4560768b
3 changed files with 28 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {