photoprism/internal/api/feedback.go
Michael Mayer e3bb8b19dd Routing: Prefix frontend UI routes with /library #840 #2466
Also improves migrations and updates the db schema docs.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-15 21:54:11 +02:00

56 lines
1.0 KiB
Go

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/acl"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/get"
"github.com/photoprism/photoprism/internal/i18n"
)
// SendFeedback sends a feedback message.
//
// POST /api/v1/feedback
func SendFeedback(router *gin.RouterGroup) {
router.POST("/feedback", func(c *gin.Context) {
conf := get.Config()
if conf.Public() {
Abort(c, http.StatusForbidden, i18n.ErrPublic)
return
}
s := Auth(c, acl.ResourceFeedback, acl.ActionCreate)
// Abort if permission was not granted.
if s.Abort(c) {
return
}
conf.UpdateHub()
var f form.Feedback
if err := c.BindJSON(&f); err != nil {
AbortBadRequest(c)
return
}
if f.Empty() {
Abort(c, http.StatusBadRequest, i18n.ErrNoItemsSelected)
return
}
if err := conf.Hub().SendFeedback(f); err != nil {
log.Error(err)
AbortSaveFailed(c)
return
}
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK})
})
}