Fix Syndicate paths.

This commit is contained in:
2025-04-04 10:57:06 +01:00
parent 22fbf59157
commit 02300c69d8
10 changed files with 65 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ package handlers
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"log"
"net/http" "net/http"
"synlotto-website/helpers" "synlotto-website/helpers"
"synlotto-website/models" "synlotto-website/models"
@@ -15,7 +16,7 @@ func CreateSyndicateHandler(db *sql.DB) http.HandlerFunc {
case http.MethodGet: case http.MethodGet:
data := BuildTemplateData(db, w, r) data := BuildTemplateData(db, w, r)
context := helpers.TemplateContext(w, r, data) 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) tmpl.ExecuteTemplate(w, "layout", context)
case http.MethodPost: case http.MethodPost:
@@ -25,12 +26,13 @@ func CreateSyndicateHandler(db *sql.DB) http.HandlerFunc {
userId, ok := helpers.GetCurrentUserID(r) userId, ok := helpers.GetCurrentUserID(r)
if !ok || name == "" { if !ok || name == "" {
helpers.SetFlash(w, r, "Invalid data submitted") 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 return
} }
_, err := storage.CreateSyndicate(db, userId, name, description) _, err := storage.CreateSyndicate(db, userId, name, description)
if err != nil { if err != nil {
log.Printf("❌ CreateSyndicate failed: %v", err)
helpers.SetFlash(w, r, "Failed to create syndicate") helpers.SetFlash(w, r, "Failed to create syndicate")
} else { } else {
helpers.SetFlash(w, r, "Syndicate created successfully") helpers.SetFlash(w, r, "Syndicate created successfully")
@@ -59,7 +61,7 @@ func ListSyndicatesHandler(db *sql.DB) http.HandlerFunc {
context["ManagedSyndicates"] = managed context["ManagedSyndicates"] = managed
context["JoinedSyndicates"] = member 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) tmpl.ExecuteTemplate(w, "layout", context)
} }
} }
@@ -95,7 +97,7 @@ func ViewSyndicateHandler(db *sql.DB) http.HandlerFunc {
context["Members"] = members context["Members"] = members
context["IsManager"] = isManager 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) tmpl.ExecuteTemplate(w, "layout", context)
} }
} }
@@ -121,7 +123,7 @@ func SyndicateLogTicketHandler(db *sql.DB) http.HandlerFunc {
context := helpers.TemplateContext(w, r, data) context := helpers.TemplateContext(w, r, data)
context["Syndicate"] = syndicate 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) tmpl.ExecuteTemplate(w, "layout", context)
case http.MethodPost: case http.MethodPost:
@@ -144,7 +146,7 @@ func SyndicateLogTicketHandler(db *sql.DB) http.HandlerFunc {
helpers.SetFlash(w, r, "Ticket added for syndicate.") 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: default:
helpers.RenderError(w, r, 405) helpers.RenderError(w, r, 405)
@@ -179,7 +181,7 @@ func SyndicateTicketsHandler(db *sql.DB) http.HandlerFunc {
context["SyndicateID"] = syndicateID context["SyndicateID"] = syndicateID
context["Tickets"] = tickets 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) tmpl.ExecuteTemplate(w, "layout", context)
} }
} }

View File

