rename book package to media
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
|
@@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user