createposthandler.go 703 B

123456789101112131415161718192021222324252627
  1. package handler
  2. import (
  3. "net/http"
  4. "slow_wild_api/apps/internal/logic"
  5. "slow_wild_api/apps/internal/response"
  6. "slow_wild_api/apps/internal/svc"
  7. "slow_wild_api/apps/internal/types"
  8. "slow_wild_api/apps/internal/utils"
  9. "github.com/zeromicro/go-zero/rest/httpx"
  10. )
  11. // 创建帖子
  12. func createPostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13. return func(w http.ResponseWriter, r *http.Request) {
  14. var req types.CreatePostReq
  15. if err := httpx.Parse(r, &req); err != nil {
  16. httpx.ErrorCtx(r.Context(), w, err)
  17. return
  18. }
  19. ip := utils.GetRealIP(r)
  20. l := logic.NewCreatePostLogic(r.Context(), svcCtx)
  21. resp, err := l.CreatePost(&req, ip, "")
  22. response.Response(w, resp, err)
  23. }
  24. }