// UpdateHandler update a stored post by id.
UpdateHandler update a stored post by id.
// UpdateHandler update a stored post by id .
func (pr *PostRouter) UpdateHandler(w http.ResponseWriter, r *http.Request) {
	idStr := chi.URLParam(r, "id")
	id, err := strconv.Atoi(idStr)
	if err != nil {
		response.HTTPError(w, r, http.StatusBadRequest, err.Error())
		return
	}
	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.Update(ctx, uint(id), p)
	if err != nil {
		response.HTTPError(w, r, http.StatusNotFound, err.Error())
		return
	}
	response.JSON(w, r, http.StatusOK, nil)
}
func ( pr * PostRouter ) UpdateHandler ( w http . ResponseWriter , r * http . Request ) { idStr := chi . URLParam ( r , " " ) id , err := strconv . Atoi ( idStr ) if err != nil { response . HTTPError ( w , r , http . StatusBadRequest , err . Error ( ) ) return } 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 . Update ( ctx , uint ( id ) , p ) if err != nil { response . HTTPError ( w , r , http . StatusNotFound , err . Error ( ) ) return } response . JSON ( w , r , http . StatusOK , nil ) }
UpdateHandler update a stored post by id.
UpdateHandler update a stored post by id .