From 98584bbef66ccd89f550861caebbc2b59a5b3257 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sat, 5 Mar 2022 10:58:15 -0500 Subject: [PATCH] rename book package to media --- cmd/manage/events.go | 8 ++++---- cmd/manage/main.go | 14 +++++++------- cmd/serve/main.go | 4 ++-- database/memory.go | 20 ++++++++++---------- database/mysql.go | 12 ++++++------ importer/csv.go | 8 ++++---- book/book.go => media/media.go | 5 ++++- ui/ui.go | 8 ++++---- 8 files changed, 41 insertions(+), 38 deletions(-) rename book/book.go => media/media.go (94%) diff --git a/cmd/manage/events.go b/cmd/manage/events.go index 3b2468a..1c8e5ad 100644 --- a/cmd/manage/events.go +++ b/cmd/manage/events.go @@ -1,7 +1,7 @@ package main import ( - "git.yetaga.in/alazyreader/library/book" + "git.yetaga.in/alazyreader/library/media" "github.com/gdamore/tcell" ) @@ -20,16 +20,16 @@ func NewEventError(err error) *EventError { // save change to book type EventBookUpdate struct { tcell.EventTime - book *book.Book + book *media.Book } -func NewEventBookUpdate(b *book.Book) *EventBookUpdate { +func NewEventBookUpdate(b *media.Book) *EventBookUpdate { e := &EventBookUpdate{book: b} e.SetEventNow() return e } -func (e *EventBookUpdate) Book() *book.Book { +func (e *EventBookUpdate) Book() *media.Book { return e.book } diff --git a/cmd/manage/main.go b/cmd/manage/main.go index 3d105db..f217a70 100644 --- a/cmd/manage/main.go +++ b/cmd/manage/main.go @@ -9,10 +9,10 @@ import ( "strings" "sync" - "git.yetaga.in/alazyreader/library/book" "git.yetaga.in/alazyreader/library/config" "git.yetaga.in/alazyreader/library/database" "git.yetaga.in/alazyreader/library/importer" + "git.yetaga.in/alazyreader/library/media" "git.yetaga.in/alazyreader/library/ui" "github.com/gdamore/tcell" "github.com/kelseyhightower/envconfig" @@ -120,7 +120,7 @@ func main() { }() // book list and options menu (left column) - l := ui.NewList(Titles(state.Get("library").([]book.Book)), 0) + l := ui.NewList(Titles(state.Get("library").([]media.Book)), 0) menu := ui.NewBox( "library", []string{"˄˅ select", "⏎ edit", "(n)ew", "(i)mport", "(q)uit"}, @@ -131,7 +131,7 @@ func main() { ui.StyleActive, false, ) - activeBookDetails := ui.NewBookDetails(&book.Book{}) + activeBookDetails := ui.NewBookDetails(&media.Book{}) // book display (right column) activeBook := ui.NewBox( @@ -307,7 +307,7 @@ func main() { default: } // repaint - l.SetMembers(Titles(state.Get("library").([]book.Book))) + l.SetMembers(Titles(state.Get("library").([]media.Book))) container.Draw(screen) popup.Draw(screen) errorPopup.Draw(screen) @@ -315,7 +315,7 @@ func main() { } } -func Titles(lb []book.Book) []ui.ListKeyValue { +func Titles(lb []media.Book) []ui.ListKeyValue { r := []ui.ListKeyValue{} for i := range lb { r = append(r, ui.ListKeyValue{ @@ -326,11 +326,11 @@ func Titles(lb []book.Book) []ui.ListKeyValue { return r } -func GetBookByID(id int, lb []book.Book) *book.Book { +func GetBookByID(id int, lb []media.Book) *media.Book { for i := range lb { if lb[i].ID == id { return &lb[i] } } - return &book.Book{} + return &media.Book{} } diff --git a/cmd/serve/main.go b/cmd/serve/main.go index 567a0de..119b990 100644 --- a/cmd/serve/main.go +++ b/cmd/serve/main.go @@ -8,10 +8,10 @@ import ( "net/http" "strings" - "git.yetaga.in/alazyreader/library/book" "git.yetaga.in/alazyreader/library/config" "git.yetaga.in/alazyreader/library/database" "git.yetaga.in/alazyreader/library/frontend" + "git.yetaga.in/alazyreader/library/media" "github.com/kelseyhightower/envconfig" ) @@ -23,7 +23,7 @@ func max(a, b int) int { } type Library interface { - GetAllBooks(context.Context) ([]book.Book, error) + GetAllBooks(context.Context) ([]media.Book, error) } type Router struct { diff --git a/database/memory.go b/database/memory.go index 58c027e..eb58fde 100644 --- a/database/memory.go +++ b/database/memory.go @@ -5,43 +5,43 @@ import ( "fmt" "sync" - "git.yetaga.in/alazyreader/library/book" + "git.yetaga.in/alazyreader/library/media" ) type Memory struct { lock sync.Mutex - shelf []book.Book + shelf []media.Book } -func (m *Memory) GetAllBooks(_ context.Context) ([]book.Book, error) { +func (m *Memory) GetAllBooks(_ context.Context) ([]media.Book, error) { m.lock.Lock() defer m.lock.Unlock() if m.shelf == nil { - m.shelf = []book.Book{} + m.shelf = []media.Book{} } return m.shelf, nil } -func (m *Memory) AddBook(_ context.Context, b *book.Book) error { +func (m *Memory) AddBook(_ context.Context, b *media.Book) error { m.lock.Lock() defer m.lock.Unlock() if m.shelf == nil { - m.shelf = []book.Book{} + m.shelf = []media.Book{} } m.shelf = append(m.shelf, *b) return nil } -func (m *Memory) UpdateBook(_ context.Context, old, new *book.Book) error { +func (m *Memory) UpdateBook(_ context.Context, old, new *media.Book) error { m.lock.Lock() defer m.lock.Unlock() if m.shelf == nil { - m.shelf = []book.Book{} + m.shelf = []media.Book{} return fmt.Errorf("book does not exist") } @@ -58,12 +58,12 @@ func (m *Memory) UpdateBook(_ context.Context, old, new *book.Book) error { return fmt.Errorf("book does not exist") } -func (m *Memory) DeleteBook(_ context.Context, b *book.Book) error { +func (m *Memory) DeleteBook(_ context.Context, b *media.Book) error { m.lock.Lock() defer m.lock.Unlock() if m.shelf == nil { - m.shelf = []book.Book{} + m.shelf = []media.Book{} return fmt.Errorf("book does not exist") } diff --git a/database/mysql.go b/database/mysql.go index bd0d1e0..8b769e4 100644 --- a/database/mysql.go +++ b/database/mysql.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "git.yetaga.in/alazyreader/library/book" + "git.yetaga.in/alazyreader/library/media" _ "github.com/go-sql-driver/mysql" ) @@ -142,12 +142,12 @@ func (m *MySQL) RunMigrations(ctx context.Context) (int, int, error) { return latestMigrationRan, migrationsRun, err } -func (m *MySQL) GetAllBooks(ctx context.Context) ([]book.Book, error) { +func (m *MySQL) GetAllBooks(ctx context.Context) ([]media.Book, error) { if m.connection == nil { return nil, fmt.Errorf("uninitialized mysql client") } - books := []book.Book{} + books := []media.Book{} rows, err := m.connection.QueryContext(ctx, ` SELECT id, title, @@ -173,7 +173,7 @@ func (m *MySQL) GetAllBooks(ctx context.Context) ([]book.Book, error) { defer rows.Close() for rows.Next() { - b := book.Book{} + b := media.Book{} var authors string err := rows.Scan( &b.ID, &b.Title, &authors, @@ -192,7 +192,7 @@ func (m *MySQL) GetAllBooks(ctx context.Context) ([]book.Book, error) { return books, nil } -func (m *MySQL) AddBook(ctx context.Context, b *book.Book) error { +func (m *MySQL) AddBook(ctx context.Context, b *media.Book) error { if m.connection == nil { return fmt.Errorf("uninitialized mysql client") } @@ -232,7 +232,7 @@ func (m *MySQL) AddBook(ctx context.Context, b *book.Book) error { return nil } -func (m *MySQL) UpdateBook(ctx context.Context, old, new *book.Book) error { +func (m *MySQL) UpdateBook(ctx context.Context, old, new *media.Book) error { if m.connection == nil { return fmt.Errorf("uninitialized mysql client") } diff --git a/importer/csv.go b/importer/csv.go index e458577..0032815 100644 --- a/importer/csv.go +++ b/importer/csv.go @@ -5,17 +5,17 @@ import ( "io" "strings" - "git.yetaga.in/alazyreader/library/book" + "git.yetaga.in/alazyreader/library/media" ) -func CSVToBooks(r io.Reader) ([]book.Book, error) { +func CSVToBooks(r io.Reader) ([]media.Book, error) { reader := csv.NewReader(r) header, err := reader.Read() if err != nil { return nil, err } hmap := parseHeader(header) - books := []book.Book{} + books := []media.Book{} for { row, err := reader.Read() @@ -25,7 +25,7 @@ func CSVToBooks(r io.Reader) ([]book.Book, error) { if err != nil { return books, err } - b := book.Book{ + b := media.Book{ Title: row[hmap["title"]], Authors: parseAuthors(row[hmap["author"]]), SortAuthor: row[hmap["authorlast"]], diff --git a/book/book.go b/media/media.go similarity index 94% rename from book/book.go rename to media/media.go index 4552e7a..13ae99e 100644 --- a/book/book.go +++ b/media/media.go @@ -1,4 +1,4 @@ -package book +package media type Book struct { ID int `json:"-"` @@ -19,3 +19,6 @@ type Book struct { OnLoan string `json:"onLoan"` CoverURL string `json:"coverURL"` } + +type Record struct { +} diff --git a/ui/ui.go b/ui/ui.go index 5595ae9..4c99520 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - "git.yetaga.in/alazyreader/library/book" + "git.yetaga.in/alazyreader/library/media" "github.com/gdamore/tcell" ) @@ -361,19 +361,19 @@ func (l *List) SetMembers(lkv []ListKeyValue) { type BookDetails struct { x, y int h, w int - book *book.Book + book *media.Book style tcell.Style visible bool } -func NewBookDetails(b *book.Book) *BookDetails { +func NewBookDetails(b *media.Book) *BookDetails { return &BookDetails{ book: b, visible: true, } } -func (l *BookDetails) SetBook(b *book.Book) { +func (l *BookDetails) SetBook(b *media.Book) { l.book = b }