feat(postgres): added CheckUserPostLink
This commit is contained in:
parent
a430c3b582
commit
ad3a43366b
@ -56,3 +56,21 @@ func EstablishUserToPostLink(ctx context.Context, db *gorm.DB, anthroveUserID mo
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckUserToPostLink(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) (bool, error) {
|
||||
var count int64
|
||||
err := db.WithContext(ctx).Model(&pgModels.UserFavorite{}).Where("user_id = ? AND post_id = ?", string(anthroveUserID), string(anthrovePostID)).Count(&count).Error
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
exists := count > 0
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"relationship_exists": exists,
|
||||
"relationship_anthrove_user_id": anthroveUserID,
|
||||
"relationship_anthrove_post_id": anthrovePostID,
|
||||
}).Trace("database: checked user post relationship")
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
@ -81,8 +81,7 @@ func (p *postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUse
|
||||
}
|
||||
|
||||
func (p *postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
return postgres.CheckUserToPostLink(ctx, p.db, anthroveUserID, models.AnthrovePostID(sourcePostID))
|
||||
}
|
||||
|
||||
func (p *postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *graphModels.AnthrovePost) (*graphModels.AnthrovePost, bool, error) {
|
||||
|
Reference in New Issue
Block a user