From ceae84f1ae0ce2f23a70aa23b899e135384332f6 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sat, 10 Feb 2024 19:39:51 +0000 Subject: Implements Latest() organisation model method And puts the list in plain text on the home page. --- cmd/web/handlers.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'cmd') diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 1f3a58f..b0e83ac 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -39,22 +39,32 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) { return } - files := []string{ - "./ui/html/base.tmpl.html", - "./ui/html/pages/home.tmpl.html", - "./ui/html/partials/nav.tmpl.html", - } - - ts, err := template.ParseFiles(files...) + organisations, err := app.organisations.Latest() if err != nil { - app.serverError(w, r, err) // Use the serverError() helper + app.serverError(w, r, err) return } - err = ts.ExecuteTemplate(w, "base", nil) - if err != nil { - app.serverError(w, r, err) // Use the serverError() helper + for _, organisation := range organisations { + fmt.Fprintf(w, "%+v\n", organisation) } + + // files := []string{ + // "./ui/html/base.tmpl.html", + // "./ui/html/pages/home.tmpl.html", + // "./ui/html/partials/nav.tmpl.html", + // } + // + // ts, err := template.ParseFiles(files...) + // if err != nil { + // app.serverError(w, r, err) // Use the serverError() helper + // return + // } + // + // err = ts.ExecuteTemplate(w, "base", nil) + // if err != nil { + // app.serverError(w, r, err) // Use the serverError() helper + // } } func (app *application) organisationView(w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3