Split voting into clean read/write endpoints

Replaces the GET-mutates-state interactions route with a proper split:
- GET  /entry/{pid}/votes  reads the tally (public, read-only)
- POST /entry/{pid}/vote   casts/toggles the vote (auth, mode in body)

Shared voteTally/writeTally helpers back both handlers. Invalid mode now
returns 400. Frontend updated to read via GET and vote via POST.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 11:03:33 +02:00
parent be8dbb4902
commit 38da498754
4 changed files with 96 additions and 64 deletions
+2 -1
View File
@@ -28,7 +28,7 @@ func main() {
// --- Entries ---
r.Get("/entry/feed/{page}", handleFeed)
r.Get("/entry/{pid}/interactions/{mode}", handleInteractions)
r.Get("/entry/{pid}/votes", handleVotes)
// --- User (öffentlich) ---
r.Get("/u/{username}", handleUserPage)
@@ -37,6 +37,7 @@ func main() {
r.Group(func(r chi.Router) {
r.Use(requireAuth)
r.Post("/entry/create", handleCreateEntry)
r.Post("/entry/{pid}/vote", handleVote)
r.Get("/user/info", handleUserInfo)
r.Post("/user/delete", handleUserDelete)
})