BREAKING CHANGE: V2 of thr SDK #12
@ -28,3 +28,33 @@ func CreateAnthrovePostNode(ctx context.Context, db *gorm.DB, anthrovePostID mod
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckIfAnthrovePostNodeExistsByAnthroveID(ctx context.Context, db *gorm.DB, anthrovePostID models.AnthrovePostID) (bool, error) {
|
||||||
|
return executeCheckQuery(ctx, db, "id = ?", string(anthrovePostID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckIfAnthrovePostNodeExistsBySourceURL(ctx context.Context, db *gorm.DB, sourceURL string) (bool, error) {
|
||||||
|
return executeCheckQuery(ctx, db, "url = ?", sourceURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckIfAnthrovePostNodeExistsBySourceID(ctx context.Context, db *gorm.DB, sourceID string) (bool, error) {
|
||||||
|
return executeCheckQuery(ctx, db, "source_id = ?", sourceID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeCheckQuery(ctx context.Context, db *gorm.DB, query string, args ...interface{}) (bool, error) {
|
||||||
|
var count int64
|
||||||
|
err := db.WithContext(ctx).Model(&pgModels.Post{}).Where(query, args...).Count(&count).Error
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
exists := count > 0
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"query": query,
|
||||||
|
"args": args,
|
||||||
|
"exists": exists,
|
||||||
|
}).Trace("database: executed check query")
|
||||||
|
|
||||||
|
return exists, nil
|
||||||
|
}
|
||||||
|
@ -84,18 +84,22 @@ func (p *postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUs
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *graphModels.AnthrovePost) (*graphModels.AnthrovePost, bool, error) {
|
func (p *postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *graphModels.AnthrovePost) (*graphModels.AnthrovePost, bool, error) {
|
||||||
//TODO implement me
|
exists, err := postgres.CheckIfAnthrovePostNodeExistsByAnthroveID(ctx, p.db, anthrovePost.PostID)
|
||||||
panic("implement me")
|
return anthrovePost, exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckPostNodeExistsBySourceURL NOT WORKING! TODO!
|
||||||
func (p *postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*graphModels.AnthrovePost, bool, error) {
|
func (p *postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*graphModels.AnthrovePost, bool, error) {
|
||||||
//TODO implement me
|
var post graphModels.AnthrovePost
|
||||||
panic("implement me")
|
exists, err := postgres.CheckIfAnthrovePostNodeExistsBySourceURL(ctx, p.db, sourceUrl)
|
||||||
|
return &post, exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckPostNodeExistsBySourceID NOT WORKING! TODO!
|
||||||
func (p *postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*graphModels.AnthrovePost, bool, error) {
|
func (p *postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*graphModels.AnthrovePost, bool, error) {
|
||||||
//TODO implement me
|
var post graphModels.AnthrovePost
|
||||||
panic("implement me")
|
exists, err := postgres.CheckIfAnthrovePostNodeExistsBySourceID(ctx, p.db, sourcePostID)
|
||||||
|
return &post, exists, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
func (p *postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
|
||||||
|
@ -14,12 +14,15 @@ type BaseModel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (base *BaseModel) BeforeCreate(db *gorm.DB) error {
|
func (base *BaseModel) BeforeCreate(db *gorm.DB) error {
|
||||||
|
|
||||||
|
if base.ID == "" {
|
||||||
id, err := gonanoid.New()
|
id, err := gonanoid.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
base.ID = id
|
base.ID = id
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user