go-bouquins/bouquins/bouquins.go

141 lines
2.0 KiB
Go

package bouquins
import (
"html/template"
"log"
"net/http"
)
const (
TPL_BOOKS = "books.html"
TPL_AUTHORS = "authors.html"
TPL_SERIES = "series.html"
TPL_INDEX = "index.html"
)
type Bouquins struct {
*template.Template
}
/*
* A book series.
*/
type Series struct {
Id int64
Name string
}
/*
* A book. Generic data.
*/
type Book struct {
Id int64
Title string
SeriesIndex int
Series *Series
}
/*
* An author.
*/
type Author struct {
Id int64
Name string
}
/*
* Author and number of books.
*/
type AuthorAdv struct {
Author
Count int
}
/*
* Downloadable book data.
*/
type BookData struct {
Size int64
Format string
Name string
}
/*
* A book. Advanced data: authors, tags.
*/
type BookAdv struct {
Book
Authors []*Author
Tags []string
}
type AuthorFull struct {
Author
Books []*BookAdv
}
type BookFull struct {
BookAdv
Data []BookData
Timestamp int64
Pubdate int64
Isbn string
Lccn string
Path string
Uuid string
Has_cover bool
Lang string
Publisher string
}
type SeriesAdv struct {
Series
Count int64
Authors []*Author
}
type SeriesFull struct {
SeriesAdv
Books []*Book
}
type IndexModel struct {
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,
nil,
series,
nil,
}
err := app.Template.ExecuteTemplate(res, TPL_INDEX, model)
if err != nil {
log.Print(err)
}
}
func (app *Bouquins) BooksPage(res http.ResponseWriter, req *http.Request) {
panic("not implemented")
}
func (app *Bouquins) AuthorsPage(res http.ResponseWriter, req *http.Request) {
panic("not implemented")
}
func (app *Bouquins) SeriesPage(res http.ResponseWriter, req *http.Request) {
panic("not implemented")
}