-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1601201
commit afc6f39
Showing
21 changed files
with
684 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,166 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
"takeout/common" | ||
"takeout/common/e" | ||
"takeout/global" | ||
"takeout/internal/api/user/request" | ||
"takeout/internal/model" | ||
"takeout/internal/service" | ||
) | ||
|
||
type ShoppingCartController struct { | ||
service service.IShoppingCartService | ||
} | ||
|
||
func NewShoppingController(service service.IShoppingCartService) *ShoppingCartController { | ||
return &ShoppingCartController{service: service} | ||
} | ||
|
||
// AddShoppingCart @AddShoppingCart 添加购物车 | ||
// @Tags ShoppingCart | ||
// @Security JWTAuth | ||
// @Produce json | ||
// @Param model body model.ShoppingCartDTO true "菜品属性" | ||
// @Success 200 {object} common.Result{} "success" | ||
// @Failure 400 {object} common.Result "Invalid request payload" | ||
// @Failure 500 {object} common.Result "Internal Server Faliure" | ||
// @Router /user/shoppingCart/add [post] | ||
func (s *ShoppingCartController) AddShoppingCart(ctx *gin.Context) { | ||
var ( | ||
code = e.SUCCESS | ||
dto request.ShoppingCartDTO | ||
err error | ||
) | ||
|
||
if err = ctx.ShouldBindJSON(&dto); err != nil { | ||
global.Log.Debug("C端-购物车接口 AddShoppingCart param error:", err.Error()) | ||
ctx.JSON(http.StatusBadRequest, common.Result{}) | ||
return | ||
} | ||
|
||
if err = s.service.AddShoppingCart(ctx, dto); err != nil { | ||
code = e.ERROR | ||
global.Log.Debug("AddShoppingCart error:", err.Error()) | ||
ctx.JSON(http.StatusInternalServerError, common.Result{ | ||
Code: code, | ||
Msg: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, common.Result{ | ||
Code: code, | ||
Msg: e.GetMsg(code), | ||
}) | ||
|
||
} | ||
|
||
// QueryShoppingCart @QueryShoppingCart 查看购物车 | ||
// @Tags ShoppingCart | ||
// @Security JWTAuth | ||
// @Produce json | ||
// @Success 200 {object} common.Result{Data=[]model.ShoppingCart} "success" | ||
// @Failure 400 {object} common.Result "Invalid request payload" | ||
// @Failure 500 {object} common.Result "Internal Server Faliure" | ||
// @Router /user/shoppingCart/list [get] | ||
func (s *ShoppingCartController) QueryShoppingCart(ctx *gin.Context) { | ||
var ( | ||
code = e.SUCCESS | ||
data []model.ShoppingCart | ||
err error | ||
) | ||
|
||
if data, err = s.service.QueryShoppingCart(ctx); err != nil { | ||
code = e.ERROR | ||
global.Log.Debug("AddShoppingCart error:", err.Error()) | ||
ctx.JSON(http.StatusInternalServerError, common.Result{ | ||
Code: code, | ||
Msg: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, common.Result{ | ||
Code: code, | ||
Data: data, | ||
Msg: e.GetMsg(code), | ||
}) | ||
} | ||
|
||
// CleanShoppingCart @CleanShoppingCart 添加购物车 | ||
// @Tags ShoppingCart | ||
// @Security JWTAuth | ||
// @Produce json | ||
// @Success 200 {object} common.Result{} "success" | ||
// @Failure 400 {object} common.Result "Invalid request payload" | ||
// @Failure 500 {object} common.Result "Internal Server Faliure" | ||
// @Router /user/shoppingCart/clean [delete] | ||
func (s *ShoppingCartController) CleanShoppingCart(ctx *gin.Context) { | ||
var ( | ||
code = e.SUCCESS | ||
dto request.ShoppingCartDTO | ||
err error | ||
) | ||
|
||
if err = ctx.ShouldBindJSON(&dto); err != nil { | ||
global.Log.Debug("C端-购物车接口 AddShoppingCart param error:", err.Error()) | ||
ctx.JSON(http.StatusBadRequest, common.Result{}) | ||
return | ||
} | ||
|
||
if err = s.service.CleanShoppingCart(ctx); err != nil { | ||
code = e.ERROR | ||
global.Log.Debug("AddShoppingCart error:", err.Error()) | ||
ctx.JSON(http.StatusInternalServerError, common.Result{ | ||
Code: code, | ||
Msg: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, common.Result{ | ||
Code: code, | ||
Msg: e.GetMsg(code), | ||
}) | ||
} | ||
|
||
// SubShoppingCart @SubShoppingCart 删除购物车中一个商品 | ||
// @Tags ShoppingCart | ||
// @Security JWTAuth | ||
// @Produce json | ||
// @Param dto body request.ShoppingCartDTO true "菜品属性" | ||
// @Success 200 {object} common.Result{Data=response.DishListVo} "success" | ||
// @Failure 400 {object} common.Result "Invalid request payload" | ||
// @Failure 500 {object} common.Result "Internal Server Faliure" | ||
// @Router /user/shoppingCart/sub [post] | ||
func (s *ShoppingCartController) SubShoppingCart(ctx *gin.Context) { | ||
var ( | ||
code = e.SUCCESS | ||
dto request.ShoppingCartDTO | ||
err error | ||
) | ||
|
||
if err = ctx.ShouldBindJSON(&dto); err != nil { | ||
global.Log.Debug("C端-购物车接口 AddShoppingCart param error:", err.Error()) | ||
ctx.JSON(http.StatusBadRequest, common.Result{}) | ||
return | ||
} | ||
|
||
if err = s.service.SubShoppingCart(ctx, dto); err != nil { | ||
code = e.ERROR | ||
global.Log.Debug("AddShoppingCart error:", err.Error()) | ||
ctx.JSON(http.StatusInternalServerError, common.Result{ | ||
Code: code, | ||
Msg: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, common.Result{ | ||
Code: code, | ||
Msg: e.GetMsg(code), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package request | ||
|
||
// ShoppingCartDTO 添加购物车传输数据模型 | ||
type ShoppingCartDTO struct { | ||
DishId int `json:"dishId"` | ||
SetmealId int `json:"setmealId"` | ||
DishFlavor string `json:"dishFlavor"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
// ShoppingCart 购物车数据模型 | ||
type ShoppingCart struct { | ||
Id int `json:"id" gorm:"primary_key;AUTO_INCREMENT"` | ||
Name string `json:"name"` | ||
Image string `json:"image"` | ||
UserId int `json:"userId"` | ||
DishId int `json:"dishId"` | ||
SetmealId int `json:"setmealId"` | ||
DishFlavor string `json:"dishFlavor"` | ||
Number int `json:"number"` | ||
Amount float64 `json:"amount"` | ||
CreateTime time.Time `json:"createTime" gorm:"autoCreateTime"` | ||
} | ||
|
||
// TableName 指定表名 | ||
func (ShoppingCart) TableName() string { | ||
return "shopping_cart" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.