This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lang_post.go
52 lines (45 loc) · 1.53 KB
/
lang_post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package recording
import (
"net/http"
"dev.sum7.eu/genofire/golang-lib/web"
"dev.sum7.eu/genofire/golang-lib/web/auth"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/Kukoon/media-server/models"
)
// @Summary Create new recording description
// @Description Create new recording description on given Recording
// @Tags recording
// @Produce json
// @Success 200 {object} models.RecordingLang
// @Failure 400 {object} web.HTTPError
// @Failure 401 {object} web.HTTPError
// @Failure 404 {object} web.HTTPError
// @Failure 500 {object} web.HTTPError
// @Router /api/v1/recording/{recording_id}/lang [post]
// @Param recording_id path string false "uuid of recording"
// @Param body body models.RecordingLang false "new values in recording description"
// @Security ApiKeyAuth
func apiLangPost(r *gin.Engine, ws *web.Service) {
r.POST("/api/v1/recording/:uuid/lang", auth.MiddlewarePermissionParamUUID(ws, models.Recording{}), func(c *gin.Context) {
id := uuid.MustParse(c.Params.ByName("uuid"))
var data models.RecordingLang
if err := c.BindJSON(&data); err != nil {
c.JSON(http.StatusBadRequest, web.HTTPError{
Message: web.ErrAPIInvalidRequestFormat.Error(),
Error: err.Error(),
})
return
}
data.ID = uuid.Nil
data.RecordingID = id
if err := ws.DB.Omit("CreatedAt", "UpdatedAt").Create(&data).Error; err != nil {
c.JSON(http.StatusInternalServerError, web.HTTPError{
Message: web.ErrAPIInternalDatabase.Error(),
Error: err.Error(),
})
return
}
c.JSON(http.StatusOK, &data)
})
}