Compare commits
3 Commits
da4fda3597
...
9c8a7c1e16
Author | SHA1 | Date | |
---|---|---|---|
9c8a7c1e16 | |||
51aa79e4c2 | |||
56bb414f9d |
@ -199,7 +199,7 @@ func TestGetPostBySourceURL(t *testing.T) {
|
|||||||
t.Fatal("Could not create source", err)
|
t.Fatal("Could not create source", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "http://test.org")
|
err = CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "http://test.org", models.PostReferenceConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Could not create source reference", err)
|
t.Fatal("Could not create source reference", err)
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ func TestGetPostBySourceID(t *testing.T) {
|
|||||||
t.Fatal("Could not create source", err)
|
t.Fatal("Could not create source", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "http://test.otg")
|
err = CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "http://test.otg", models.PostReferenceConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Could not create source reference", err)
|
t.Fatal("Could not create source reference", err)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain, postURL models.AnthrovePostURL) error {
|
func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain, postURL models.AnthrovePostURL, config models.PostReferenceConfig) error {
|
||||||
if anthrovePostID == "" {
|
if anthrovePostID == "" {
|
||||||
return &otterError.EntityValidationFailed{Reason: otterError.AnthroveUserIDIsEmpty}
|
return &otterError.EntityValidationFailed{Reason: otterError.AnthroveUserIDIsEmpty}
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ func CreateReferenceBetweenPostAndSource(ctx context.Context, db *gorm.DB, anthr
|
|||||||
return &otterError.EntityValidationFailed{Reason: "sourceDomain cannot be empty"}
|
return &otterError.EntityValidationFailed{Reason: "sourceDomain cannot be empty"}
|
||||||
}
|
}
|
||||||
|
|
||||||
result := db.WithContext(ctx).Exec(`INSERT INTO "PostReference" (post_id, source_id, url) SELECT $1, source.id, $2 FROM "Source" AS source WHERE domain = $3;`, anthrovePostID, postURL, sourceDomain)
|
result := db.WithContext(ctx).Exec(`INSERT INTO "PostReference" (post_id, source_id, url, full_file_url, preview_file_url, sample_file_url, source_post_id) SELECT $1, source.id, $2, $4, $5, $6, $7 FROM "Source" AS source WHERE domain = $3;`, anthrovePostID, postURL, sourceDomain, config.FullFileURL, config.PreviewFileURL, config.SampleFileURL, config.SourcePostID)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
@ -162,7 +162,7 @@ func TestCreateUserNodeWithSourceRelation(t *testing.T) {
|
|||||||
userID: "e1",
|
userID: "e1",
|
||||||
username: "marius",
|
username: "marius",
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test 5: no userID",
|
name: "Test 5: no userID",
|
||||||
|
@ -2,7 +2,6 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ type OtterSpace interface {
|
|||||||
CreateTagAndReferenceToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.Tag) error
|
CreateTagAndReferenceToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.Tag) error
|
||||||
|
|
||||||
// CreateReferenceBetweenPostAndSource links a post with a source.
|
// CreateReferenceBetweenPostAndSource links a post with a source.
|
||||||
CreateReferenceBetweenPostAndSource(ctx context.Context, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain, postURL models.AnthrovePostURL) error
|
CreateReferenceBetweenPostAndSource(ctx context.Context, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain, postURL models.AnthrovePostURL, config models.PostReferenceConfig) error
|
||||||
|
|
||||||
// CreateReferenceBetweenUserAndPost links a user with a post.
|
// CreateReferenceBetweenUserAndPost links a user with a post.
|
||||||
CreateReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error
|
CreateReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error
|
||||||
@ -66,4 +65,16 @@ type OtterSpace interface {
|
|||||||
|
|
||||||
// GetSourceByDomain retrieves a source by its URL.
|
// GetSourceByDomain retrieves a source by its URL.
|
||||||
GetSourceByDomain(ctx context.Context, sourceDomain models.AnthroveSourceDomain) (*models.Source, error)
|
GetSourceByDomain(ctx context.Context, sourceDomain models.AnthroveSourceDomain) (*models.Source, error)
|
||||||
|
|
||||||
|
GetAllTagAlias(ctx context.Context) ([]models.TagAlias, error)
|
||||||
|
GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error)
|
||||||
|
CreateTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName, tagID models.AnthroveTagID) error
|
||||||
|
DeleteTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName) error
|
||||||
|
|
||||||
|
GetAllTagGroup(ctx context.Context) ([]models.TagGroup, error)
|
||||||
|
GetAllTagGroupByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagGroup, error)
|
||||||
|
CreateTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName, tagID models.AnthroveTagID)
|
||||||
|
DeleteTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName) error
|
||||||
|
|
||||||
|
UpdateUserWithScrapeTimeInterval(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, scrapeTime models.AnthroveScrapeTimeInterval) error
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ func (p *postgresqlConnection) CreateTagAndReferenceToPost(ctx context.Context,
|
|||||||
return postgres.CreateTagAndReferenceToPost(ctx, p.db, anthrovePostID, anthroveTag)
|
return postgres.CreateTagAndReferenceToPost(ctx, p.db, anthrovePostID, anthroveTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) CreateReferenceBetweenPostAndSource(ctx context.Context, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain, postURL models.AnthrovePostURL) error {
|
func (p *postgresqlConnection) CreateReferenceBetweenPostAndSource(ctx context.Context, anthrovePostID models.AnthrovePostID, sourceDomain models.AnthroveSourceDomain, postURL models.AnthrovePostURL, config models.PostReferenceConfig) error {
|
||||||
return postgres.CreateReferenceBetweenPostAndSource(ctx, p.db, anthrovePostID, sourceDomain, postURL)
|
return postgres.CreateReferenceBetweenPostAndSource(ctx, p.db, anthrovePostID, sourceDomain, postURL, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) CreateReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error {
|
func (p *postgresqlConnection) CreateReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error {
|
||||||
@ -148,6 +148,51 @@ func (p *postgresqlConnection) GetSourceByDomain(ctx context.Context, sourceDoma
|
|||||||
return postgres.GetSourceByDomain(ctx, p.db, sourceDomain)
|
return postgres.GetSourceByDomain(ctx, p.db, sourceDomain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) GetAllTagAlias(ctx context.Context) ([]models.TagAlias, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) CreateTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName, tagID models.AnthroveTagID) error {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) DeleteTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName) error {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) GetAllTagGroup(ctx context.Context) ([]models.TagGroup, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) GetAllTagGroupByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagGroup, error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) CreateTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName, tagID models.AnthroveTagID) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) DeleteTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName) error {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *postgresqlConnection) UpdateUserWithScrapeTimeInterval(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, scrapeTime models.AnthroveScrapeTimeInterval) error {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) migrateDatabase(dbPool *gorm.DB) error {
|
func (p *postgresqlConnection) migrateDatabase(dbPool *gorm.DB) error {
|
||||||
dialect := "postgres"
|
dialect := "postgres"
|
||||||
migrations := &migrate.EmbedFileSystemMigrationSource{FileSystem: embedMigrations, Root: "migrations"}
|
migrations := &migrate.EmbedFileSystemMigrationSource{FileSystem: embedMigrations, Root: "migrations"}
|
||||||
|
@ -521,7 +521,7 @@ func Test_postgresqlConnection_CreateReferenceBetweenPostAndSource(t *testing.T)
|
|||||||
db: gormDB,
|
db: gormDB,
|
||||||
debug: true,
|
debug: true,
|
||||||
}
|
}
|
||||||
if err := p.CreateReferenceBetweenPostAndSource(tt.args.ctx, tt.args.anthrovePostID, tt.args.sourceDomain, tt.args.postURl); (err != nil) != tt.wantErr {
|
if err := p.CreateReferenceBetweenPostAndSource(tt.args.ctx, tt.args.anthrovePostID, tt.args.sourceDomain, tt.args.postURl, models.PostReferenceConfig{}); (err != nil) != tt.wantErr {
|
||||||
t.Errorf("CreateReferenceBetweenPostAndSource() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("CreateReferenceBetweenPostAndSource() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -834,7 +834,7 @@ func Test_postgresqlConnection_GetPostByURL(t *testing.T) {
|
|||||||
t.Fatal("Could not create source", err)
|
t.Fatal("Could not create source", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = postgres.CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "https://e62asdwad.com/asdas")
|
err = postgres.CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "https://e62asdwad.com/asdas", models.PostReferenceConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Could not create source reference", err)
|
t.Fatal("Could not create source reference", err)
|
||||||
}
|
}
|
||||||
@ -935,7 +935,7 @@ func Test_postgresqlConnection_GetPostBySourceID(t *testing.T) {
|
|||||||
t.Fatal("Could not create source", err)
|
t.Fatal("Could not create source", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = postgres.CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "https://easd15aed.de/asd")
|
err = postgres.CreateReferenceBetweenPostAndSource(ctx, gormDB, post.ID, models.AnthroveSourceDomain(source.Domain), "https://easd15aed.de/asd", models.PostReferenceConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Could not create source reference", err)
|
t.Fatal("Could not create source reference", err)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "google.golang.org/genproto/googleapis/type/date"
|
||||||
|
|
||||||
type AnthroveUserID string
|
type AnthroveUserID string
|
||||||
type AnthrovePostID string
|
type AnthrovePostID string
|
||||||
type AnthroveSourceID string
|
type AnthroveSourceID string
|
||||||
type AnthroveSourceDomain string
|
type AnthroveSourceDomain string
|
||||||
type AnthrovePostURL string
|
type AnthrovePostURL string
|
||||||
|
type AnthroveTagGroupName string
|
||||||
|
type AnthroveTagAliasName string
|
||||||
|
type AnthroveTagID string
|
||||||
|
type AnthroveScrapeTimeInterval date.Date
|
||||||
|
|
||||||
type Rating string
|
type Rating string
|
||||||
type TagType string
|
type TagType string
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type PostReference struct {
|
type PostReference struct {
|
||||||
PostID string `gorm:"primaryKey"`
|
PostID string `gorm:"primaryKey"`
|
||||||
SourceID string `gorm:"primaryKey"`
|
SourceID string `gorm:"primaryKey"`
|
||||||
URL string `gorm:"not null;unique"`
|
URL string `gorm:"not null;unique"`
|
||||||
|
PostReferenceConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
type PostReferenceConfig struct {
|
||||||
SourcePostID string
|
SourcePostID string
|
||||||
FullFileURL string
|
FullFileURL string
|
||||||
PreviewFileURL string
|
PreviewFileURL string
|
||||||
|
@ -3,17 +3,15 @@ package test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||||
migrate "github.com/rubenv/sql-migrate"
|
migrate "github.com/rubenv/sql-migrate"
|
||||||
postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres"
|
postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/testcontainers/testcontainers-go"
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/wait"
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
@ -34,9 +32,7 @@ func StartPostgresContainer(ctx context.Context) (*postgrescontainer.PostgresCon
|
|||||||
postgrescontainer.WithUsername(databaseUser),
|
postgrescontainer.WithUsername(databaseUser),
|
||||||
postgrescontainer.WithPassword(databasePassword),
|
postgrescontainer.WithPassword(databasePassword),
|
||||||
testcontainers.WithWaitStrategy(
|
testcontainers.WithWaitStrategy(
|
||||||
wait.ForLog("database system is ready to accept connections").
|
wait.ForLog("database system is ready to accept connections")))
|
||||||
WithOccurrence(2).WithStartupTimeout(10*time.Second)),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user