Files
ArmedPolice/app/api/config.go
2021-11-18 09:51:39 +08:00

242 lines
5.9 KiB
Go

package api
import (
"ArmedPolice/app/controller/config"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Config struct{}
/**
* @apiDefine Config 配置管理
*/
func (*Config) List(c *gin.Context) {
form := &struct {
Kind int `json:"kind" form:"kind"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := config.NewInstance()().List(form.Kind, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
func (*Config) Edit(c *gin.Context) {
form := &struct {
Params map[string]interface{} `json:"params" form:"params"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := config.NewInstance()().Form(form.Params)
APIResponse(err)(c)
}
/**
* @api {get} /api/v1/config/area 区域信息
* @apiVersion 1.0.0
* @apiName ConfigArea
* @apiGroup Config
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [key="''"] 区域标识
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息{"110000": "北京市", "120000": "天津市", ...}
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "110000": "北京市",
* "120000": "天津市",
* "130000": "河北省",
* "140000": "山西省",
* }
* }
*/
func (*Config) Area(c *gin.Context) {
form := &struct {
Key string `json:"key" form:"key"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data := config.NewArea()(getSession()(c).(*service.Session)).List(form.Key)
APIResponse(nil, data)(c)
}
/**
* @api {post} /api/v1/config/breakdown 故障信息
* @apiVersion 1.0.0
* @apiName ConfigBreakdown
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} [title="''"] 标题名称
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.id ID
* @apiSuccess (200) {String} data.title 标题名称
* @apiSuccess (200) {String} data.remark 备注信息
* @apiSuccess (200) {Time} data.created_at 创建时间
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* {
* "id": "m9Qa2ZaOvE",
* "title": "刹车盘",
* "remark": "",
* "created_at": "2021-11-05T14:24:07+08:00",
* }
* ]
* }
*/
func (*Config) Breakdown(c *gin.Context) {
form := &struct {
Title string `json:"title" form:"title"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := config.NewBreakdown()(getSession()(c).(*service.Session)).List(form.Title, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
func (*Config) BreakdownSelect(c *gin.Context) {
data, err := config.NewBreakdown()(getSession()(c).(*service.Session)).Select()
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/config/breakdown/add 故障信息添加
* @apiVersion 1.0.0
* @apiName ConfigBreakdownAdd
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} title 名称
* @apiParam {String} [remark="''"] 备注名称
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Config) BreakdownAdd(c *gin.Context) {
form := &struct {
Title string `json:"title" form:"title" binding:"required"`
Remark string `json:"remark" form:"remark"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := config.NewBreakdown()(getSession()(c).(*service.Session)).Form(0, form.Title, form.Remark)
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/config/breakdown/edit 故障信息修改
* @apiVersion 1.0.0
* @apiName ConfigBreakdownEdit
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} id ID
* @apiParam {String} title 名称
* @apiParam {String} [remark="''"] 备注名称
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Config) BreakdownEdit(c *gin.Context) {
form := &struct {
IDStringForm
Title string `json:"title" form:"title" binding:"required"`
Remark string `json:"remark" form:"remark"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := config.NewBreakdown()(getSession()(c).(*service.Session)).Form(form.Convert(), form.Title, form.Remark)
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/config/breakdown/delete 故障信息删除
* @apiVersion 1.0.0
* @apiName ConfigBreakdownDelete
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Config) BreakdownDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := config.NewBreakdown()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)(c)
}