// CreateHandler Create a new post.
CreateHandler Create a new post.
// CreateHandler Create a new post .
func (pr *PostRouter) CreateHandler(w http.ResponseWriter, r *http.Request) {
	var p post.Post
	err := json.NewDecoder(r.Body).Decode(&p)
	if err != nil {
		response.HTTPError(w, r, http.StatusBadRequest, err.Error())
		return
	}
	defer r.Body.Close()
	ctx := r.Context()
	err = pr.Repository.Create(ctx, &p)
	if err != nil {
		response.HTTPError(w, r, http.StatusBadRequest, err.Error())
		return
	}
	w.Header().Add("Location", fmt.Sprintf("%s%d", r.URL.String(), p.ID))
	response.JSON(w, r, http.StatusCreated, response.Map{"post": p})
}
func ( pr * PostRouter ) CreateHandler ( w http . ResponseWriter , r * http . Request ) { var p post . Post err := json . NewDecoder ( r . Body ) . Decode ( & p ) if err != nil { response . HTTPError ( w , r , http . StatusBadRequest , err . Error ( ) ) return } defer r . Body . Close ( ) ctx := r . Context ( ) err = pr . Repository . Create ( ctx , & p ) if err != nil { response . HTTPError ( w , r , http . StatusBadRequest , err . Error ( ) ) return } w . Header ( ) . Add ( " " , fmt . Sprintf ( " " , r . URL . String ( ) , p . ID ) ) response . JSON ( w , r , http . StatusCreated , response . Map { " " : p } ) }
CreateHandler Create a new post.
CreateHandler Create a new post .