book

package
v0.0.0-...-55af573 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAffect    = errors.New("No rows affected")
	ErrNoBookFound = errors.New("No book found")
)
View Source
var (
	ErrInvalidID   = errors.New("ID is not in the correct form")
	ErrInvalidSort = errors.New("invalid sort field")
)

Functions

This section is empty.

Types

type Book

type Book struct {
	ID       string `db:"id" json:"id"`
	ISBN     string `db:"isbn" json:"isbn"`
	Title    string `db:"title" json:"title"`
	Author   string `db:"author" json:"author"`
	Category string `db:"category" json:"category"`
}

type NewBook

type NewBook struct {
	ISBN     string `json:"isbn" validate:"required"`
	Title    string `json:"title" validate:"required"`
	Author   string `json:"author" validate:"required"`
	Category string `json:"category"`
}

type Repository

type Repository interface {
	GetAll() ([]Book, error)
	GetById(id string) (*Book, error)
	Search(sp SearchParams, sortOrder string, limit, offset int) ([]Book, error)
	Create(bk *Book) error
	Update(bk *Book) error
	Destroy(id string) error
}

func NewRepository

func NewRepository(db *sql.DB) Repository

type SearchParams

type SearchParams struct {
	ISBN     string
	Title    string
	Author   string
	Category string
}

type Service

type Service interface {
	GetAll() ([]Book, error)
	GetById(id string) (*Book, error)
	Search(sp SearchParams, sort, order, limitStr, offsetStr string) ([]Book, error)
	Create(nb *NewBook) (*Book, error)
	Update(id string, ub UpdateBook) error
	Destroy(id string) error
}

func NewService

func NewService(br Repository) Service

type UpdateBook

type UpdateBook struct {
	ISBN     string  `json:"isbn"`
	Title    string  `json:"title"`
	Author   string  `json:"author"`
	Category *string `json:"category"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL