first commit

This commit is contained in:
2024-10-02 00:57:17 +08:00
commit 6773f86bc5
312 changed files with 19169 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package userProduct
import (
"context"
"errors"
"tianyuan-api/apps/sentinel/client/userproduct"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AddUserProductLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddUserProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserProductLogic {
return &AddUserProductLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AddUserProductLogic) AddUserProduct(req *types.AddUserProductReq) error {
userId, ok := l.ctx.Value("userId").(int64)
if !ok {
return errors.New("无法获取 userId")
}
_, err := l.svcCtx.UserProductRpc.CreateUserProduct(l.ctx, &userproduct.CreateUserProductRequest{
UserId: userId,
ProductId: req.ProductId,
})
if err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,40 @@
package userProduct
import (
"context"
"errors"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteUserProductLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteUserProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserProductLogic {
return &DeleteUserProductLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteUserProductLogic) DeleteUserProduct(req *types.DeleteUserProductReq) error {
return errors.New("not implements")
// 未完善应加上判断是否该用户订阅后删除id也不是这个id暂不开放开放也没用
//_, ok := l.ctx.Value("userId").(int64)
//if !ok {
// return errors.New("无法获取 userId")
//}
//_, err := l.svcCtx.UserProductRpc.DeleteUserProduct(l.ctx, &userproduct.DeleteUserProductRequest{
// Id: req.Id,
//})
//if err != nil {
// return err
//}
//return nil
}

View File

@@ -0,0 +1,60 @@
package userProduct
import (
"context"
"errors"
"tianyuan-api/apps/sentinel/client/userproduct"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserProductListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetUserProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProductListLogic {
return &GetUserProductListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetUserProductListLogic) GetUserProductList(req *types.GetUserProductListReq) (resp *types.GetUserProductListResp, err error) {
userId, ok := l.ctx.Value("userId").(int64)
if !ok {
return nil, errors.New("无法获取 userId")
}
userProductPageListResp, err := l.svcCtx.UserProductRpc.GetUserProductPageList(l.ctx, &userproduct.UserProuctPageListRequest{
UserId: userId,
Page: req.Page,
PageSize: req.PageSize,
})
if err != nil {
return nil, err
}
var list []types.UserProductItem
for _, up := range userProductPageListResp.UserProducts {
list = append(list, types.UserProductItem{
Id: up.Id,
ProductId: up.ProductId,
ProductName: up.ProductName,
ProductPrice: up.ProductPrice,
ProductGroup: up.ProductGroup,
ProductCode: up.ProductCode,
ProductDescription: up.ProductDescription,
CreatedAt: up.CreatedAt,
UpdatedAt: up.UpdatedAt,
})
}
resp = &types.GetUserProductListResp{
Total: userProductPageListResp.Total,
List: list,
}
return resp, nil
}