| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package logic
- import (
- "context"
- "slow_wild_api/apps/internal/svc"
- "slow_wild_api/apps/internal/types"
- "git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
- "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, ip, ipLoc string) (resp *types.BaseReturnData, err error) {
- resp = &types.BaseReturnData{}
- var tags []*slowwildserver.CreateTag
- if len(req.Tags) > 0 {
- for _, tag := range req.Tags {
- tags = append(tags, &slowwildserver.CreateTag{
- Id: tag.Id,
- Name: tag.Name,
- })
- }
- }
- rpcResp, err := l.svcCtx.SlowWildPb.CreatePost(l.ctx, &slowwildserver.CreatePostReq{
- Title: req.Title,
- Content: req.Content,
- Tags: tags,
- AtUserIds: req.AtUserIds,
- Type: req.PostType,
- Visibility: req.Visibility,
- Images: req.Images,
- VideoCover: req.VideoCover,
- VideoUrl: req.VideoUrl,
- Ip: ip,
- IpLoc: ipLoc,
- })
- if err != nil {
- return nil, err
- }
- resp.Data = rpcResp
- return
- }
|