💥 Unified the publisher api
This commit is contained in:
parent
f9a01bff70
commit
615fe3ff6c
@ -14,8 +14,8 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
publishers.Post("/organization", createOrganizationPublisher)
|
||||
publishers.Get("/:name/pins", listPinnedPost)
|
||||
publishers.Get("/:name", getPublisher)
|
||||
publishers.Put("/:publisherId", editPublisher)
|
||||
publishers.Delete("/:publisherId", deletePublisher)
|
||||
publishers.Put("/:name", editPublisher)
|
||||
publishers.Delete("/:name", deletePublisher)
|
||||
}
|
||||
|
||||
recommendations := api.Group("/recommendations").Name("Recommendations API")
|
||||
|
@ -109,8 +109,8 @@ func editPublisher(c *fiber.Ctx) error {
|
||||
}
|
||||
user := c.Locals("user").(authm.Account)
|
||||
|
||||
id, _ := c.ParamsInt("publisherId", 0)
|
||||
publisher, err := services.GetPublisher(uint(id), user.ID)
|
||||
name := c.Params("name")
|
||||
publisher, err := services.GetPublisherByName(name, user.ID)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
@ -150,8 +150,8 @@ func deletePublisher(c *fiber.Ctx) error {
|
||||
}
|
||||
user := c.Locals("user").(authm.Account)
|
||||
|
||||
id, _ := c.ParamsInt("publisherId", 0)
|
||||
publisher, err := services.GetPublisher(uint(id), user.ID)
|
||||
name := c.Params("name")
|
||||
publisher, err := services.GetPublisherByName(name, user.ID)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user