blog_backend_api/controller/hardware.go

73 lines
1.2 KiB
Go

package controller
import (
"background/logs"
"background/model"
"github.com/gin-gonic/gin"
"qiniupkg.com/x/log.v7"
)
func AddHardware(c *gin.Context) {
resp := RespBase{"unkown error",-231,nil}
defer func() {
c.JSON(200,resp)
}()
var hardware model.Hardware
e := c.BindJSON(&hardware)
if nil != e{
log.Print(e)
print(e)
return
}
e = hardware.CreateHardware()
if nil != e{
resp.Status = -100
resp.Msg = e.Error()
log.Print(e)
return
}
resp.Data = nil
resp.Msg = "OK"
resp.Status = 0
}
func DeleteHardWare(c *gin.Context) {
resp := RespBase{"unkown error",-231,nil}
defer func() {
c.JSON(200,resp)
}()
name := c.Query("name")
if name == ""{
return
}
e := model.DeleteHardware(name)
if nil != e{
logs.Error(e.Error())
return
}
resp.Msg = "OK"
resp.Status = 0
resp.Data = nil
}
func UpdateHardWare(c *gin.Context) {
}
func ReadHardWare(c *gin.Context) {
rsp := RespBase{"ERR",-1,nil}
defer func() {
c.JSON(200,rsp)
}()
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
}