@@ -23,7 +23,7 @@ func SyndicateInviteHandler(db *sql.DB) http.HandlerFunc {
context := helpers.TemplateContext(w, r, data) context := helpers.TemplateContext(w, r, data)
context["SyndicateID"] = syndicateID 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) err := tmpl.ExecuteTemplate(w, "layout", context)
if err != nil { if err != nil {
helpers.RenderError(w, r, 500) helpers.RenderError(w, r, 500)
@@ -38,7 +38,7 @@ func SyndicateInviteHandler(db *sql.DB) http.HandlerFunc {
} else { } else {
helpers.SetFlash(w, r, "Invite sent successfully.") 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: default:
helpers.RenderError(w, r, http.StatusMethodNotAllowed) helpers.RenderError(w, r, http.StatusMethodNotAllowed)
@@ -59,7 +59,7 @@ func ViewInvitesHandler(db *sql.DB) http.HandlerFunc {
context := helpers.TemplateContext(w, r, data) context := helpers.TemplateContext(w, r, data)
context["Invites"] = invites 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) tmpl.ExecuteTemplate(w, "layout", context)
} }
} }
@@ -78,7 +78,7 @@ func AcceptInviteHandler(db *sql.DB) http.HandlerFunc {
} else { } else {
helpers.SetFlash(w, r, "You have joined the syndicate") 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) { return func(w http.ResponseWriter, r *http.Request) {
inviteID := helpers.Atoi(r.URL.Query().Get("id")) inviteID := helpers.Atoi(r.URL.Query().Get("id"))
_ = storage.UpdateInviteStatus(db, inviteID, "declined") _ = storage.UpdateInviteStatus(db, inviteID, "declined")
http.Redirect(w, r, "/account/syndicates/invites", http.StatusSeeOther) http.Redirect(w, r, "/syndicate/invites", http.StatusSeeOther)
} }
} }

15
main.go
View File

@@ -84,12 +84,13 @@ func setupResultRoutes(mux *http.ServeMux, db *sql.DB) {
} }
func setupSyndicateRoutes(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("/syndicate", middleware.Auth(true)(handlers.ListSyndicatesHandler(db)))
mux.HandleFunc("/account/syndicates/view", middleware.Auth(true)(handlers.ViewSyndicateHandler(db))) mux.HandleFunc("/syndicate/create", middleware.Auth(true)(handlers.CreateSyndicateHandler(db)))
mux.HandleFunc("/account/syndicates/tickets", middleware.Auth(true)(handlers.SyndicateTicketsHandler(db))) mux.HandleFunc("/syndicate/view", middleware.Auth(true)(handlers.ViewSyndicateHandler(db)))
mux.HandleFunc("/account/syndicates/tickets/new", middleware.Auth(true)(handlers.SyndicateLogTicketHandler(db))) mux.HandleFunc("/syndicate/tickets", middleware.Auth(true)(handlers.SyndicateTicketsHandler(db)))
mux.HandleFunc("/account/syndicates/invites", middleware.Auth(true)(handlers.ViewInvitesHandler(db))) mux.HandleFunc("/syndicate/tickets/new", middleware.Auth(true)(handlers.SyndicateLogTicketHandler(db)))
mux.HandleFunc("/account/syndicates/invites/accept", middleware.Auth(true)(handlers.AcceptInviteHandler(db))) mux.HandleFunc("/syndicate/invites", middleware.Auth(true)(handlers.ViewInvitesHandler(db)))
mux.HandleFunc("/account/syndicates/invites/decline", middleware.Auth(true)(handlers.DeclineInviteHandler(db))) mux.HandleFunc("/syndicate/invites/accept", middleware.Auth(true)(handlers.AcceptInviteHandler(db)))
mux.HandleFunc("/syndicate/invites/decline", middleware.Auth(true)(handlers.DeclineInviteHandler(db)))
} }

View File

@@ -48,7 +48,16 @@
</ul> </ul>
</div> </div>
</li> </li>
<li class="nav-item"><strong class="nav-link">Syndicate</strong></li> <li class="nav-item">
<a class="nav-link d-flex justify-content-between align-items-center" data-bs-toggle="collapse" href="#syndicateSubmenu" role="button" aria-expanded="false" aria-controls="syndicateSubmenu">
<strong>Syndicate</strong>
</a>
<div class="collapse ps-3" id="syndicateSubmenu">
<ul class="nav flex-column">
<li class="nav-item"><a class="nav-link" href="/syndicate/create">Create new Syndicate</a></li>
</ul>
</div>
</li>
</ul> </ul>
</div> </div>
</nav> </nav>

View File

