// Code scaffolded by goctl. Safe to edit. // goctl 1.10.1 package post import ( "context" "fmt" "sundynix-micro-go/app/plant/api/internal/svc" "sundynix-micro-go/app/plant/api/internal/types" "sundynix-micro-go/app/plant/rpc/plant" "github.com/zeromicro/go-zero/core/logx" ) type CreatePostLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } // 发布帖子 func NewCreatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePostLogic { return &CreatePostLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) error { userId := fmt.Sprintf("%v", l.ctx.Value("userId")) imgIds := req.ImgIds if len(imgIds) == 0 && len(req.OssIds) > 0 { imgIds = req.OssIds } _, err := l.svcCtx.PlantRpc.CreatePost(l.ctx, &plant.CreatePostReq{ UserId: userId, Title: req.Title, Content: req.Content, Location: req.Location, ImgIds: imgIds, TopicId: req.TopicId, }) return err }