✨ Editable content rating for every community moderator
This commit is contained in:
parent
1de0a86074
commit
26a267b111
@ -154,6 +154,38 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
|
||||
}
|
||||
}
|
||||
|
||||
func updateAttachmentRating(c *fiber.Ctx) error {
|
||||
id, _ := c.ParamsInt("id", 0)
|
||||
user := c.Locals("nex_user").(*sec.UserInfo)
|
||||
|
||||
var data struct {
|
||||
ContentRating int `json:"content_rating" validate:"required,min=3,max=21"`
|
||||
QualityRating int `json:"quality_rating" validate:"min=0,max=5"`
|
||||
}
|
||||
|
||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
attachment, err := services.GetAttachmentByID(uint(id))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
} else if attachment.AccountID != user.ID {
|
||||
if err = sec.EnsureGrantedPerm(c, "OverrideAttachmentRating", true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
attachment.ContentRating = data.ContentRating
|
||||
attachment.QualityRating = data.QualityRating
|
||||
|
||||
if attachment, err = services.UpdateAttachment(attachment); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
return c.JSON(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteAttachment(c *fiber.Ctx) error {
|
||||
id, _ := c.ParamsInt("id", 0)
|
||||
user := c.Locals("nex_user").(*sec.UserInfo)
|
||||
|
@ -39,6 +39,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
attachments.Post("/", sec.ValidatorMiddleware, createAttachmentDirectly)
|
||||
attachments.Post("/referenced", sec.ValidatorMiddleware, createAttachmentWithURL)
|
||||
attachments.Put("/:id", sec.ValidatorMiddleware, updateAttachmentMeta)
|
||||
attachments.Put("/:id/rating", sec.ValidatorMiddleware, updateAttachmentRating)
|
||||
attachments.Delete("/:id", sec.ValidatorMiddleware, deleteAttachment)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user