Merge branch 'main' into feat/member-management

This commit is contained in:
juancwu 2026-02-08 00:21:09 +00:00
commit 5c9804d967
4 changed files with 72 additions and 6 deletions

View file

@ -3,6 +3,7 @@ package handler
import (
"log/slog"
"net/http"
"strings"
"git.juancwu.dev/juancwu/budgit/internal/ctxkeys"
"git.juancwu.dev/juancwu/budgit/internal/service"
@ -43,3 +44,23 @@ func (h *dashboardHandler) DashboardPage(w http.ResponseWriter, r *http.Request)
ui.Render(w, r, pages.Dashboard(spaces, totalBalance))
}
func (h *dashboardHandler) CreateSpace(w http.ResponseWriter, r *http.Request) {
user := ctxkeys.User(r.Context())
name := strings.TrimSpace(r.FormValue("name"))
if name == "" {
http.Error(w, "Space name is required", http.StatusBadRequest)
return
}
space, err := h.spaceService.CreateSpace(name, user.ID)
if err != nil {
slog.Error("failed to create space", "error", err, "user_id", user.ID)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
w.Header().Set("HX-Redirect", "/app/spaces/"+space.ID)
w.WriteHeader(http.StatusOK)
}