From bd22ed3f7933a9990be34164f259b5fb1f9121f0 Mon Sep 17 00:00:00 2001 From: soxx Date: Fri, 14 Jun 2024 13:29:53 +0200 Subject: [PATCH] feat(postgres): added AddPost --- internal/postgres/post.go | 30 ++++++++++++++++++++++++++++++ pkg/database/postgres.go | 3 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 internal/postgres/post.go diff --git a/internal/postgres/post.go b/internal/postgres/post.go new file mode 100644 index 0000000..ff3d0d3 --- /dev/null +++ b/internal/postgres/post.go @@ -0,0 +1,30 @@ +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 CreateAnthrovePostNode(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID, anthroveRating models.Rating) error { + post := pgModels.Post{ + BaseModel: pgModels.BaseModel{ + ID: string(anthrovePostID), + }, + Rating: anthroveRating, + } + + err := db.WithContext(ctx).Create(&post).Error + if err != nil { + return err + } + + log.WithFields(log.Fields{ + "anthrove_post_id": anthrovePostID, + "anthrove_post_rating": anthroveRating, + }).Trace("database: created anthrove post") + + return nil +} diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index 661a884..bc4b494 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -64,8 +64,7 @@ func (p *postgresqlConnection) AddSource(ctx context.Context, anthroveSource *gr } func (p *postgresqlConnection) AddPost(ctx context.Context, anthrovePost *graphModels.AnthrovePost) error { - //TODO implement me - panic("implement me") + return postgres.CreateAnthrovePostNode(ctx, p.db, anthrovePost.PostID, anthrovePost.Rating) } func (p *postgresqlConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *graphModels.AnthroveTag) error {