From 02300c69d86235d7095cd8b24e4d679ab9ae41d3 Mon Sep 17 00:00:00 2001 From: H3ALY Date: Fri, 4 Apr 2025 10:57:06 +0100 Subject: [PATCH] Fix Syndicate paths. --- handlers/syndicate.go | 16 +++++++----- handlers/syndicate_invites.go | 10 +++---- main.go | 15 ++++++----- templates/layout.html | 11 +++++++- templates/syndicate/create.html | 26 +++++++++++++++++++ .../{syndicates => syndicate}/index.html | 6 ++--- .../{syndicates => syndicate}/invite.html | 2 +- .../{syndicates => syndicate}/log_ticket.html | 2 +- .../{syndicates => syndicate}/tickets.html | 0 templates/{syndicates => syndicate}/view.html | 4 +-- 10 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 templates/syndicate/create.html rename templates/{syndicates => syndicate}/index.html (77%) rename templates/{syndicates => syndicate}/invite.html (83%) rename templates/{syndicates => syndicate}/log_ticket.html (90%) rename templates/{syndicates => syndicate}/tickets.html (100%) rename templates/{syndicates => syndicate}/view.html (76%) diff --git a/handlers/syndicate.go b/handlers/syndicate.go index 558811e..0584be5 100644 --- a/handlers/syndicate.go +++ b/handlers/syndicate.go @@ -3,6 +3,7 @@ package handlers import ( "database/sql" "fmt" + "log" "net/http" "synlotto-website/helpers" "synlotto-website/models" @@ -15,7 +16,7 @@ func CreateSyndicateHandler(db *sql.DB) http.HandlerFunc { case http.MethodGet: data := BuildTemplateData(db, w, r) context := helpers.TemplateContext(w, r, data) - tmpl := helpers.LoadTemplateFiles("create-syndicate.html", "templates/account/syndicates/create.html") + tmpl := helpers.LoadTemplateFiles("create-syndicate.html", "templates/syndicate/create.html") tmpl.ExecuteTemplate(w, "layout", context) case http.MethodPost: @@ -25,12 +26,13 @@ func CreateSyndicateHandler(db *sql.DB) http.HandlerFunc { userId, ok := helpers.GetCurrentUserID(r) if !ok || name == "" { helpers.SetFlash(w, r, "Invalid data submitted") - http.Redirect(w, r, "/account/syndicates/create", http.StatusSeeOther) + http.Redirect(w, r, "/syndicate/create", http.StatusSeeOther) return } _, err := storage.CreateSyndicate(db, userId, name, description) if err != nil { + log.Printf("❌ CreateSyndicate failed: %v", err) helpers.SetFlash(w, r, "Failed to create syndicate") } else { helpers.SetFlash(w, r, "Syndicate created successfully") @@ -59,7 +61,7 @@ func ListSyndicatesHandler(db *sql.DB) http.HandlerFunc { context["ManagedSyndicates"] = managed context["JoinedSyndicates"] = member - tmpl := helpers.LoadTemplateFiles("syndicates.html", "templates/account/syndicates/index.html") + tmpl := helpers.LoadTemplateFiles("syndicates.html", "templates/syndicate/index.html") tmpl.ExecuteTemplate(w, "layout", context) } } @@ -95,7 +97,7 @@ func ViewSyndicateHandler(db *sql.DB) http.HandlerFunc { context["Members"] = members context["IsManager"] = isManager - tmpl := helpers.LoadTemplateFiles("syndicate-view.html", "templates/syndicates/view.html") + tmpl := helpers.LoadTemplateFiles("syndicate-view.html", "templates/syndicate/view.html") tmpl.ExecuteTemplate(w, "layout", context) } } @@ -121,7 +123,7 @@ func SyndicateLogTicketHandler(db *sql.DB) http.HandlerFunc { context := helpers.TemplateContext(w, r, data) context["Syndicate"] = syndicate - tmpl := helpers.LoadTemplateFiles("syndicate-log-ticket.html", "templates/syndicates/log_ticket.html") + tmpl := helpers.LoadTemplateFiles("syndicate-log-ticket.html", "templates/syndicate/log_ticket.html") tmpl.ExecuteTemplate(w, "layout", context) case http.MethodPost: @@ -144,7 +146,7 @@ func SyndicateLogTicketHandler(db *sql.DB) http.HandlerFunc { helpers.SetFlash(w, r, "Ticket added for syndicate.") } - http.Redirect(w, r, fmt.Sprintf("/account/syndicates/view?id=%d", syndicateId), http.StatusSeeOther) + http.Redirect(w, r, fmt.Sprintf("/syndicate/view?id=%d", syndicateId), http.StatusSeeOther) default: helpers.RenderError(w, r, 405) @@ -179,7 +181,7 @@ func SyndicateTicketsHandler(db *sql.DB) http.HandlerFunc { context["SyndicateID"] = syndicateID context["Tickets"] = tickets - tmpl := helpers.LoadTemplateFiles("syndicate-tickets.html", "templates/syndicates/tickets.html") + tmpl := helpers.LoadTemplateFiles("syndicate-tickets.html", "templates/syndicate/tickets.html") tmpl.ExecuteTemplate(w, "layout", context) } } diff --git a/handlers/syndicate_invites.go b/handlers/syndicate_invites.go index 40bcbda..42f5f8e 100644 --- a/handlers/syndicate_invites.go +++ b/handlers/syndicate_invites.go @@ -23,7 +23,7 @@ func SyndicateInviteHandler(db *sql.DB) http.HandlerFunc { context := helpers.TemplateContext(w, r, data) context["SyndicateID"] = syndicateID - tmpl := helpers.LoadTemplateFiles("invite-syndicate.html", "templates/syndicates/invite.html") + tmpl := helpers.LoadTemplateFiles("invite-syndicate.html", "templates/syndicate/invite.html") err := tmpl.ExecuteTemplate(w, "layout", context) if err != nil { helpers.RenderError(w, r, 500) @@ -38,7 +38,7 @@ func SyndicateInviteHandler(db *sql.DB) http.HandlerFunc { } else { helpers.SetFlash(w, r, "Invite sent successfully.") } - http.Redirect(w, r, "/account/syndicates/view?id="+strconv.Itoa(syndicateID), http.StatusSeeOther) + http.Redirect(w, r, "/syndicate/view?id="+strconv.Itoa(syndicateID), http.StatusSeeOther) default: helpers.RenderError(w, r, http.StatusMethodNotAllowed) @@ -59,7 +59,7 @@ func ViewInvitesHandler(db *sql.DB) http.HandlerFunc { context := helpers.TemplateContext(w, r, data) context["Invites"] = invites - tmpl := helpers.LoadTemplateFiles("invites.html", "templates/syndicates/invites.html") + tmpl := helpers.LoadTemplateFiles("invites.html", "templates/syndicate/invites.html") tmpl.ExecuteTemplate(w, "layout", context) } } @@ -78,7 +78,7 @@ func AcceptInviteHandler(db *sql.DB) http.HandlerFunc { } else { helpers.SetFlash(w, r, "You have joined the syndicate") } - http.Redirect(w, r, "/account/syndicates", http.StatusSeeOther) + http.Redirect(w, r, "/syndicates", http.StatusSeeOther) } } @@ -86,6 +86,6 @@ func DeclineInviteHandler(db *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { inviteID := helpers.Atoi(r.URL.Query().Get("id")) _ = storage.UpdateInviteStatus(db, inviteID, "declined") - http.Redirect(w, r, "/account/syndicates/invites", http.StatusSeeOther) + http.Redirect(w, r, "/syndicate/invites", http.StatusSeeOther) } } diff --git a/main.go b/main.go index aac00aa..a1857bd 100644 --- a/main.go +++ b/main.go @@ -84,12 +84,13 @@ func setupResultRoutes(mux *http.ServeMux, db *sql.DB) { } func setupSyndicateRoutes(mux *http.ServeMux, db *sql.DB) { - mux.HandleFunc("/account/syndicates", middleware.Auth(true)(handlers.ListSyndicatesHandler(db))) - mux.HandleFunc("/account/syndicates/view", middleware.Auth(true)(handlers.ViewSyndicateHandler(db))) - mux.HandleFunc("/account/syndicates/tickets", middleware.Auth(true)(handlers.SyndicateTicketsHandler(db))) - mux.HandleFunc("/account/syndicates/tickets/new", middleware.Auth(true)(handlers.SyndicateLogTicketHandler(db))) - mux.HandleFunc("/account/syndicates/invites", middleware.Auth(true)(handlers.ViewInvitesHandler(db))) - mux.HandleFunc("/account/syndicates/invites/accept", middleware.Auth(true)(handlers.AcceptInviteHandler(db))) - mux.HandleFunc("/account/syndicates/invites/decline", middleware.Auth(true)(handlers.DeclineInviteHandler(db))) + mux.HandleFunc("/syndicate", middleware.Auth(true)(handlers.ListSyndicatesHandler(db))) + mux.HandleFunc("/syndicate/create", middleware.Auth(true)(handlers.CreateSyndicateHandler(db))) + mux.HandleFunc("/syndicate/view", middleware.Auth(true)(handlers.ViewSyndicateHandler(db))) + mux.HandleFunc("/syndicate/tickets", middleware.Auth(true)(handlers.SyndicateTicketsHandler(db))) + mux.HandleFunc("/syndicate/tickets/new", middleware.Auth(true)(handlers.SyndicateLogTicketHandler(db))) + mux.HandleFunc("/syndicate/invites", middleware.Auth(true)(handlers.ViewInvitesHandler(db))) + mux.HandleFunc("/syndicate/invites/accept", middleware.Auth(true)(handlers.AcceptInviteHandler(db))) + mux.HandleFunc("/syndicate/invites/decline", middleware.Auth(true)(handlers.DeclineInviteHandler(db))) } diff --git a/templates/layout.html b/templates/layout.html index a0cecd8..1d1641d 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -48,7 +48,16 @@ - + diff --git a/templates/syndicate/create.html b/templates/syndicate/create.html new file mode 100644 index 0000000..6e41ac0 --- /dev/null +++ b/templates/syndicate/create.html @@ -0,0 +1,26 @@ +{{ define "content" }} +
+

Create New Syndicate

+ + {{ if .Flash }} +
{{ .Flash }}
+ {{ end }} + +
+ {{ .CSRFField }} + +
+ + +
+ +
+ + +
+ + + Cancel +
+
+{{ end }} diff --git a/templates/syndicates/index.html b/templates/syndicate/index.html similarity index 77% rename from templates/syndicates/index.html rename to templates/syndicate/index.html index c55b1ae..e1d446a 100644 --- a/templates/syndicates/index.html +++ b/templates/syndicate/index.html @@ -11,7 +11,7 @@ {{ .Name }}
{{ .Description }} - Manage + Manage {{ end }} @@ -26,7 +26,7 @@ {{ .Name }}
{{ .Description }} - View + View {{ end }} @@ -36,6 +36,6 @@
You are not part of any syndicates yet.
{{ end }} - Create New Syndicate + Create New Syndicate {{ end }} diff --git a/templates/syndicates/invite.html b/templates/syndicate/invite.html similarity index 83% rename from templates/syndicates/invite.html rename to templates/syndicate/invite.html index 5adb463..9f3ba3b 100644 --- a/templates/syndicates/invite.html +++ b/templates/syndicate/invite.html @@ -12,7 +12,7 @@ - Cancel + Cancel {{ end }} diff --git a/templates/syndicates/log_ticket.html b/templates/syndicate/log_ticket.html similarity index 90% rename from templates/syndicates/log_ticket.html rename to templates/syndicate/log_ticket.html index 957ff73..3764636 100644 --- a/templates/syndicates/log_ticket.html +++ b/templates/syndicate/log_ticket.html @@ -28,7 +28,7 @@ {{ template "ballInputs" . }} - Cancel + Cancel {{ end }} diff --git a/templates/syndicates/tickets.html b/templates/syndicate/tickets.html similarity index 100% rename from templates/syndicates/tickets.html rename to templates/syndicate/tickets.html diff --git a/templates/syndicates/view.html b/templates/syndicate/view.html similarity index 76% rename from templates/syndicates/view.html rename to templates/syndicate/view.html index 7fa268e..6519351 100644 --- a/templates/syndicates/view.html +++ b/templates/syndicate/view.html @@ -20,9 +20,9 @@ Manager Controls
You can add or remove members, and manage tickets. - Invite Members + Invite Members {{ end }} - ← Back to Syndicates + ← Back to Syndicates {{ end }}