feat: post reshare enhancements

This commit is contained in:
Krispire Admin
2026-06-03 14:41:15 +05:30
parent 3f6b7b6636
commit 7f5b0fee11
9 changed files with 397 additions and 190 deletions
+7 -6
View File
@@ -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.