51 lines
894 B
Go
51 lines
894 B
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
"Lee-WineList/core"
|
||
|
"Lee-WineList/model/param"
|
||
|
"Lee-WineList/repository"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
type wineApi struct {
|
||
|
}
|
||
|
|
||
|
func WineApi() *wineApi {
|
||
|
return &wineApi{}
|
||
|
}
|
||
|
|
||
|
// GetList 获取酒品列表
|
||
|
func (w *wineApi) GetList(ctx *gin.Context) {
|
||
|
var p param.GetWineList
|
||
|
|
||
|
if err := ctx.ShouldBind(&p); err != nil {
|
||
|
core.R(ctx).FailWithMessage(err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
wines, err := repository.Wine().GetWineList(p)
|
||
|
if err != nil {
|
||
|
core.R(ctx).FailWithMessage(err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
core.R(ctx).OkWithData(wines)
|
||
|
}
|
||
|
|
||
|
// Add 添加酒单
|
||
|
func (w *wineApi) Add(ctx *gin.Context) {
|
||
|
var p param.AddWine
|
||
|
|
||
|
if err := ctx.ShouldBind(&p); err != nil {
|
||
|
core.R(ctx).FailWithMessage(err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if err := repository.Wine().Add(p); err != nil {
|
||
|
core.R(ctx).FailWithMessage(err.Error())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
core.R(ctx).OkWithMessage("添加成功")
|
||
|
}
|