background/controller/plan.go

90 lines
1.5 KiB
Go
Raw Normal View History

2021-02-16 06:05:21 +00:00
package controller
import (
"background/db"
"background/model"
"log"
"strconv"
"github.com/gin-gonic/gin"
)
type PlanController struct {
}
func (this *PlanController) GetPlan(c *gin.Context) {
}
func (this *PlanController) GetPlanDates(c *gin.Context) {
type Req struct {
Date string `json:"date"`
}
var req Req
resp := RespBase{
Msg: "ERROR",
Status: 23,
}
defer c.JSON(200, &resp)
e := c.BindJSON(&req)
if nil != e {
log.Print(e.Error())
return
}
plan := []model.Plan{}
e = db.GetOrm().Model(&plan).Where("date = ?", req.Date).Find(&plan).Error
if nil != e {
log.Print(e.Error())
}
resp.Status = 0
resp.Msg = "OK"
resp.Data = plan
return
}
func (this *PlanController) AddPlan(c *gin.Context) {
var req model.Plan
resp := RespBase{Msg: "r", Status: 0, Data: nil}
defer c.JSON(200, &resp)
e := c.BindJSON(&req)
if nil != e {
log.Print(e.Error())
return
}
e = db.GetOrm().Create(&req).Error
if nil != e {
log.Print(e.Error())
return
}
resp.Msg = "OK"
resp.Status = 0
}
func (this *PlanController) DelPlan(c *gin.Context) {
resp := RespBase{Msg: "r", Status: 0, Data: nil}
defer c.JSON(200, &resp)
var e error
iid := 0
id := c.Query("id")
if "" != id {
iid, e = strconv.Atoi(id)
if nil != e {
log.Print(e.Error())
return
}
} else {
return
}
plan := model.Plan{}
plan.ID = uint32(iid)
e = db.GetOrm().Delete(&plan).Error
if nil != e {
log.Print(e.Error())
return
}
resp.Msg = "OK"
resp.Status = 0
}