92 lines
1.7 KiB
Go
92 lines
1.7 KiB
Go
package app
|
|
|
|
import (
|
|
"Lee-WineList/api"
|
|
"Lee-WineList/core"
|
|
"Lee-WineList/model/entity"
|
|
"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 entity.Wine
|
|
|
|
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("添加成功")
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
var ue entity.User
|
|
if api.GetUser(ctx, &ue, false, true); ctx.IsAborted() {
|
|
return
|
|
}
|
|
|
|
if err := repository.Wine().Delete(&p, &ue); err != nil {
|
|
core.R(ctx).FailWithMessage(err.Error())
|
|
return
|
|
}
|
|
|
|
core.R(ctx).OkWithMessage("删除成功")
|
|
}
|