travebing/backend/server/handle_plan.go

47 lines
945 B
Go

package server
import (
"strconv"
"github.com/gin-gonic/gin"
"pkg.bing89.com/travebing/controller/plan"
"pkg.bing89.com/travebing/http"
"pkg.bing89.com/travebing/tberror"
)
func (s *Server)HandlePlanList(c *gin.Context){
ret, code, err := s.ctrl.Plans().List()
if err != nil {
http.Error(c, code, err)
return
}
http.Success(c, ret)
}
func (s *Server)HandlePlanCreate(c *gin.Context){
opt := plan.CreateOption{}
if err := c.ShouldBind(&opt); err != nil {
http.Error(c, tberror.CodeBadRequest, err)
return
}
ret, code, err := s.ctrl.Plans().Create(opt)
if err != nil {
http.Error(c, code, err)
return
}
http.Success(c, ret)
}
func (s *Server)HandlePlanGet(c *gin.Context){
plan, err := strconv.Atoi(c.Param("plan"))
if err != nil {
http.Error(c, tberror.CodeBadRequest, err)
return
}
ret, code, err := s.ctrl.Plans().Get(plan)
if err != nil {
http.Error(c, code, err)
return
}
http.Success(c, ret)
}