Compare commits

...

3 Commits

Author SHA1 Message Date
ea2958b27d feat(sources): finished implementing get all sources
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-03 22:18:02 +02:00
ebc7fcc571 feat(sources): get all source nodes
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-03 22:14:50 +02:00
c1df01d113 chore: reorganizing code
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-03 21:45:39 +02:00
3 changed files with 29 additions and 5 deletions

View File

@ -0,0 +1,25 @@
package postgres
import (
"context"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
// GetAllSourceNodes returns a list of all models.AnthroveSource
func GetAllSourceNodes(ctx context.Context, db *gorm.DB) ([]models.AnthroveSource, error) {
var sources []models.AnthroveSource
result := db.WithContext(ctx).Find(&sources)
if result.Error != nil {
return nil, result.Error
}
log.WithFields(log.Fields{
"tag_amount": result.RowsAffected,
}).Trace("database: get all source nodes")
return sources, nil
}

View File

@ -3,7 +3,6 @@ package database
import (
"context"
"git.dragse.it/anthrove/otter-space-sdk/internal/graph"
"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"

View File

@ -3,8 +3,9 @@ package database
import (
"context"
"fmt"
"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"
)
@ -21,7 +22,7 @@ func NewPostgresqlConnection() 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
@ -120,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) {