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
2 changed files with 40 additions and 2 deletions
Showing only changes of commit 8d655e991f - Show all commits

View File

@ -0,0 +1,39 @@
package postgres
import (
"context"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/pgModels"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
func EstablishAnthrovePostToSourceLink(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string) error {
var post pgModels.Post
var source pgModels.Source
// Find the post
err := db.WithContext(ctx).Where("id = ?", anthrovePostID).First(&post).Error
if err != nil {
return err
}
// Find the source
err = db.WithContext(ctx).Where("domain = ?", anthroveSourceDomain).First(&source).Error
if err != nil {
return err
}
// Establish the relationship
err = db.WithContext(ctx).Model(&post).Association("Sources").Append(&source)
if err != nil {
return err
}
log.WithFields(log.Fields{
"anthrove_post_id": anthrovePostID,
"anthrove_source_domain": anthroveSourceDomain,
}).Trace("database: created anthrove post to source link")
return nil
}

View File

@ -73,8 +73,7 @@ func (p *postgresqlConnection) AddTagWithRelationToPost(ctx context.Context, ant
}
func (p *postgresqlConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *graphModels.AnthrovePostRelationship) error {
//TODO implement me
panic("implement me")
return postgres.EstablishAnthrovePostToSourceLink(ctx, p.db, anthrovePostID, anthroveSourceDomain)
}
func (p *postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error {