46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/factory/internal/dao"
|
|
"lone-services/services/factory/internal/model"
|
|
|
|
"lone-services/rpc/factory/pb"
|
|
"lone-services/services/factory/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type PostNamesLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewPostNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostNamesLogic {
|
|
return &PostNamesLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *PostNamesLogic) PostNames(in *factory.EmptyRequest) (*factory.Response, error) {
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
w := modelbase.Params{Eq: map[string]string{"status": utils.StringStatusOk}}
|
|
var names []dao.PostName
|
|
err := model.PostModel{}.Init().Items(w, &names)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
return l.ok(names)
|
|
}
|