Index: query sort/order

This commit is contained in:
Meutel 2017-07-31 20:14:57 +02:00
parent e171731d62
commit d992c30346
2 changed files with 25 additions and 1 deletions

View File

@ -12,6 +12,14 @@ const (
TPL_AUTHORS = "author.html"
TPL_SERIES = "series.html"
TPL_INDEX = "index.html"
PARAM_LIST = "list"
PARAM_ORDER = "order"
PARAM_SORT = "sort"
LIST_AUTHORS = "authors"
LIST_SERIES = "series"
LIST_BOOKS = "books"
)
type Bouquins struct {
@ -146,7 +154,17 @@ func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) {
log.Print(err)
}
model := NewIndexModel("", count)
model.Books, err = app.BooksAdv(0, 0, "", "")
order, sort := req.URL.Query().Get(PARAM_ORDER), req.URL.Query().Get(PARAM_SORT)
switch req.URL.Query().Get(PARAM_LIST) {
case LIST_AUTHORS:
model.Authors, err = app.AuthorsAdv(0, 0, sort, order)
case LIST_SERIES:
model.Series, err = app.SeriesAdv(0, 0, sort, order)
case LIST_BOOKS:
fallthrough
default:
model.Books, err = app.BooksAdv(0, 0, sort, order)
}
if err != nil {
log.Print(err)
}

View File

@ -196,6 +196,12 @@ func (app *Bouquins) BookCount() (int64, error) {
err := row.Scan(&count)
return count, err
}
func (app *Bouquins) SeriesAdv(limit, offset int, sort, order string) ([]*SeriesAdv, error) {
panic("not implemented")
}
func (app *Bouquins) AuthorsAdv(limit, offset int, sort, order string) ([]*AuthorAdv, error) {
panic("not implemented")
}
func (app *Bouquins) BooksAdv(limit, offset int, sort, order string) ([]*BookAdv, error) {
if limit == 0 {