init: 1.0.0
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/model/subscribe"
|
||||
"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 GetSubscribeGroupListLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get subscribe group list
|
||||
func NewGetSubscribeGroupListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeGroupListLogic {
|
||||
return &GetSubscribeGroupListLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetSubscribeGroupListLogic) GetSubscribeGroupList() (resp *types.GetSubscribeGroupListResponse, err error) {
|
||||
var list []*subscribe.Group
|
||||
var total int64
|
||||
err = l.svcCtx.DB.Model(&subscribe.Group{}).Count(&total).Find(&list).Error
|
||||
if err != nil {
|
||||
l.Logger.Error("[GetSubscribeGroupListLogic] get subscribe group list failed: ", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get subscribe group list failed: %v", err.Error())
|
||||
}
|
||||
groupList := make([]types.SubscribeGroup, 0)
|
||||
tool.DeepCopy(&groupList, list)
|
||||
return &types.GetSubscribeGroupListResponse{
|
||||
Total: total,
|
||||
List: groupList,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user