This commit is contained in:
@@ -93,30 +93,6 @@ func GetPost(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, dto)
|
||||
}
|
||||
|
||||
func PostAttachmentDownload(w http.ResponseWriter, r *http.Request) {
|
||||
pool := poolFrom(r)
|
||||
postID, err := uuid.Parse(chi.URLParam(r, "id"))
|
||||
if err != nil {
|
||||
http.Error(w, "bad id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
aid, err := uuid.Parse(chi.URLParam(r, "aid"))
|
||||
if err != nil {
|
||||
http.Error(w, "bad attachment id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
cmd, err := pool.Exec(r.Context(), `
|
||||
UPDATE posts SET download_count = download_count + 1, updated_at = NOW()
|
||||
WHERE id = $1 AND status = 'published' AND is_public = TRUE
|
||||
AND (published_at IS NULL OR published_at <= NOW())`, postID)
|
||||
if err != nil || cmd.RowsAffected() == 0 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
writeJSON(w, map[string]any{"ok": true})
|
||||
_ = aid
|
||||
}
|
||||
|
||||
func listPostsQuery(w http.ResponseWriter, r *http.Request, searchMode bool) {
|
||||
pool := poolFrom(r)
|
||||
limit := postLimitDef(r, 20, 50)
|
||||
|
||||
Reference in New Issue
Block a user