2024-06-03 20:18:02 +00:00
|
|
|
package database
|
2024-06-03 19:31:44 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-06-03 20:18:02 +00:00
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/internal/postgres"
|
2024-06-03 19:31:44 +00:00
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
2024-06-03 21:55:30 +00:00
|
|
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/graphModels"
|
2024-06-03 20:18:02 +00:00
|
|
|
gormPostgres "gorm.io/driver/postgres"
|
2024-06-03 19:31:44 +00:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type postgresqlConnection struct {
|
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
|
2024-06-03 20:18:02 +00:00
|
|
|
func NewPostgresqlConnection() OtterSpace {
|
2024-06-03 19:31:44 +00:00
|
|
|
return &postgresqlConnection{
|
|
|
|
db: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2024-06-03 20:18:02 +00:00
|
|
|
db, err := gorm.Open(gormPostgres.Open(dsn), &gorm.Config{})
|
2024-06-03 19:31:44 +00:00
|
|
|
p.db = db
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postgresqlConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) AddSource(ctx context.Context, anthroveSource *graphModels.AnthroveSource) error {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) AddPost(ctx context.Context, anthrovePost *graphModels.AnthrovePost) error {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *graphModels.AnthroveTag) error {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *graphModels.AnthrovePostRelationship) error {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *graphModels.AnthrovePost) (*graphModels.AnthrovePost, bool, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*graphModels.AnthrovePost, bool, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*graphModels.AnthrovePost, bool, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]graphModels.AnthroveUserRelationship, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]graphModels.AnthroveUserRelationship, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*graphModels.AnthroveUser, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*graphModels.FavoriteList, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]graphModels.TagsWithFrequency, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetAllTags(ctx context.Context) ([]graphModels.TagsWithFrequency, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetAllSources(ctx context.Context) ([]graphModels.AnthroveSource, error) {
|
2024-06-03 20:18:02 +00:00
|
|
|
return postgres.GetAllSourceNodes(ctx, p.db)
|
2024-06-03 19:31:44 +00:00
|
|
|
}
|
|
|
|
|
2024-06-03 21:55:30 +00:00
|
|
|
func (p postgresqlConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*graphModels.AnthroveSource, error) {
|
2024-06-03 19:31:44 +00:00
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|