background/controller/hardware.go

75 lines
1.2 KiB
Go
Raw Normal View History

2020-03-21 03:17:24 +00:00
package controller
import (
2020-03-31 17:07:32 +00:00
"background/logs"
2020-03-25 02:57:25 +00:00
"background/model"
2020-08-23 18:08:26 +00:00
2020-03-21 03:17:24 +00:00
"github.com/gin-gonic/gin"
2020-03-25 02:57:25 +00:00
"qiniupkg.com/x/log.v7"
2020-03-21 03:17:24 +00:00
)
2020-06-20 15:15:23 +00:00
2020-08-23 18:08:26 +00:00
func AddHardware(c *gin.Context) {
resp := RespBase{"unkown error", -231, nil}
2020-03-21 03:17:24 +00:00
defer func() {
2020-08-23 18:08:26 +00:00
c.JSON(200, resp)
2020-03-21 03:17:24 +00:00
}()
2020-03-25 02:57:25 +00:00
var hardware model.Hardware
e := c.BindJSON(&hardware)
2020-08-23 18:08:26 +00:00
if nil != e {
2020-03-25 02:57:25 +00:00
log.Print(e)
print(e)
return
}
2020-08-23 18:08:26 +00:00
e = hardware.CreateHardware()
if nil != e {
2020-03-31 17:07:32 +00:00
resp.Status = -100
resp.Msg = e.Error()
log.Print(e)
2020-03-25 02:57:25 +00:00
return
}
2020-03-24 16:30:55 +00:00
resp.Data = nil
2020-03-21 03:17:24 +00:00
resp.Msg = "OK"
resp.Status = 0
2020-03-24 16:30:55 +00:00
}
2020-08-23 18:08:26 +00:00
func DeleteHardWare(c *gin.Context) {
resp := RespBase{"unkown error", -231, nil}
2020-03-31 17:07:32 +00:00
defer func() {
2020-08-23 18:08:26 +00:00
c.JSON(200, resp)
2020-03-31 17:07:32 +00:00
}()
name := c.Query("name")
2020-08-23 18:08:26 +00:00
if name == "" {
2020-03-31 17:07:32 +00:00
return
}
e := model.DeleteHardware(name)
2020-08-23 18:08:26 +00:00
if nil != e {
2020-03-31 17:07:32 +00:00
logs.Error(e.Error())
return
2020-03-31 17:07:32 +00:00
}
resp.Msg = "OK"
resp.Status = 0
resp.Data = nil
2020-03-24 16:30:55 +00:00
}
2020-08-23 18:08:26 +00:00
func UpdateHardWare(c *gin.Context) {
2020-03-24 16:30:55 +00:00
}
2020-08-23 18:08:26 +00:00
func ReadHardWare(c *gin.Context) {
rsp := RespBase{"ERR", -1, nil}
defer func() {
2020-08-23 18:08:26 +00:00
c.JSON(200, rsp)
}()
2020-03-27 16:00:46 +00:00
2020-08-23 18:08:26 +00:00
limit, offset := GetPageParaFromQuery(c)
log.Print(limit, offset)
hardware, e := model.GetHardwares(limit, offset)
if nil != e {
return
}
rsp.Data = hardware
rsp.Msg = "OK"
rsp.Status = 0
2020-03-24 16:30:55 +00:00
}