diff --git a/bouquins/bouquins.go b/bouquins/bouquins.go index a2aaa94..3759bcc 100644 --- a/bouquins/bouquins.go +++ b/bouquins/bouquins.go @@ -99,42 +99,55 @@ type SeriesFull struct { Books []*Book } +type BouquinsModel struct { + Title string +} + +// Constructor BouquinsModel +func NewBouquinsModel(title string) *BouquinsModel { + return &BouquinsModel{ + title, + } +} + type IndexModel struct { + BouquinsModel BooksCount int64 Books []*BookAdv Series []*SeriesAdv Authors []*AuthorAdv } -func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) { - series := make([]*SeriesAdv, 0) - a1 := make([]*Author, 0) - s1 := &SeriesAdv{ - Series{ - 666, - "Serie 1", - }, - 12, - a1, - } - series = append(series, s1) - model := &IndexModel{ - 123, +// Constructor IndexModel +func NewIndexModel(title string, count int64) *IndexModel { + return &IndexModel{ + *NewBouquinsModel(title), + count, + nil, nil, - series, nil, } - err := app.Template.ExecuteTemplate(res, TPL_INDEX, model) +} + +// ROUTES // + +func (app *Bouquins) render(res http.ResponseWriter, tpl string, model interface{}) { + err := app.Template.ExecuteTemplate(res, tpl, model) if err != nil { log.Print(err) } } + +func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) { + model := NewIndexModel("", 123) + app.render(res, TPL_INDEX, model) +} func (app *Bouquins) BooksPage(res http.ResponseWriter, req *http.Request) { - panic("not implemented") + app.render(res, TPL_BOOKS, nil) } func (app *Bouquins) AuthorsPage(res http.ResponseWriter, req *http.Request) { - panic("not implemented") + app.render(res, TPL_AUTHORS, nil) } func (app *Bouquins) SeriesPage(res http.ResponseWriter, req *http.Request) { - panic("not implemented") + app.render(res, TPL_SERIES, nil) } diff --git a/main.go b/main.go index dc5c061..4af3c7f 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ const ( SERIES = "/series" JS = "/js/" CSS = "/css/" + FONTS = "/fonts/" ) func init() { @@ -22,11 +23,9 @@ func init() { if err != nil { log.Fatalln(err) } - app := &bouquins.Bouquins{ tpl, } - assets() router(app) } @@ -34,6 +33,7 @@ func init() { func assets() { http.Handle(JS, http.FileServer(http.Dir("assets"))) http.Handle(CSS, http.FileServer(http.Dir("assets"))) + http.Handle(FONTS, http.FileServer(http.Dir("assets"))) } func router(app *bouquins.Bouquins) { diff --git a/templates/author.html b/templates/author.html index 90a9264..6a1e96f 100644 --- a/templates/author.html +++ b/templates/author.html @@ -1,73 +1,43 @@ - - -
-