Bearbeiten: POST /entry/{pid}/edit (Inhalt ändern)
- handleEditEntry: Eigentümerprüfung, nicht-leer, content-only Update - Bild und last_activity bleiben unverändert; gelöschte Posts nicht editierbar - Frontend: Bearbeiten-Button + Inline-Formular auf der Focus-Seite Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -264,6 +264,43 @@ func handleCreateEntry(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// handleEditEntry ändert den Inhalt eines eigenen Beitrags. Das angehängte Bild
|
||||
// bleibt unverändert; last_activity wird nicht angefasst (eine Korrektur soll den
|
||||
// Thread nicht nach oben spülen).
|
||||
func handleEditEntry(w http.ResponseWriter, r *http.Request) {
|
||||
pid, err := strconv.ParseInt(chi.URLParam(r, "pid"), 10, 64)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, "Ungültige pid")
|
||||
return
|
||||
}
|
||||
uid := uidFromContext(r.Context())
|
||||
|
||||
var owner int64
|
||||
if err := db.QueryRow(`SELECT uid FROM entry WHERE pid = ?`, pid).Scan(&owner); err != nil {
|
||||
writeError(w, http.StatusNotFound, "Beitrag nicht gefunden")
|
||||
return
|
||||
}
|
||||
if owner != uid {
|
||||
writeError(w, http.StatusForbidden, "Das ist nicht dein Beitrag.")
|
||||
return
|
||||
}
|
||||
|
||||
content := strings.TrimSpace(r.FormValue("content"))
|
||||
if content == "" {
|
||||
writeError(w, http.StatusBadRequest, "Inhalt darf nicht leer sein.")
|
||||
return
|
||||
}
|
||||
if len(content) > 1000 {
|
||||
content = content[:1000]
|
||||
}
|
||||
|
||||
if _, err := db.Exec(`UPDATE entry SET content = ? WHERE pid = ?`, content, pid); err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "Bearbeiten fehlgeschlagen")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"pid": pid, "content": content})
|
||||
}
|
||||
|
||||
// handleDeleteEntry löscht einen eigenen Beitrag "weich": die Zeile bleibt als
|
||||
// [deleted]-Platzhalter erhalten (damit Antworten nicht verwaisen), Inhalt, Bild
|
||||
// und Autor werden entfernt.
|
||||
|
||||
Reference in New Issue
Block a user