133 lines
3.9 KiB
Go
133 lines
3.9 KiB
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"ifms/internal/mods/autocontrol/biz"
|
||
|
"ifms/internal/mods/autocontrol/schema"
|
||
|
"ifms/pkg/util"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
// 设备操作日志表
|
||
|
type DeviceControlLog struct {
|
||
|
DeviceControlLogBIZ *biz.DeviceControlLog
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceControlLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Query device control log list
|
||
|
// @Param current query int true "pagination index" default(1)
|
||
|
// @Param pageSize query int true "pagination size" default(10)
|
||
|
// @Success 200 {object} util.ResponseResult{data=[]schema.DeviceControlLog}
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-control-logs [get]
|
||
|
func (a *DeviceControlLog) Query(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
var params schema.DeviceControlLogQueryParam
|
||
|
if err := util.ParseQuery(c, ¶ms); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
result, err := a.DeviceControlLogBIZ.Query(ctx, params)
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResPage(c, result.Data, result.PageResult)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceControlLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Get device control log record by ID
|
||
|
// @Param id path string true "unique id"
|
||
|
// @Success 200 {object} util.ResponseResult{data=schema.DeviceControlLog}
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-control-logs/{id} [get]
|
||
|
func (a *DeviceControlLog) Get(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
item, err := a.DeviceControlLogBIZ.Get(ctx, c.Param("id"))
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResSuccess(c, item)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceControlLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Create device control log record
|
||
|
// @Param body body schema.DeviceControlLogForm true "Request body"
|
||
|
// @Success 200 {object} util.ResponseResult{data=schema.DeviceControlLog}
|
||
|
// @Failure 400 {object} util.ResponseResult
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-control-logs [post]
|
||
|
func (a *DeviceControlLog) Create(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
item := new(schema.DeviceControlLogForm)
|
||
|
if err := util.ParseJSON(c, item); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
} else if err := item.Validate(); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
result, err := a.DeviceControlLogBIZ.Create(ctx, item)
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResSuccess(c, result)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceControlLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Update device control log record by ID
|
||
|
// @Param id path string true "unique id"
|
||
|
// @Param body body schema.DeviceControlLogForm true "Request body"
|
||
|
// @Success 200 {object} util.ResponseResult
|
||
|
// @Failure 400 {object} util.ResponseResult
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-control-logs/{id} [put]
|
||
|
func (a *DeviceControlLog) Update(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
item := new(schema.DeviceControlLogForm)
|
||
|
if err := util.ParseJSON(c, item); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
} else if err := item.Validate(); err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := a.DeviceControlLogBIZ.Update(ctx, c.Param("id"), item)
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResOK(c)
|
||
|
}
|
||
|
|
||
|
// @Tags DeviceControlLogAPI
|
||
|
// @Security ApiKeyAuth
|
||
|
// @Summary Delete device control log record by ID
|
||
|
// @Param id path string true "unique id"
|
||
|
// @Success 200 {object} util.ResponseResult
|
||
|
// @Failure 401 {object} util.ResponseResult
|
||
|
// @Failure 500 {object} util.ResponseResult
|
||
|
// @Router /api/v1/autocontrol/device-control-logs/{id} [delete]
|
||
|
func (a *DeviceControlLog) Delete(c *gin.Context) {
|
||
|
ctx := c.Request.Context()
|
||
|
err := a.DeviceControlLogBIZ.Delete(ctx, c.Param("id"))
|
||
|
if err != nil {
|
||
|
util.ResError(c, err)
|
||
|
return
|
||
|
}
|
||
|
util.ResOK(c)
|
||
|
}
|