garage

package
v0.0.0-...-9cccc27 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateCar

func ValidateCar(car *Car) error

ValidateCar checks if the car brand and color are available. If the car is not valid, an helpers.ErrValidation is returned.

Types

type Car

type Car struct {
	ID    string `json:"id" bson:"_id"`
	Brand string `json:"brand" bson:"brand"`
	Color string `json:"color" bson:"color"`
}

Car is the structure representing a car.

type CarManager

type CarManager struct {
	Repo   *CarRepository
	Logger *zap.Logger
}

CarManager handles the creation, modification and deletion of cars. It uses a CarRepository to communicate with the database.

func (*CarManager) Create

func (m *CarManager) Create(car *Car) (*Car, error)

Create inserts the given car in the database. It returns the inserted car.

func (*CarManager) Delete

func (m *CarManager) Delete(id string) error

Delete removes the car with the given id.

func (*CarManager) Get

func (m *CarManager) Get(id string) (*Car, error)

Get returns the car with the given id. If the car does not exist an helpers.ErrNotFound is returned.

func (*CarManager) GetAll

func (m *CarManager) GetAll() ([]*Car, error)

GetAll returns the list of cars.

func (*CarManager) Update

func (m *CarManager) Update(id string, car *Car) (*Car, error)

Update updates the car with the given id. It uses the values contained in the given car fields. It returns the updated car.

type CarRepository

type CarRepository struct {
	Session *mgo.Session
}

CarRepository contains all the interactions with the car collection stored in mongo.

func (*CarRepository) Delete

func (repo *CarRepository) Delete(id string) error

Delete removes the car with the given id.

func (*CarRepository) FindAll

func (repo *CarRepository) FindAll() ([]*Car, error)

FindAll returns all the cars stored in the database.

func (*CarRepository) FindByID

func (repo *CarRepository) FindByID(id string) (*Car, error)

FindByID retrieves the car with the given id from the database.

func (*CarRepository) Insert

func (repo *CarRepository) Insert(car *Car) error

Insert inserts a car in the database.

func (*CarRepository) IsAlreadyExistErr

func (repo *CarRepository) IsAlreadyExistErr(err error) bool

IsAlreadyExistErr returns true if the error is related to the insertion of an already existing document.

func (*CarRepository) IsNotFoundErr

func (repo *CarRepository) IsNotFoundErr(err error) bool

IsNotFoundErr returns true if the error concerns a not found document.

func (*CarRepository) Update

func (repo *CarRepository) Update(car *Car) error

Update updates all the caracteristics of a car.

Jump to

Keyboard shortcuts

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