go-crm improvements

This commit is contained in:
2026-05-01 15:43:13 -03:00
parent ee6673265f
commit 31247a63f6
17 changed files with 416 additions and 63 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"log"
"net/http"
"strings"
"go-crm/internal/db"
"go-crm/internal/handlers"
@@ -32,15 +31,14 @@ func main() {
templates.Init()
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
homeTmpl := templates.Get("home.html")
layoutTmpl := templates.Layout("Home", "")
if homeTmpl != nil && layoutTmpl != nil {
buf := &strings.Builder{}
homeTmpl.Execute(buf, map[string]string{"Title": "Home"})
layoutTmpl.Execute(w, map[string]string{"Title": "Home", "Content": buf.String()})
} else {
w.Write([]byte(`<!DOCTYPE html><html><head><title>Home</title></head><body><h1>Welcome to CRM</h1><nav><a href="/clients">Clients</a> | <a href="/customers">Customers</a> | <a href="/services">Services</a> | <a href="/questions">Questions</a> | <a href="/answers">Answers</a></nav></body></html>`))
_, err := handlers.GetAccountID(r)
if err != nil {
http.Redirect(w, r, "/auth/login", http.StatusFound)
return
}
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(`<!DOCTYPE html><html><head><title>Dashboard</title></head><body><h1>Welcome to CRM</h1><nav><a href="/clients">Clients</a> | <a href="/customers">Customers</a> | <a href="/services">Services</a> | <a href="/scheduling">Scheduling</a> | <a href="/payments">Payments</a> | <a href="/questions">Questions</a> | <a href="/answers">Answers</a> | <a href="/auth/account">Account</a> | <form method="POST" action="/auth/logout" style="display:inline"><button type="submit">Logout</button></form></nav></body></html>`))
})
r.Route("/auth", func(r chi.Router) {
@@ -49,6 +47,8 @@ func main() {
r.Get("/login", handlers.LoginPage)
r.Post("/login", handlers.Login)
r.Post("/logout", handlers.Logout)
r.Get("/account", handlers.AccountPage)
r.Post("/account", handlers.UpdateAccount)
})
r.Route("/clients", func(r chi.Router) {