first commit
This commit is contained in:
42
apps/sentinel/internal/logic/product/createproductlogic.go
Normal file
42
apps/sentinel/internal/logic/product/createproductlogic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateProductLogic {
|
||||
return &CreateProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Product methods
|
||||
func (l *CreateProductLogic) CreateProduct(in *sentinel.CreateProductRequest) (*sentinel.Product, error) {
|
||||
_, err := l.svcCtx.ProductsModel.Insert(l.ctx, &model.Products{
|
||||
ProductName: in.ProductName,
|
||||
ProductCode: in.ProductCode,
|
||||
ProductDescription: sqlutil.StringToNullString(in.ProductDescription),
|
||||
ProductContent: sqlutil.StringToNullString(in.ProductContent),
|
||||
ProductGroup: in.ProductGroup,
|
||||
ProductPrice: in.ProductPrice,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
30
apps/sentinel/internal/logic/product/deleteproductlogic.go
Normal file
30
apps/sentinel/internal/logic/product/deleteproductlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteProductLogic {
|
||||
return &DeleteProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteProductLogic) DeleteProduct(in *sentinel.DeleteProductRequest) (*sentinel.Product, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
42
apps/sentinel/internal/logic/product/getproductbyidlogic.go
Normal file
42
apps/sentinel/internal/logic/product/getproductbyidlogic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductByIdLogic {
|
||||
return &GetProductByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductByIdLogic) GetProductById(in *sentinel.GetRecordByIdRequest) (*sentinel.Product, error) {
|
||||
product, err := l.svcCtx.ProductsModel.FindOne(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Product{
|
||||
Id: product.Id,
|
||||
ProductName: product.ProductName,
|
||||
ProductCode: product.ProductCode,
|
||||
ProductPrice: product.ProductPrice,
|
||||
ProductDescription: sqlutil.NullStringToString(product.ProductDescription),
|
||||
ProductContent: sqlutil.NullStringToString(product.ProductContent),
|
||||
ProductGroup: product.ProductGroup,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetProductPageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetProductPageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductPageListLogic {
|
||||
return &GetProductPageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetProductPageListLogic) GetProductPageList(in *sentinel.PageListRequest) (*sentinel.ProductResponse, error) {
|
||||
products, total, err := l.svcCtx.ProductsModel.FindProductsList(l.ctx, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []*sentinel.Product
|
||||
for _, p := range products {
|
||||
list = append(list, &sentinel.Product{
|
||||
Id: p.Id,
|
||||
ProductName: p.ProductName,
|
||||
ProductCode: p.ProductCode,
|
||||
ProductDescription: sqlutil.NullStringToString(p.ProductDescription),
|
||||
ProductGroup: p.ProductGroup,
|
||||
ProductPrice: p.ProductPrice,
|
||||
})
|
||||
}
|
||||
return &sentinel.ProductResponse{
|
||||
Total: total,
|
||||
Products: list,
|
||||
}, nil
|
||||
}
|
||||
30
apps/sentinel/internal/logic/product/updateproductlogic.go
Normal file
30
apps/sentinel/internal/logic/product/updateproductlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package productlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateProductLogic {
|
||||
return &UpdateProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateProductLogic) UpdateProduct(in *sentinel.UpdateProductRequest) (*sentinel.Product, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Product{}, nil
|
||||
}
|
||||
46
apps/sentinel/internal/logic/secret/createsecretlogic.go
Normal file
46
apps/sentinel/internal/logic/secret/createsecretlogic.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
"tianyuan-api/pkg/crypto"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateSecretLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateSecretLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSecretLogic {
|
||||
return &CreateSecretLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Secret methods
|
||||
func (l *CreateSecretLogic) CreateSecret(in *sentinel.CreateSecretRequest) (*sentinel.Secret, error) {
|
||||
secretId, err := crypto.GenerateSecretId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aesKey, err := crypto.GenerateSecretKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.SecretsModel.Insert(l.ctx, &model.Secrets{
|
||||
UserId: in.UserId,
|
||||
SecretId: secretId,
|
||||
AesKey: aesKey,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sentinel.Secret{}, nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetSecretBySecretIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetSecretBySecretIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSecretBySecretIdLogic {
|
||||
return &GetSecretBySecretIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSecretBySecretIdLogic) GetSecretBySecretId(in *sentinel.GetSecretBySecretIdRequest) (*sentinel.Secret, error) {
|
||||
secret, err := l.svcCtx.SecretsModel.FindOneBySecretId(l.ctx, in.SecretId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, err
|
||||
|
||||
}
|
||||
}
|
||||
return &sentinel.Secret{
|
||||
Id: secret.Id,
|
||||
UserId: secret.UserId,
|
||||
SecretId: secret.SecretId,
|
||||
AesKey: secret.AesKey,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package secretlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetSecretByUserIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetSecretByUserIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSecretByUserIdLogic {
|
||||
return &GetSecretByUserIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSecretByUserIdLogic) GetSecretByUserId(in *sentinel.GetRecordByIdRequest) (*sentinel.Secret, error) {
|
||||
secretModel, err := l.svcCtx.SecretsModel.FindOneByUserId(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
return nil, errors.New("请先进行企业认证")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Secret{
|
||||
SecretId: secretModel.SecretId,
|
||||
AesKey: secretModel.AesKey,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package userproductlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateUserProductLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateUserProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserProductLogic {
|
||||
return &CreateUserProductLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// UserProduct methods
|
||||
func (l *CreateUserProductLogic) CreateUserProduct(in *sentinel.CreateUserProductRequest) (*sentinel.UserProductEmptyResponse, error) {
|
||||
isExist, err := l.IsUserProductAssociated(l.ctx, in.UserId, in.ProductId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isExist {
|
||||
return nil, errors.New("该产品已定阅读,无法重复订阅")
|
||||
}
|
||||
_, err = l.svcCtx.UserProductsModel.Insert(l.ctx, &model.UserProducts{UserId: in.UserId, ProductId: in.ProductId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.UserProductEmptyResponse{}, nil
|
||||
}
|
||||
func (l *CreateUserProductLogic) IsUserProductAssociated(ctx context.Context, userId, productId int64) (bool, error) {
|
||||
_, err := l.svcCtx.UserProductsModel.FindOneUserProduct(ctx, userId, productId)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package userproductlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/client/product"
|
||||
"tianyuan-api/pkg/sqlutil"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetUserProductPageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetUserProductPageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserProductPageListLogic {
|
||||
return &GetUserProductPageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserProductPageListLogic) GetUserProductPageList(in *sentinel.UserProuctPageListRequest) (*sentinel.UserProductResponse, error) {
|
||||
list, total, err := l.svcCtx.UserProductsModel.FindUserProductsList(l.ctx, in.UserId, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var userProducts []*product.UserProductItem
|
||||
for _, up := range list {
|
||||
userProducts = append(userProducts, &product.UserProductItem{
|
||||
Id: up.Id,
|
||||
ProductId: up.ProductId,
|
||||
ProductName: up.ProductName,
|
||||
ProductPrice: up.ProductPrice,
|
||||
ProductGroup: up.ProductGroup,
|
||||
ProductDescription: sqlutil.NullStringToString(up.ProductDescription),
|
||||
ProductCode: up.ProductCode,
|
||||
CreatedAt: up.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: up.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return &sentinel.UserProductResponse{
|
||||
Total: total,
|
||||
UserProducts: userProducts,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package userproductlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type MatchingUserIdProductCodeLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewMatchingUserIdProductCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MatchingUserIdProductCodeLogic {
|
||||
return &MatchingUserIdProductCodeLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *MatchingUserIdProductCodeLogic) MatchingUserIdProductCode(in *sentinel.MatchingUserIdProductCodeRequest) (*sentinel.MatchResponse, error) {
|
||||
match, err := l.svcCtx.UserProductsModel.FindMatchUserProductCode(l.ctx, in.Id, in.ProductCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.MatchResponse{
|
||||
Match: match,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/model"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateWhitelistLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateWhitelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWhitelistLogic {
|
||||
return &CreateWhitelistLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// Whitelist methods
|
||||
func (l *CreateWhitelistLogic) CreateWhitelist(in *sentinel.CreateWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
white := model.Whitelist{
|
||||
UserId: in.UserId,
|
||||
WhitelistIp: in.WhitelistIp,
|
||||
}
|
||||
_, err := l.svcCtx.WhitelistModel.Insert(l.ctx, &white)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Whitelist{}, nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteWhitelistLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteWhitelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteWhitelistLogic {
|
||||
return &DeleteWhitelistLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteWhitelistLogic) DeleteWhitelist(in *sentinel.DeleteWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
err := l.svcCtx.WhitelistModel.Delete(l.ctx, in.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.Whitelist{}, nil
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWhitePageListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetWhitePageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitePageListLogic {
|
||||
return &GetWhitePageListLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWhitePageListLogic) GetWhitePageList(in *sentinel.WhitePageListRequest) (*sentinel.WhitelistResponse, error) {
|
||||
whitelists, total, err := l.svcCtx.WhitelistModel.FindWhitelistList(l.ctx, in.UserId, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var list []*sentinel.Whitelist
|
||||
for _, w := range whitelists {
|
||||
list = append(list, &sentinel.Whitelist{
|
||||
Id: w.Id,
|
||||
UserId: w.UserId,
|
||||
WhitelistIp: w.WhitelistIp,
|
||||
CreatedAt: w.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: w.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
return &sentinel.WhitelistResponse{
|
||||
Total: total,
|
||||
Whitelists: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type MatchWhitelistByIpLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewMatchWhitelistByIpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MatchWhitelistByIpLogic {
|
||||
return &MatchWhitelistByIpLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *MatchWhitelistByIpLogic) MatchWhitelistByIp(in *sentinel.MatchWhitelistByIpRequest) (*sentinel.MatchResponse, error) {
|
||||
isMatch, err := l.svcCtx.WhitelistModel.IsIpInWhitelist(l.ctx, in.Ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sentinel.MatchResponse{
|
||||
Match: isMatch,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package whitelistlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/svc"
|
||||
"tianyuan-api/apps/sentinel/sentinel"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateWhitelistLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateWhitelistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWhitelistLogic {
|
||||
return &UpdateWhitelistLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateWhitelistLogic) UpdateWhitelist(in *sentinel.UpdateWhitelistRequest) (*sentinel.Whitelist, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &sentinel.Whitelist{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user