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 BookRepository ¶
BookRepository contains all the functionality and dependencies for managing books.
func NewBookRepository ¶
func NewBookRepository(db *gorm.DB, ps PostingService) *BookRepository
NewBookRepository initialises a BookService given its dependencies.
func (*BookRepository) Get ¶
func (bs *BookRepository) Get(b *Book) error
Get populates a given book or returns error if none exists.
func (*BookRepository) List ¶
func (bs *BookRepository) List() ([]Book, error)
List returns the list of available books.
func (*BookRepository) ListByUser ¶
func (bs *BookRepository) ListByUser(userID string) ([]Book, error)
ListByUser returns the list of books for a given user.
func (*BookRepository) SwapBook ¶
func (bs *BookRepository) SwapBook(bookID, userID string) (*Book, error)
SwapBook checks whether a book is available and, if possible, marks it as swapped.
func (*BookRepository) Upsert ¶
func (bs *BookRepository) 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.