init
This commit is contained in:
@@ -7,6 +7,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// handleGetActiveSession behandelt GET /api/v1/sessions/active.
|
||||
// Gibt die offene Session des Nutzers mit den Übungen des zugehörigen Sets zurück,
|
||||
// oder null wenn keine Session aktiv ist.
|
||||
func (h *Handler) handleGetActiveSession(w http.ResponseWriter, r *http.Request) {
|
||||
uid, err := userID(r)
|
||||
if err != nil {
|
||||
@@ -37,6 +40,8 @@ func (h *Handler) handleGetActiveSession(w http.ResponseWriter, r *http.Request)
|
||||
})
|
||||
}
|
||||
|
||||
// handleCreateSession behandelt POST /api/v1/sessions.
|
||||
// Gibt 409 zurück wenn bereits eine offene Session existiert.
|
||||
func (h *Handler) handleCreateSession(w http.ResponseWriter, r *http.Request) {
|
||||
uid, err := userID(r)
|
||||
if err != nil {
|
||||
@@ -70,6 +75,8 @@ func (h *Handler) handleCreateSession(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusCreated, session)
|
||||
}
|
||||
|
||||
// handleListSessions behandelt GET /api/v1/sessions.
|
||||
// Unterstützt Query-Parameter: limit (Standard: 20) und offset (Standard: 0).
|
||||
func (h *Handler) handleListSessions(w http.ResponseWriter, r *http.Request) {
|
||||
uid, err := userID(r)
|
||||
if err != nil {
|
||||
@@ -87,6 +94,7 @@ func (h *Handler) handleListSessions(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, sessions)
|
||||
}
|
||||
|
||||
// handleGetSession behandelt GET /api/v1/sessions/{id}.
|
||||
func (h *Handler) handleGetSession(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
@@ -106,6 +114,8 @@ func (h *Handler) handleGetSession(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, session)
|
||||
}
|
||||
|
||||
// handleEndSession behandelt PUT /api/v1/sessions/{id}/end.
|
||||
// Beendet eine offene Session und speichert optional eine Notiz.
|
||||
func (h *Handler) handleEndSession(w http.ResponseWriter, r *http.Request) {
|
||||
uid, err := userID(r)
|
||||
if err != nil {
|
||||
@@ -167,6 +177,9 @@ func (h *Handler) handleDeleteSession(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// handleCreateLog behandelt POST /api/v1/sessions/{id}/logs.
|
||||
// Fügt einen Satz zu einer offenen Session hinzu.
|
||||
// Gibt 409 zurück bei doppelter (exercise_id, set_number)-Kombination.
|
||||
func (h *Handler) handleCreateLog(w http.ResponseWriter, r *http.Request) {
|
||||
sessionID, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
@@ -204,6 +217,8 @@ func (h *Handler) handleCreateLog(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusCreated, log)
|
||||
}
|
||||
|
||||
// handleUpdateLog behandelt PUT /api/v1/sessions/{id}/logs/{logId}.
|
||||
// Alle Felder im Request sind optional (Partial Update).
|
||||
func (h *Handler) handleUpdateLog(w http.ResponseWriter, r *http.Request) {
|
||||
sessionID, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
@@ -242,6 +257,7 @@ func (h *Handler) handleUpdateLog(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, log)
|
||||
}
|
||||
|
||||
// handleDeleteLog behandelt DELETE /api/v1/sessions/{id}/logs/{logId}.
|
||||
func (h *Handler) handleDeleteLog(w http.ResponseWriter, r *http.Request) {
|
||||
sessionID, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user