mirror of https://github.com/synctv-org/synctv
Feat: impl admin api
parent
aa6fa5411f
commit
94823a3d96
@ -1,7 +1,33 @@
|
||||
package handlers
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
dbModel "github.com/synctv-org/synctv/internal/model"
|
||||
"github.com/synctv-org/synctv/internal/op"
|
||||
"github.com/synctv-org/synctv/server/model"
|
||||
)
|
||||
|
||||
func AdminSettings(ctx *gin.Context) {
|
||||
// user := ctx.MustGet("user").(*op.User)
|
||||
|
||||
req := model.AdminSettingsReq{}
|
||||
if err := req.Decode(ctx); err != nil {
|
||||
ctx.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range req {
|
||||
t, ok := op.GetSettingType(k)
|
||||
if !ok {
|
||||
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp(fmt.Sprintf("setting %s not found", k)))
|
||||
return
|
||||
}
|
||||
switch t {
|
||||
case dbModel.SettingTypeBool:
|
||||
op.BoolSettings[k].Set(v == "1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
json "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type AdminSettingsReq map[string]string
|
||||
|
||||
func (asr *AdminSettingsReq) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (asr *AdminSettingsReq) Decode(ctx *gin.Context) error {
|
||||
return json.NewDecoder(ctx.Request.Body).Decode(asr)
|
||||
}
|
Loading…
Reference in New Issue