💥 Unified the publisher api

This commit is contained in:
2024-11-09 00:47:19 +08:00
parent f9a01bff70
commit 615fe3ff6c
4 changed files with 19 additions and 12 deletions

View File

@ -110,14 +110,13 @@ func PreloadGeneral(tx *gorm.DB) *gorm.DB {
return tx.
Preload("Tags").
Preload("Categories").
Preload("Realm").
Preload("Author").
Preload("Publisher").
Preload("ReplyTo").
Preload("ReplyTo.Author").
Preload("ReplyTo.Publisher").
Preload("ReplyTo.Tags").
Preload("ReplyTo.Categories").
Preload("RepostTo").
Preload("RepostTo.Author").
Preload("RepostTo.Publisher").
Preload("RepostTo.Tags").
Preload("RepostTo.Categories")
}
@ -327,7 +326,7 @@ func NewPost(user models.Publisher, item models.Post) (models.Post, error) {
var op models.Post
if err := database.C.
Where("id = ?", item.ReplyID).
Preload("Author").
Preload("Publisher").
First(&op).Error; err == nil {
if op.Publisher.AccountID != nil && op.Publisher.ID != user.ID {
log.Debug().Uint("user", *op.Publisher.AccountID).Msg("Notifying the original poster their post got replied...")
@ -406,7 +405,7 @@ func ReactPost(user authm.Account, reaction models.Reaction) (bool, models.React
var op models.Post
if err := database.C.
Where("id = ?", reaction.PostID).
Preload("Author").
Preload("Publisher").
First(&op).Error; err != nil {
return true, reaction, err
}

View File

@ -15,6 +15,14 @@ func GetPublisher(id uint, userID uint) (models.Publisher, error) {
return publisher, nil
}
func GetPublisherByName(name string, userID uint) (models.Publisher, error) {
var publisher models.Publisher
if err := database.C.Where("name = ? AND account_id = ?", name, userID).First(&publisher).Error; err != nil {
return publisher, fmt.Errorf("unable to get publisher: %v", err)
}
return publisher, nil
}
func CreatePersonalPublisher(user authm.Account) (models.Publisher, error) {
var publisher models.Publisher
var count int64