Rename author to authors and subject to tags
This commit is contained in:
parent
e72de38725
commit
7f9c172853
17 changed files with 37 additions and 39 deletions
10
lib/admin.go
10
lib/admin.go
|
@ -69,8 +69,8 @@ func editHandler(h handler) {
|
|||
data.Book = book
|
||||
data.S = GetStatus(h)
|
||||
author := ""
|
||||
if len(book.Author) > 0 {
|
||||
author = " by " + book.Author[0]
|
||||
if len(book.Authors) > 0 {
|
||||
author = " by " + book.Authors[0]
|
||||
}
|
||||
data.S.Title = book.Title + author + " -- Edit -- " + data.S.Title
|
||||
h.template.load(h, "edit", data)
|
||||
|
@ -98,7 +98,7 @@ func saveHandler(h handler) {
|
|||
date := h.r.FormValue("date")
|
||||
description := h.r.FormValue("description")
|
||||
author := cleanEmptyStr(h.r.Form["author"])
|
||||
subject := cleanEmptyStr(strings.Split(h.r.FormValue("subject"), ","))
|
||||
tags := cleanEmptyStr(strings.Split(h.r.FormValue("tags"), ","))
|
||||
isbn := parser.ISBN(h.r.FormValue("isbn")) // XXX: check for errors
|
||||
lang := cleanEmptyStr(h.r.Form["lang"])
|
||||
book := map[string]interface{}{"title": title,
|
||||
|
@ -106,7 +106,7 @@ func saveHandler(h handler) {
|
|||
"date": date,
|
||||
"description": description,
|
||||
"author": author,
|
||||
"subject": subject,
|
||||
"tags": tags,
|
||||
"isbn": isbn,
|
||||
"lang": lang}
|
||||
err := h.db.UpdateBook(id, book)
|
||||
|
@ -174,7 +174,7 @@ func newHandler(h handler) {
|
|||
for i, b := range res {
|
||||
data.Books[i].B = b
|
||||
_, data.Books[i].TitleFound, _ = h.db.GetBooks("title:"+b.Title, 1, 0)
|
||||
_, data.Books[i].AuthorFound, _ = h.db.GetBooks("author:"+strings.Join(b.Author, " author:"), 1, 0)
|
||||
_, data.Books[i].AuthorFound, _ = h.db.GetBooks("author:"+strings.Join(b.Authors, " author:"), 1, 0)
|
||||
}
|
||||
data.Page = page + 1
|
||||
if num > (page+1)*newItemsPage {
|
||||
|
|
|
@ -5,15 +5,14 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// TODO: Author -> Authors, Subject -> Tags
|
||||
type Book struct {
|
||||
Id string
|
||||
Title string
|
||||
Author []string `sql:"authors" pg:",array"`
|
||||
Authors []string `sql:"authors" pg:",array"`
|
||||
Contributor string
|
||||
Publisher string
|
||||
Description string
|
||||
Subject []string `sql:"tags" pg:",array"`
|
||||
Tags []string `sql:"tags" pg:",array"`
|
||||
Date string
|
||||
Lang string
|
||||
Isbn string
|
||||
|
|
|
@ -3,9 +3,9 @@ package database
|
|||
import "testing"
|
||||
|
||||
var book = Book{
|
||||
Id: "r_m-IOzzIbA6QK5w",
|
||||
Title: "some title",
|
||||
Author: []string{"Alice", "Bob"},
|
||||
Id: "r_m-IOzzIbA6QK5w",
|
||||
Title: "some title",
|
||||
Authors: []string{"Alice", "Bob"},
|
||||
}
|
||||
|
||||
func TestAddAndDeleteBook(t *testing.T) {
|
||||
|
@ -61,8 +61,8 @@ func TestActiveBook(t *testing.T) {
|
|||
if !b.Active {
|
||||
t.Error("Book is not activated")
|
||||
}
|
||||
if b.Author[0] != books[0].Author[0] {
|
||||
t.Error("Book author don't match : '", b.Author, "' <=> '", book.Author, "'")
|
||||
if b.Authors[0] != books[0].Authors[0] {
|
||||
t.Error("Book author don't match : '", b.Authors, "' <=> '", book.Authors, "'")
|
||||
}
|
||||
|
||||
bs, num, err := db.GetBooks(book.Title, 20, 0)
|
||||
|
@ -72,8 +72,8 @@ func TestActiveBook(t *testing.T) {
|
|||
if num != 1 || len(bs) != 1 {
|
||||
t.Fatal("We got a un expected number of books: ", num, bs)
|
||||
}
|
||||
if bs[0].Author[0] != book.Author[0] {
|
||||
t.Error("Book author don't match : '", bs[0].Author, "' <=> '", book.Author, "'")
|
||||
if bs[0].Authors[0] != book.Authors[0] {
|
||||
t.Error("Book author don't match : '", bs[0].Authors, "' <=> '", book.Authors, "'")
|
||||
}
|
||||
|
||||
bs, num, err = db.GetBooks("none", 20, 0)
|
||||
|
|
|
@ -21,7 +21,6 @@ type Visits struct {
|
|||
Count int "count"
|
||||
}
|
||||
|
||||
// TODO: split code in files
|
||||
func (db *pgDB) AddStats(stats interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book {
|
|||
case "title":
|
||||
book.Title = cleanStr(strings.Join(data, ", "))
|
||||
case "creator":
|
||||
book.Author = parseAuthr(data)
|
||||
book.Authors = parseAuthr(data)
|
||||
case "contributor":
|
||||
book.Contributor = cleanStr(strings.Join(data, ", "))
|
||||
case "publisher":
|
||||
|
@ -27,7 +27,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book {
|
|||
case "description":
|
||||
book.Description = parseDescription(data)
|
||||
case "subject":
|
||||
book.Subject = parseSubject(data)
|
||||
book.Tags = parseSubject(data)
|
||||
case "date":
|
||||
book.Date = parseDate(data)
|
||||
case "language":
|
||||
|
|
|
@ -159,8 +159,8 @@ func readHandler(h handler) {
|
|||
data.S = GetStatus(h)
|
||||
|
||||
author := ""
|
||||
if len(book.Author) > 0 {
|
||||
author = " by " + book.Author[0]
|
||||
if len(book.Authors) > 0 {
|
||||
author = " by " + book.Authors[0]
|
||||
}
|
||||
data.S.Title = book.Title + author + " -- Read -- " + data.S.Title
|
||||
|
||||
|
|
|
@ -208,11 +208,11 @@ func bookJsonRaw(book database.Book) map[string]interface{} {
|
|||
return map[string]interface{}{
|
||||
"id": book.Id,
|
||||
"title": book.Title,
|
||||
"author": book.Author,
|
||||
"authors": book.Authors,
|
||||
"contributor": book.Contributor,
|
||||
"publisher": book.Publisher,
|
||||
"description": book.Description,
|
||||
"subject": book.Subject,
|
||||
"tags": book.Tags,
|
||||
"date": book.Date,
|
||||
"lang": book.Lang,
|
||||
"isbn": book.Isbn,
|
||||
|
|
|
@ -68,8 +68,8 @@ func bookHandler(h handler) {
|
|||
data.Book = book
|
||||
|
||||
author := ""
|
||||
if len(book.Author) > 0 {
|
||||
author = " by " + book.Author[0]
|
||||
if len(book.Authors) > 0 {
|
||||
author = " by " + book.Authors[0]
|
||||
}
|
||||
data.S.Title = book.Title + author + " -- " + data.S.Title
|
||||
|
||||
|
|
Reference in a new issue