Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRecordNotFound = errors.New("record not found")
Functions ¶
Types ¶
type Book ¶
type Book struct { ID string `json:"id" gorm:"primaryKey"` Name string `json:"name"` Author string `json:"author"` OwnerID string `json:"owner_id"` Status string `json:"status"` }
Book contains all the fields for representing a book.
type BookOperationsService ¶
type BookService ¶
BookService contains all the functionality and dependencies for managing books.
func NewBookService ¶
func NewBookService(db *gorm.DB, ps PostingService) *BookService
NewBookService initialises a BookService given its dependencies.
func (*BookService) Get ¶
func (bs *BookService) Get(id string) (*Book, error)
Get returns a given book or error if none exists.
func (*BookService) List ¶
func (bs *BookService) List() ([]Book, error)
List returns the list of available books.
func (*BookService) ListByUser ¶
func (bs *BookService) ListByUser(userID string) ([]Book, error)
ListByUser returns the list of books for a given user.
func (*BookService) SwapBook ¶
func (bs *BookService) SwapBook(bookID, userID string) (*Book, error)
SwapBook checks whether a book is available and, if possible, marks it as swapped.
func (*BookService) Upsert ¶
func (bs *BookService) Upsert(b Book) Book
Upsert creates or updates a book.
type BookStatus ¶
type BookStatus int
BooksStatus contains the different types of Book status.
const ( Available BookStatus = iota Swapped )
func (BookStatus) String ¶
func (o BookStatus) String() string
type PostingService ¶
PostingService interface wraps around external posting functionality.
func NewPostingService ¶
func NewPostingService() PostingService
NewPostingService initialises the PostingService.
type StubbedPostingService ¶
type StubbedPostingService struct{}
StubbedPostingService is a concrete mock of the external PostingService.
func (*StubbedPostingService) NewOrder ¶
func (sps *StubbedPostingService) NewOrder(b Book) error
NewOrder creates a new order and sends it to the posting servivce for posting.
type User ¶
type User struct { ID string `json:"id" gorm:"primaryKey"` Name string `json:"name"` Address string `json:"address"` PostCode string `json:"post_code"` Country string `json:"country"` }
User contains all the user fields.
type UserService ¶
UserService has all the dependencies required for managing users.
func NewUserService ¶
func NewUserService(db *gorm.DB, bs BookOperationsService) *UserService
NewUserService initialises the UserService.
func (*UserService) Exists ¶
func (us *UserService) Exists(id string) error
Exists returns whether a given user exists and returns an error if none found.