init: 1.0.0
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/svc"
|
||||
"github.com/perfect-panel/ppanel-server/internal/types"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/tool"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type QuerySubscribeListLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get subscribe list
|
||||
func NewQuerySubscribeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QuerySubscribeListLogic {
|
||||
return &QuerySubscribeListLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QuerySubscribeListLogic) QuerySubscribeList() (resp *types.QuerySubscribeListResponse, err error) {
|
||||
|
||||
data, err := l.svcCtx.SubscribeModel.QuerySubscribeList(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[QuerySubscribeListLogic] Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "QuerySubscribeList error: %v", err.Error())
|
||||
}
|
||||
resp = &types.QuerySubscribeListResponse{
|
||||
Total: int64(len(data)),
|
||||
}
|
||||
list := make([]types.Subscribe, len(data))
|
||||
for i, item := range data {
|
||||
var sub types.Subscribe
|
||||
tool.DeepCopy(&sub, item)
|
||||
if item.Discount != "" {
|
||||
var discount []types.SubscribeDiscount
|
||||
_ = json.Unmarshal([]byte(item.Discount), &discount)
|
||||
sub.Discount = discount
|
||||
list[i] = sub
|
||||
}
|
||||
list[i] = sub
|
||||
}
|
||||
resp.List = list
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user