52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"SciencesServer/app/api/admin/controller"
|
|
"SciencesServer/app/basic/api"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Config struct{}
|
|
|
|
func (a *Config) Index(c *gin.Context) {
|
|
form := &struct {
|
|
Kind int `json:"kind" form:"kind"`
|
|
api.PageForm
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
data, err := controller.NewConfig()().Config(form.Kind, form.Page, form.PageSize)
|
|
api.APIResponse(err, data)(c)
|
|
}
|
|
|
|
func (a *Config) Add(c *gin.Context) {
|
|
form := &struct {
|
|
Kind int `json:"kind" form:"kind" binding:"required"`
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Key string `json:"key" form:"key" binding:"required"`
|
|
Value string `json:"value" form:"value" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := controller.NewConfig()().Add(form.Kind, form.Name, form.Key, form.Value)
|
|
api.APIResponse(err)(c)
|
|
}
|
|
|
|
func (a *Config) Edit(c *gin.Context) {
|
|
form := &struct {
|
|
api.IDStringForm
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Value string `json:"value" form:"value" binding:"required"`
|
|
}{}
|
|
if err := api.Bind(form)(c); err != nil {
|
|
api.APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := controller.NewConfig()().Form(form.Convert(), form.Name, form.Value)
|
|
api.APIResponse(err)(c)
|
|
}
|