// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package post

import (
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"sundynix-micro-go/app/plant/api/internal/logic/post"
	"sundynix-micro-go/app/plant/api/internal/svc"
	"sundynix-micro-go/app/plant/api/internal/types"
	"sundynix-micro-go/common/response"
)

// 发布帖子
func CreatePostHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.CreatePostReq
		if err := httpx.Parse(r, &req); err != nil {
			response.Fail(w, err.Error())
			return
		}

		l := post.NewCreatePostLogic(r.Context(), svcCtx)
		err := l.CreatePost(&req)
		if err != nil {
			response.Fail(w, err.Error())
		} else {
			response.Ok(w)
		}
	}
}
