BREAKING CHANGE: V2 of thr SDK #12
@ -2,8 +2,10 @@ package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/graphModels"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/pgModels"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
@ -38,15 +40,26 @@ func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, db *gorm.DB,
|
||||
return executeCheckQuery(ctx, db, "id = ?", string(anthrovePostID))
|
||||
}
|
||||
|
||||
func CheckIfAnthrovePostNodeExistsBySourceURL(ctx context.Context, db *gorm.DB, sourceURL string) (bool, error) {
|
||||
var size int64
|
||||
err := db.WithContext(ctx).Model(&pgModels.PostReference{}).Where("url = ?", sourceURL).Count(&size).Error
|
||||
func CheckIfAnthrovePostNodeExistsBySourceURL(ctx context.Context, db *gorm.DB, sourceURL string) (*graphModels.AnthrovePost, bool, error) {
|
||||
var post pgModels.Post
|
||||
err := db.WithContext(ctx).Model(&pgModels.Post{}).InnerJoins("References", db.Where("url = ?", sourceURL)).First(&post).Error
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, false, nil
|
||||
}
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
return size > 0, nil
|
||||
pgPost := &graphModels.AnthrovePost{
|
||||
PostID: models.AnthrovePostID(post.ID),
|
||||
Rating: post.Rating,
|
||||
}
|
||||
|
||||
//TODO Now test it! :D
|
||||
// Naaa
|
||||
// D:
|
||||
return pgPost, true, nil
|
||||
fenpaws marked this conversation as resolved
Outdated
|
||||
}
|
||||
|
||||
func CheckIfAnthrovePostNodeExistsBySourceID(ctx context.Context, db *gorm.DB, sourceID string) (bool, error) {
|
||||
|
@ -89,8 +89,7 @@ func (p *postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Conte
|
||||
|
||||
// CheckPostNodeExistsBySourceURL NOT WORKING! TODO!
|
||||
func (p *postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*graphModels.AnthrovePost, bool, error) {
|
||||
var post graphModels.AnthrovePost
|
||||
exists, err := postgres.CheckIfAnthrovePostNodeExistsBySourceURL(ctx, p.db, sourceUrl)
|
||||
post, exists, err := postgres.CheckIfAnthrovePostNodeExistsBySourceURL(ctx, p.db, sourceUrl)
|
||||
return &post, exists, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user
didn't we call the sourceURL not postUrl or so?
Something, so we don't mix it up with domainUrl or sourceDomain...