From f2847024481c5b595ba9225c372b6dd4e29bb9ab Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 11:05:59 +0800 Subject: [PATCH] 11 --- .../modifycartpurchasequantityhandler.go | 35 ---------- .../shopping-cart/internal/handler/routes.go | 5 -- .../logic/modifycartpurchasequantitylogic.go | 69 ------------------- server/shopping-cart/internal/types/types.go | 5 -- server_api/shopping-cart.api | 9 +-- 5 files changed, 1 insertion(+), 122 deletions(-) delete mode 100644 server/shopping-cart/internal/handler/modifycartpurchasequantityhandler.go delete mode 100644 server/shopping-cart/internal/logic/modifycartpurchasequantitylogic.go diff --git a/server/shopping-cart/internal/handler/modifycartpurchasequantityhandler.go b/server/shopping-cart/internal/handler/modifycartpurchasequantityhandler.go deleted file mode 100644 index b04427bf..00000000 --- a/server/shopping-cart/internal/handler/modifycartpurchasequantityhandler.go +++ /dev/null @@ -1,35 +0,0 @@ -package handler - -import ( - "net/http" - "reflect" - - "fusenapi/utils/basic" - - "fusenapi/server/shopping-cart/internal/logic" - "fusenapi/server/shopping-cart/internal/svc" - "fusenapi/server/shopping-cart/internal/types" -) - -func ModifyCartPurchaseQuantityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - - var req types.ModifyCartPurchaseQuantityReq - userinfo, err := basic.RequestParse(w, r, svcCtx, &req) - if err != nil { - return - } - - // 创建一个业务逻辑层实例 - l := logic.NewModifyCartPurchaseQuantityLogic(r.Context(), svcCtx) - - rl := reflect.ValueOf(l) - basic.BeforeLogic(w, r, rl) - - resp := l.ModifyCartPurchaseQuantity(&req, userinfo) - - if !basic.AfterLogic(w, r, rl, resp) { - basic.NormalAfterLogic(w, r, resp) - } - } -} diff --git a/server/shopping-cart/internal/handler/routes.go b/server/shopping-cart/internal/handler/routes.go index 3a4188d6..14f2c2d3 100644 --- a/server/shopping-cart/internal/handler/routes.go +++ b/server/shopping-cart/internal/handler/routes.go @@ -22,11 +22,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/shopping-cart/delete", Handler: DeleteCartHandler(serverCtx), }, - { - Method: http.MethodPost, - Path: "/api/shopping-cart/modify", - Handler: ModifyCartPurchaseQuantityHandler(serverCtx), - }, { Method: http.MethodGet, Path: "/api/shopping-cart/get_carts", diff --git a/server/shopping-cart/internal/logic/modifycartpurchasequantitylogic.go b/server/shopping-cart/internal/logic/modifycartpurchasequantitylogic.go deleted file mode 100644 index b78dd2e8..00000000 --- a/server/shopping-cart/internal/logic/modifycartpurchasequantitylogic.go +++ /dev/null @@ -1,69 +0,0 @@ -package logic - -import ( - "errors" - "fusenapi/model/gmodel" - "fusenapi/utils/auth" - "fusenapi/utils/basic" - "gorm.io/gorm" - - "context" - - "fusenapi/server/shopping-cart/internal/svc" - "fusenapi/server/shopping-cart/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type ModifyCartPurchaseQuantityLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewModifyCartPurchaseQuantityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModifyCartPurchaseQuantityLogic { - return &ModifyCartPurchaseQuantityLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 处理进入前逻辑w,r -// func (l *ModifyCartPurchaseQuantityLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { -// } - -func (l *ModifyCartPurchaseQuantityLogic) ModifyCartPurchaseQuantity(req *types.ModifyCartPurchaseQuantityReq, userinfo *auth.UserInfo) (resp *basic.Response) { - if !userinfo.IsUser() { - return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in") - } - if req.Id <= 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "cart id is required") - } - if req.PurchaseQuantity <= 0 { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "purchase quantity can not less than 0 or equal to 0") - } - //查询购物车 - _, err := l.svcCtx.AllModels.FsShoppingCart.FineOneUserCart(l.ctx, req.Id, userinfo.UserId, "id") - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the shopping cart is not exists") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get shopping cart info ") - } - //修改数量 - err = l.svcCtx.AllModels.FsShoppingCart.Update(l.ctx, req.Id, userinfo.UserId, &gmodel.FsShoppingCart{ - PurchaseQuantity: &req.PurchaseQuantity, - }) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to modify cart purchase quantity") - } - return resp.SetStatus(basic.CodeOK, "success") -} - -// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *ModifyCartPurchaseQuantityLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { -// // httpx.OkJsonCtx(r.Context(), w, resp) -// } diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index 65041e67..a1eb5ab2 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -29,11 +29,6 @@ type DeleteCartReq struct { Id int64 `json:"id"` //购物车id } -type ModifyCartPurchaseQuantityReq struct { - Id int64 `json:"id"` //购物车id - PurchaseQuantity int64 `json:"purchase_quantity"` //数量 -} - type GetCartsReq struct { CurrentPage int `form:"current_page"` //当前页 } diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 0c076fa2..bb347743 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -15,9 +15,6 @@ service shopping-cart { //删除购物车 @handler DeleteCartHandler post /api/shopping-cart/delete(DeleteCartReq) returns (response); - //修改购物车购买数量 - @handler ModifyCartPurchaseQuantityHandler - post /api/shopping-cart/modify(ModifyCartPurchaseQuantityReq) returns (response); //获取购物车列表 @handler GetCartsHandler get /api/shopping-cart/get_carts(GetCartsReq) returns (response); @@ -49,11 +46,7 @@ type DiyInfo { type DeleteCartReq { Id int64 `json:"id"` //购物车id } -//修改购物车购买数量 -type ModifyCartPurchaseQuantityReq { - Id int64 `json:"id"` //购物车id - PurchaseQuantity int64 `json:"purchase_quantity"` //数量 -} + //获取购物车列表 type GetCartsReq { CurrentPage int `form:"current_page"` //当前页