createpostlogic.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package logic
  2. import (
  3. "context"
  4. "slow_wild_api/apps/internal/svc"
  5. "slow_wild_api/apps/internal/types"
  6. "git.banshen.xyz/huangguangrong/slow_wild_protobuff/slowwild/slowwildserver"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type CreatePostLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. // 创建帖子
  15. func NewCreatePostLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePostLogic {
  16. return &CreatePostLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *CreatePostLogic) CreatePost(req *types.CreatePostReq) (resp *types.BaseReturnData, err error) {
  23. resp = &types.BaseReturnData{}
  24. var tags []*slowwildserver.CreateTag
  25. if len(req.Tags) > 0 {
  26. for _, tag := range req.Tags {
  27. tags = append(tags, &slowwildserver.CreateTag{
  28. Id: tag.Id,
  29. Name: tag.Name,
  30. })
  31. }
  32. }
  33. rpcResp, err := l.svcCtx.SlowWildPb.CreatePost(l.ctx, &slowwildserver.CreatePostReq{
  34. Title: req.Title,
  35. Content: req.Content,
  36. Tags: tags,
  37. AtUserIds: req.AtUserIds,
  38. Type: req.PostType,
  39. Visibility: req.Visibility,
  40. Images: req.Images,
  41. VideoCover: req.VideoCover,
  42. VideoUrl: req.VideoUrl,
  43. Ip: req.Ip,
  44. IpLoc: req.IpLoc,
  45. })
  46. if err != nil {
  47. return nil, err
  48. }
  49. resp.Data = rpcResp
  50. return
  51. }