BREAKING CHANGE: V2 of thr SDK #12
39
internal/postgres/relationships.go
Normal file
39
internal/postgres/relationships.go
Normal 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
|
||||||
|
}
|
@ -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 {
|
func (p *postgresqlConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *graphModels.AnthrovePostRelationship) error {
|
||||||
//TODO implement me
|
return postgres.EstablishAnthrovePostToSourceLink(ctx, p.db, anthrovePostID, anthroveSourceDomain)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error {
|
func (p *postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *graphModels.AnthroveUser, anthrovePost *graphModels.AnthrovePost) error {
|
||||||
|
Reference in New Issue
Block a user