2017-07-30 14:06:38 +00:00
|
|
|
package bouquins
|
|
|
|
|
2017-07-30 15:20:48 +00:00
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TPL_BOOKS = "books.html"
|
|
|
|
TPL_AUTHORS = "authors.html"
|
|
|
|
TPL_SERIES = "series.html"
|
|
|
|
TPL_INDEX = "index.html"
|
|
|
|
)
|
2017-07-30 14:06:38 +00:00
|
|
|
|
|
|
|
type Bouquins struct {
|
2017-07-30 15:20:48 +00:00
|
|
|
*template.Template
|
2017-07-30 14:06:38 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 14:42:18 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2017-07-30 15:20:48 +00:00
|
|
|
Authors []*Author
|
2017-07-30 14:42:18 +00:00
|
|
|
Tags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type AuthorFull struct {
|
|
|
|
Author
|
2017-07-30 15:20:48 +00:00
|
|
|
Books []*BookAdv
|
2017-07-30 14:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-07-30 15:20:48 +00:00
|
|
|
Count int64
|
|
|
|
Authors []*Author
|
2017-07-30 14:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SeriesFull struct {
|
|
|
|
SeriesAdv
|
2017-07-30 15:20:48 +00:00
|
|
|
Books []*Book
|
|
|
|
}
|
|
|
|
|
|
|
|
type IndexModel struct {
|
|
|
|
BooksCount int64
|
|
|
|
Books []*BookAdv
|
|
|
|
Series []*SeriesAdv
|
|
|
|
Authors []*AuthorAdv
|
2017-07-30 14:42:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 15:20:48 +00:00
|
|
|
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)
|
|
|
|
}
|
2017-07-30 14:06:38 +00:00
|
|
|
}
|
2017-07-30 15:20:48 +00:00
|
|
|
func (app *Bouquins) BooksPage(res http.ResponseWriter, req *http.Request) {
|
2017-07-30 14:06:38 +00:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
2017-07-30 15:20:48 +00:00
|
|
|
func (app *Bouquins) AuthorsPage(res http.ResponseWriter, req *http.Request) {
|
2017-07-30 14:06:38 +00:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
2017-07-30 15:20:48 +00:00
|
|
|
func (app *Bouquins) SeriesPage(res http.ResponseWriter, req *http.Request) {
|
2017-07-30 14:06:38 +00:00
|
|
|
panic("not implemented")
|
|
|
|
}
|