@@ -0,0 +1,26 @@
{{ define "content" }}
<div class="container py-5">
<h2>Create New Syndicate</h2>
{{ if .Flash }}
<div class="alert alert-info">{{ .Flash }}</div>
{{ end }}
<form method="POST">
{{ .CSRFField }}
<div class="mb-3">
<label class="form-label">Syndicate Name</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Description (optional)</label>
<textarea name="description" class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-primary">Create</button>
<a href="/syndicates" class="btn btn-secondary">Cancel</a>
</form>
</div>
{{ end }}

View File

@@ -11,7 +11,7 @@
<strong>{{ .Name }}</strong><br> <strong>{{ .Name }}</strong><br>
<small class="text-muted">{{ .Description }}</small> <small class="text-muted">{{ .Description }}</small>
</div> </div>
<a href="/account/syndicates/view?id={{ .ID }}" class="btn btn-outline-primary btn-sm">Manage</a> <a href="/syndicate/view?id={{ .ID }}" class="btn btn-outline-primary btn-sm">Manage</a>
</li> </li>
{{ end }} {{ end }}
</ul> </ul>
@@ -26,7 +26,7 @@
<strong>{{ .Name }}</strong><br> <strong>{{ .Name }}</strong><br>
<small class="text-muted">{{ .Description }}</small> <small class="text-muted">{{ .Description }}</small>
</div> </div>
<a href="/account/syndicates/view?id={{ .ID }}" class="btn btn-outline-secondary btn-sm">View</a> <a href="/syndicate/view?id={{ .ID }}" class="btn btn-outline-secondary btn-sm">View</a>
</li> </li>
{{ end }} {{ end }}
</ul> </ul>
@@ -36,6 +36,6 @@
<div class="alert alert-info">You are not part of any syndicates yet.</div> <div class="alert alert-info">You are not part of any syndicates yet.</div>
{{ end }} {{ end }}
<a href="/account/syndicates/create" class="btn btn-primary mt-3">Create New Syndicate</a> <a href="/syndicate/create" class="btn btn-primary mt-3">Create New Syndicate</a>
</div> </div>
{{ end }} {{ end }}

View File

@@ -12,7 +12,7 @@
<input type="text" class="form-control" id="username" name="username" required> <input type="text" class="form-control" id="username" name="username" required>
</div> </div>
<button type="submit" class="btn btn-primary">Send Invite</button> <button type="submit" class="btn btn-primary">Send Invite</button>
<a href="/account/syndicates/view?id={{ .Syndicate.ID }}" class="btn btn-secondary ms-2">Cancel</a> <a href="/syndicate/view?id={{ .Syndicate.ID }}" class="btn btn-secondary ms-2">Cancel</a>
</form> </form>
</div> </div>
{{ end }} {{ end }}

View File

@@ -28,7 +28,7 @@
{{ template "ballInputs" . }} {{ template "ballInputs" . }}
<button type="submit" class="btn btn-success">Submit Ticket</button> <button type="submit" class="btn btn-success">Submit Ticket</button>
<a href="/account/syndicates/view?id={{ .Syndicate.ID }}" class="btn btn-secondary ms-2">Cancel</a> <a href="/syndicate/view?id={{ .Syndicate.ID }}" class="btn btn-secondary ms-2">Cancel</a>
</form> </form>
</div> </div>
{{ end }} {{ end }}

View File

@@ -20,9 +20,9 @@
<strong>Manager Controls</strong><br> <strong>Manager Controls</strong><br>
You can add or remove members, and manage tickets. You can add or remove members, and manage tickets.
</div> </div>
<a href="/account/syndicates/invite?id={{ .Syndicate.ID }}" class="btn btn-outline-primary">Invite Members</a> <a href="/syndicate/invite?id={{ .Syndicate.ID }}" class="btn btn-outline-primary">Invite Members</a>
{{ end }} {{ end }}
<a href="/account/syndicates" class="btn btn-secondary mt-3">← Back to Syndicates</a> <a href="/syndicate" class="btn btn-secondary mt-3">← Back to Syndicates</a>
</div> </div>
{{ end }} {{ end }}