mongo

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBookNotFound   = errors.New("book not found")
	ErrReviewNotFound = errors.New("review not found")
)

Functions

This section is empty.

Types

type Mongo

type Mongo struct {
	BooksCollection   string
	ReviewsCollection string
	Database          string
	Session           *mgo.Session
	URI               string
	// contains filtered or unexported fields
}

Mongo contains the information needed to create and interact with a mongo session

func (*Mongo) AddBook

func (m *Mongo) AddBook(ctx context.Context, book *models.Book) error

AddBook adds a Book

func (*Mongo) AddReview added in v1.10.0

func (m *Mongo) AddReview(ctx context.Context, review *models.Review) error

AddReview adds a Review to a Book

func (*Mongo) Close

func (m *Mongo) Close(ctx context.Context) (err error)

Close closes the mongo session and returns any error

func (*Mongo) GetBook

func (m *Mongo) GetBook(ctx context.Context, ID string) (*models.Book, error)

GetBook returns a models.Book for a given ID. It returns an error if the Book is not found

func (*Mongo) GetBooks

func (m *Mongo) GetBooks(ctx context.Context) (models.Books, error)

GetBooks returns all the existing models.Books. It returns an error if the models.Books cannot be listed.

func (*Mongo) GetReview added in v1.10.0

func (m *Mongo) GetReview(ctx context.Context, reviewID string) (*models.Review, error)

GetReview returns a models.Review for a given reviewID. It returns an error if the review is not found.

func (*Mongo) GetReviews added in v1.10.0

func (m *Mongo) GetReviews(ctx context.Context, bookID string) (models.Reviews, error)

GetReviews returns all the existing models.Reviews. It returns an error if the models.Reviews cannot be listed.

func (*Mongo) Init

func (m *Mongo) Init(mongoConfig config.MongoConfig) (err error)

Init initialises a mongo session with the given configuration. It returns an error if the session already exists or if it cannot connect.

func (*Mongo) UpdateReview added in v1.10.0

func (m *Mongo) UpdateReview(ctx context.Context, reviewID string, review *models.Review) error

UpdateReview updates an existing Review. Only the message and user can be updated. It returns an error if the review is not found

Jump to

Keyboard shortcuts

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