From ea2958b27d406cc4b3f19914bb7a1e98c2696440 Mon Sep 17 00:00:00 2001 From: SoXX Date: Mon, 3 Jun 2024 22:18:02 +0200 Subject: [PATCH] feat(sources): finished implementing get all sources Signed-off-by: SoXX --- pkg/database/{graph => }/graph.go | 6 ++---- pkg/database/{postgres => }/postgres.go | 13 ++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) rename pkg/database/{graph => }/graph.go (97%) rename pkg/database/{postgres => }/postgres.go (94%) diff --git a/pkg/database/graph/graph.go b/pkg/database/graph.go similarity index 97% rename from pkg/database/graph/graph.go rename to pkg/database/graph.go index 81f94a8..869f643 100644 --- a/pkg/database/graph/graph.go +++ b/pkg/database/graph.go @@ -1,10 +1,8 @@ -package graph +package database import ( "context" "git.dragse.it/anthrove/otter-space-sdk/internal/graph" - "git.dragse.it/anthrove/otter-space-sdk/pkg/database" - "git.dragse.it/anthrove/otter-space-sdk/pkg/models" "github.com/neo4j/neo4j-go-driver/v5/neo4j" "github.com/neo4j/neo4j-go-driver/v5/neo4j/config" @@ -15,7 +13,7 @@ type graphConnection struct { graphDebug bool } -func NewGraphConnection(graphDebug bool) database.OtterSpace { +func NewGraphConnection(graphDebug bool) OtterSpace { return &graphConnection{ driver: nil, graphDebug: graphDebug, diff --git a/pkg/database/postgres/postgres.go b/pkg/database/postgres.go similarity index 94% rename from pkg/database/postgres/postgres.go rename to pkg/database/postgres.go index bac144a..89628e6 100644 --- a/pkg/database/postgres/postgres.go +++ b/pkg/database/postgres.go @@ -1,11 +1,11 @@ -package postgres +package database import ( "context" "fmt" - "git.dragse.it/anthrove/otter-space-sdk/pkg/database" + "git.dragse.it/anthrove/otter-space-sdk/internal/postgres" "git.dragse.it/anthrove/otter-space-sdk/pkg/models" - "gorm.io/driver/postgres" + gormPostgres "gorm.io/driver/postgres" "gorm.io/gorm" ) @@ -13,7 +13,7 @@ type postgresqlConnection struct { db *gorm.DB } -func NewPostgresqlConnection() database.OtterSpace { +func NewPostgresqlConnection() OtterSpace { return &postgresqlConnection{ db: nil, } @@ -22,7 +22,7 @@ func NewPostgresqlConnection() database.OtterSpace { func (p postgresqlConnection) Connect(ctx context.Context, endpoint string, username string, password string, database string, port int, ssl string, timezone string) error { dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", endpoint, username, password, database, port, ssl, timezone) - db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) + db, err := gorm.Open(gormPostgres.Open(dsn), &gorm.Config{}) p.db = db if err != nil { return err @@ -121,8 +121,7 @@ func (p postgresqlConnection) GetAllTags(ctx context.Context) ([]models.TagsWith } func (p postgresqlConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) { - //TODO implement me - panic("implement me") + return postgres.GetAllSourceNodes(ctx, p.db) } func (p postgresqlConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {