db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = errors.New("record not found")

Functions

func OpenDB

func OpenDB(t *testing.T) (*gorm.DB, func())

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 BookOperationsService interface {
	ListByUser(userID string) ([]Book, error)
}

type BookService

type BookService struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

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

type PostingService interface {
	NewOrder(b Book) error
}

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

type UserService struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

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.

func (*UserService) Get

func (us *UserService) Get(id string) (*User, []Book, error)

Get returns a given user or error if none exists.

func (*UserService) Upsert

func (us *UserService) Upsert(u User) (User, error)

Upsert creates or updates a new order.

Jump to

Keyboard shortcuts

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