BREAKING CHANGE: V2 of thr SDK #12

Merged
fenpaws merged 124 commits from develop/postgresql into main 2024-07-01 20:46:28 +00:00
7 changed files with 28 additions and 14 deletions
Showing only changes of commit 56bb414f9d - Show all commits

View File

@ -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)
} }

View File

@ -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) {

View File

@ -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",

View File

@ -23,7 +23,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 +66,14 @@ 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)
/*
CreateTagAlias()
DeleteTagAlias()
UpdateTagWithAlias()
CreateTagGroup()
DeleteTagGroup()
UpdateTagWithGroup()
UpdateUserWithScrapeTimeInterval()*/
} }

View File

@ -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 {

View File

@ -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)
} }

View File

@ -4,6 +4,10 @@ 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