|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/internal/postgres"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/internal/postgres"
|
|
|
|
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/internal/utils"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/graphModels"
|
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/graphModels"
|
|
|
|
_ "github.com/lib/pq"
|
|
|
|
_ "github.com/lib/pq"
|
|
|
@ -29,7 +30,7 @@ func NewPostgresqlConnection() OtterSpace {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) Connect(_ context.Context, endpoint string, username string, password string, database string, port int, ssl string, timezone string) error {
|
|
|
|
func (p *postgresqlConnection) Connect(_ 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)
|
|
|
|
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", endpoint, username, password, database, port, ssl, timezone)
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
|
@ -40,7 +41,8 @@ func (p postgresqlConnection) Connect(_ context.Context, endpoint string, userna
|
|
|
|
|
|
|
|
|
|
|
|
log.Infof("OtterSpace: migration compleate")
|
|
|
|
log.Infof("OtterSpace: migration compleate")
|
|
|
|
|
|
|
|
|
|
|
|
p.db, err = gorm.Open(gormPostgres.Open(dsn), &gorm.Config{})
|
|
|
|
db, err := gorm.Open(gormPostgres.Open(dsn), &gorm.Config{})
|
|
|
|
|
|
|
|
p.db = db
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -50,106 +52,113 @@ func (p postgresqlConnection) Connect(_ context.Context, endpoint string, userna
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
|
|
|
func (p *postgresqlConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) AddSource(ctx context.Context, anthroveSource *graphModels.AnthroveSource) error {
|
|
|
|
func (p *postgresqlConnection) AddSource(ctx context.Context, anthroveSource *graphModels.AnthroveSource) error {
|
|
|
|
|
|
|
|
source := utils.GraphConvertSource(anthroveSource)
|
|
|
|
|
|
|
|
return postgres.CreateSourceNode(ctx, p.db, source)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (p *postgresqlConnection) AddPost(ctx context.Context, anthrovePost *graphModels.AnthrovePost) error {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) AddPost(ctx context.Context, anthrovePost *graphModels.AnthrovePost) error {
|
|
|
|
func (p *postgresqlConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *graphModels.AnthroveTag) error {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *graphModels.AnthroveTag) error {
|
|
|
|
func (p *postgresqlConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *graphModels.AnthrovePostRelationship) error {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *graphModels.AnthrovePostRelationship) error {
|
|
|
|
func (p *postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error {
|
|
|
|
func (p *postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
|
|
|
|
func (p *postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *graphModels.AnthrovePost) (*graphModels.AnthrovePost, bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *graphModels.AnthrovePost) (*graphModels.AnthrovePost, bool, error) {
|
|
|
|
func (p *postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*graphModels.AnthrovePost, bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*graphModels.AnthrovePost, bool, error) {
|
|
|
|
func (p *postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*graphModels.AnthrovePost, bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*graphModels.AnthrovePost, bool, error) {
|
|
|
|
func (p *postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
|
|
|
func (p *postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {
|
|
|
|
func (p *postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]graphModels.AnthroveUserRelationship, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]graphModels.AnthroveUserRelationship, error) {
|
|
|
|
func (p *postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
|
|
|
func (p *postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
|
|
|
func (p *postgresqlConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*graphModels.FavoriteList, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*graphModels.FavoriteList, error) {
|
|
|
|
func (p *postgresqlConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]graphModels.TagsWithFrequency, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]graphModels.TagsWithFrequency, error) {
|
|
|
|
func (p *postgresqlConnection) GetAllTags(ctx context.Context) ([]graphModels.TagsWithFrequency, error) {
|
|
|
|
//TODO implement me
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetAllTags(ctx context.Context) ([]graphModels.TagsWithFrequency, error) {
|
|
|
|
func (p *postgresqlConnection) GetAllSources(ctx context.Context) ([]graphModels.AnthroveSource, error) {
|
|
|
|
//TODO implement me
|
|
|
|
var anthroveSources []graphModels.AnthroveSource
|
|
|
|
panic("implement me")
|
|
|
|
source, err := postgres.GetAllSourceNodes(ctx, p.db)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range source {
|
|
|
|
|
|
|
|
anthroveSource := utils.PostgresConvertToAnthroveSource(&v)
|
|
|
|
|
|
|
|
anthroveSources = append(anthroveSources, *anthroveSource)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetAllSources(ctx context.Context) ([]graphModels.AnthroveSource, error) {
|
|
|
|
func (p *postgresqlConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*graphModels.AnthroveSource, error) {
|
|
|
|
return postgres.GetAllSourceNodes(ctx, p.db)
|
|
|
|
source, err := postgres.GetSourceNodesByURL(ctx, p.db, sourceUrl)
|
|
|
|
|
|
|
|
return utils.PostgresConvertToAnthroveSource(source), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*graphModels.AnthroveSource, error) {
|
|
|
|
func (p *postgresqlConnection) migrateDatabase(connectionString string) error {
|
|
|
|
//TODO implement me
|
|
|
|
|
|
|
|
panic("implement me")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (p postgresqlConnection) migrateDatabase(connectionString string) error {
|
|
|
|
|
|
|
|
dialect := "postgres"
|
|
|
|
dialect := "postgres"
|
|
|
|
migrations := &migrate.EmbedFileSystemMigrationSource{FileSystem: embedMigrations, Root: "migrations"}
|
|
|
|
migrations := &migrate.EmbedFileSystemMigrationSource{FileSystem: embedMigrations, Root: "migrations"}
|
|
|
|
|
|
|
|
|
|
|
|