2023-04-27 15:56:12 +08:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"Lee-WineList/core"
|
2023-04-27 17:36:07 +08:00
|
|
|
"Lee-WineList/model/entity"
|
2023-04-27 15:56:12 +08:00
|
|
|
"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) {
|
2023-04-27 17:36:07 +08:00
|
|
|
var p entity.Wine
|
2023-04-27 15:56:12 +08:00
|
|
|
|
|
|
|
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("添加成功")
|
|
|
|
}
|
2023-04-27 17:36:07 +08:00
|
|
|
|
|
|
|
// Update 更新酒单
|
|
|
|
func (w *wineApi) Update(ctx *gin.Context) {
|
|
|
|
var p entity.Wine
|
|
|
|
|
|
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
|
|
core.R(ctx).FailWithMessage(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := repository.Wine().Update(p); err != nil {
|
|
|
|
core.R(ctx).FailWithMessage(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
core.R(ctx).OkWithMessage("更新成功")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete 删除酒单
|
|
|
|
func (w *wineApi) Delete(ctx *gin.Context) {
|
|
|
|
var p entity.Wine
|
|
|
|
|
|
|
|
if err := ctx.ShouldBind(&p); err != nil {
|
|
|
|
core.R(ctx).FailWithMessage(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := repository.Wine().Delete(p); err != nil {
|
|
|
|
core.R(ctx).FailWithMessage(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
core.R(ctx).OkWithMessage("删除成功")
|
|
|
|
}
|