order address apis
This commit is contained in:
@@ -2,6 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/validator"
|
||||
"strconv"
|
||||
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/svc"
|
||||
@@ -24,8 +30,39 @@ func NewWebCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCartLo
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WebCartLogic) WebCart(in *order.EmptyRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
func (l *WebCartLogic) WebCart(in *order.CartRequest) (*order.Response, error) {
|
||||
var v validator.CartValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
var info dao.CartInfo
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"type": strconv.Itoa(int(in.Type)),
|
||||
},
|
||||
}
|
||||
switch in.Type {
|
||||
case dao.CartTypeSale:
|
||||
w.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
case dao.CartTypeUser:
|
||||
w.Eq["user_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
case dao.CartTypeStore:
|
||||
w.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
||||
}
|
||||
|
||||
return &order.Response{}, nil
|
||||
err := model.CartModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
return l.ok(info)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user