fix
This commit is contained in:
parent
311ad581cc
commit
147af8ae29
@ -86,3 +86,6 @@ func (c *FsCartModel) Create(ctx context.Context, data FsCart) error {
|
|||||||
func (c *FsCartModel) Update(ctx context.Context, id int64, data FsCart) error {
|
func (c *FsCartModel) Update(ctx context.Context, id int64, data FsCart) error {
|
||||||
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).Updates(data).Error
|
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).Updates(data).Error
|
||||||
}
|
}
|
||||||
|
func (c *FsCartModel) UpdateByIdUserId(ctx context.Context, id int64, userId int64, data FsCart) error {
|
||||||
|
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ? and `user_id` = ?", id, userId).Updates(data).Error
|
||||||
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
// 解析jwtToken
|
||||||
/*claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
@ -40,7 +40,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
var req types.CartAddReq
|
var req types.CartAddReq
|
||||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
@ -53,7 +53,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
// 创建一个业务逻辑层实例
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewCartAddLogic(r.Context(), svcCtx)
|
l := logic.NewCartAddLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartAdd(&req, &auth.UserInfo{83})
|
resp := l.CartAdd(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
|
@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/cart/add",
|
Path: "/cart/add",
|
||||||
Handler: CartAddHandler(serverCtx),
|
Handler: CartAddHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/cart/del",
|
||||||
|
Handler: CartDeleteHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -122,5 +122,5 @@ func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) (
|
|||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to add to cart")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to add to cart")
|
||||||
}
|
}
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatusWithMessage(basic.CodeOK, "add to cart success")
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,10 @@ type CartAddReq struct {
|
|||||||
IsCheck int64 `json:"is_check,optional"`
|
IsCheck int64 `json:"is_check,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CartDeleteReq struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"msg"`
|
Message string `json:"msg"`
|
||||||
|
@ -11,6 +11,9 @@ service shopping-cart-confirmation {
|
|||||||
//添加入购物车
|
//添加入购物车
|
||||||
@handler CartAddHandler
|
@handler CartAddHandler
|
||||||
post /cart/add (CartAddReq) returns (response);
|
post /cart/add (CartAddReq) returns (response);
|
||||||
|
//删除购物车
|
||||||
|
@handler CartDeleteHandler
|
||||||
|
post /cart/del (CartDeleteReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加入购物车
|
//添加入购物车
|
||||||
@ -19,3 +22,7 @@ type CartAddReq {
|
|||||||
BuyNum int64 `json:"buy_num"` //购买数量
|
BuyNum int64 `json:"buy_num"` //购买数量
|
||||||
IsCheck int64 `json:"is_check,optional"`
|
IsCheck int64 `json:"is_check,optional"`
|
||||||
}
|
}
|
||||||
|
//删除购物车
|
||||||
|
type CartDeleteReq {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user