fix(postgres): CheckIfAnthrovePostNodeExistsBySourceURL function to use PostReference model

Signed-off-by: soxx <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-06-21 23:25:55 +02:00
parent c359b4636e
commit c07fd69f4f

View File

@ -41,8 +41,8 @@ func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, db *gorm.DB,
} }
func CheckIfAnthrovePostNodeExistsBySourceURL(ctx context.Context, db *gorm.DB, sourceURL string) (*graphModels.AnthrovePost, bool, error) { func CheckIfAnthrovePostNodeExistsBySourceURL(ctx context.Context, db *gorm.DB, sourceURL string) (*graphModels.AnthrovePost, bool, error) {
post := pgModels.Post{} postRef := pgModels.PostReference{}
err := db.WithContext(ctx).Model(&pgModels.Post{}).InnerJoins("References", db.Where("url = ?", sourceURL)).First(&post).Error err := db.WithContext(ctx).Model(&pgModels.PostReference{}).Where("url = ?", sourceURL).First(&postRef).Error
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
@ -51,6 +51,13 @@ func CheckIfAnthrovePostNodeExistsBySourceURL(ctx context.Context, db *gorm.DB,
return nil, false, err return nil, false, err
} }
var post pgModels.Post
err = db.WithContext(ctx).First(&post, "id = ?", postRef.PostID).Error
if err != nil {
return nil, false, err
}
pgPost := graphModels.AnthrovePost{ pgPost := graphModels.AnthrovePost{
PostID: models.AnthrovePostID(post.ID), PostID: models.AnthrovePostID(post.ID),
Rating: post.Rating, Rating: post.Rating,