79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"errors"
|
||
|
"net/http"
|
||
|
"text/template"
|
||
|
|
||
|
"git.32bit.cafe/yequari/webring/internal/models"
|
||
|
)
|
||
|
|
||
|
func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||
|
if r.URL.Path != "/" {
|
||
|
http.NotFound(w, r)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
files := []string{
|
||
|
"./ui/html/base.tmpl.html",
|
||
|
"./ui/html/pages/home.tmpl.html",
|
||
|
}
|
||
|
|
||
|
ts, err := template.ParseFiles(files...)
|
||
|
if err != nil {
|
||
|
app.serverError(w, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err = ts.ExecuteTemplate(w, "base", nil)
|
||
|
if err != nil {
|
||
|
app.serverError(w, err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (app *application) webmasterView(w http.ResponseWriter, r *http.Request) {
|
||
|
id := models.WebmasterId(r.URL.Query().Get("id"))
|
||
|
|
||
|
webmaster, err := app.webmasters.Get(id)
|
||
|
if err != nil {
|
||
|
if errors.Is(err, models.ErrNoRecord) {
|
||
|
app.notFound(w)
|
||
|
} else {
|
||
|
app.serverError(w, err)
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
fmt.Fprintf(w, "%+v", webmaster)
|
||
|
}
|
||
|
|
||
|
func (app *application) webmasterCreate(w http.ResponseWriter, r *http.Request) {
|
||
|
}
|
||
|
|
||
|
func (app *application) siteEntryView(w http.ResponseWriter, r *http.Request) {
|
||
|
id := models.SiteId(r.URL.Query().Get("id"))
|
||
|
|
||
|
siteEntry, err := app.siteEntries.Get(id)
|
||
|
if err != nil {
|
||
|
if errors.Is(err, models.ErrNoRecord) {
|
||
|
app.notFound(w)
|
||
|
} else {
|
||
|
app.serverError(w, err)
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
fmt.Fprintf(w, "%+v", siteEntry)
|
||
|
}
|
||
|
|
||
|
func (app *application) siteEntryCreate(w http.ResponseWriter, r *http.Request) {
|
||
|
}
|
||
|
|
||
|
func (app *application) nextSiteEntry(w http.ResponseWriter, r *http.Request) {
|
||
|
}
|
||
|
|
||
|
func (app *application) prevSiteEntry(w http.ResponseWriter, r *http.Request) {
|
||
|
}
|
||
|
|