feat: post reshare enhancements
This commit is contained in:
@@ -59,18 +59,19 @@ func (h *PostHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
response.JSON(w, http.StatusCreated, p)
|
||||
}
|
||||
|
||||
// Reshare records the caller as having reshared the post identified
|
||||
// by {id}. Idempotent. Returns 204 on success; conflict for the
|
||||
// "reshare your own post" case surfaces as 400 via mapSocialErr's
|
||||
// fallthrough (errors.New wrapper in the service).
|
||||
// Reshare materialises a reshare of the post identified by {id} as a
|
||||
// new posts row owned by the caller. Idempotent — second call returns
|
||||
// the same row (still 201). The body is the new (or existing) post so
|
||||
// the frontend can drop it into its local feed without a refetch.
|
||||
func (h *PostHandler) Reshare(w http.ResponseWriter, r *http.Request) {
|
||||
uid := middleware.UserID(r.Context())
|
||||
id := chi.URLParam(r, "id")
|
||||
if err := h.svc.Reshare(r.Context(), id, uid); err != nil {
|
||||
p, err := h.svc.Reshare(r.Context(), id, uid)
|
||||
if err != nil {
|
||||
mapSocialErr(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
response.JSON(w, http.StatusCreated, p)
|
||||
}
|
||||
|
||||
// Unreshare removes a previously recorded reshare. Idempotent.
|
||||
|
||||
Reference in New Issue
Block a user