rename book package to media

This commit is contained in:
2022-03-05 10:58:15 -05:00
parent c9b70f02e7
commit 98584bbef6
8 changed files with 41 additions and 38 deletions

View File

@@ -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")
}