Documentation ¶
Index ¶
- Variables
- func OpenDB(t *testing.T) (*gorm.DB, func())
- type Book
- type BookOperationsService
- type BookService
- type BookStatus
- type Magazine
- type MagazineOperationsService
- type MagazineService
- func (ms *MagazineService) Get(id string) (*Magazine, error)
- func (ms *MagazineService) List() ([]Magazine, error)
- func (ms *MagazineService) ListByUser(userID string) ([]Magazine, error)
- func (ms *MagazineService) SwapMagazine(magID, userID string) (*Magazine, error)
- func (ms *MagazineService) Upsert(m Magazine) Magazine
- type PostingService
- type StubbedPostingService
- type User
- type UserProfile
- type UserService
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 Magazine ¶
type Magazine struct { ID string `json:"id" gorm:"primaryKey"` Name string `json:"name"` IssueNumber int `json:"issue_number"` OwnerID string `json:"owner_id"` Status string `json:"status"` }
Magazine contains all the fields for representing a magazine.
type MagazineService ¶
MagazineService contains all the functionality and dependencies for managing magazines.
func NewMagazineService ¶
func NewMagazineService(db *gorm.DB, ps PostingService) *MagazineService
NewMagazineService initialises a MagazineService given its dependencies.
func (*MagazineService) Get ¶
func (ms *MagazineService) Get(id string) (*Magazine, error)
Get returns a given magazine or error if none exists.
func (*MagazineService) List ¶
func (ms *MagazineService) List() ([]Magazine, error)
List returns the list of available magazines.
func (*MagazineService) ListByUser ¶
func (ms *MagazineService) ListByUser(userID string) ([]Magazine, error)
ListByUser returns the list of magazines for a given user.
func (*MagazineService) SwapMagazine ¶
func (ms *MagazineService) SwapMagazine(magID, userID string) (*Magazine, error)
SwapMagazine checks whether a magazine is available and, if possible, marks it as swapped.
func (*MagazineService) Upsert ¶
func (ms *MagazineService) Upsert(m Magazine) Magazine
Upsert creates or updates a magazine.
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) NewBookOrder ¶
func (sps *StubbedPostingService) NewBookOrder(b Book) error
NewBookOrder creates a book order and sends it to the posting servivce for posting.
func (*StubbedPostingService) NewMagazineOrder ¶
func (sps *StubbedPostingService) NewMagazineOrder(m Magazine) error
NewMagazineOrder creates a book 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 UserProfile ¶
Wrapper struct for all the books and magazines of a given user
type UserService ¶
UserService has all the dependencies required for managing users.
func NewUserService ¶
func NewUserService(db *gorm.DB, bs BookOperationsService, ms MagazineOperationsService) *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.
func (*UserService) Get ¶
func (us *UserService) Get(id string) (*UserProfile, error)
Get returns a given user or error if none exists.