Documentation ¶
Index ¶
- func ValidateCar(car *Car) error
- type Car
- type CarManager
- type CarRepository
- func (repo *CarRepository) Delete(id string) error
- func (repo *CarRepository) FindAll() ([]*Car, error)
- func (repo *CarRepository) FindByID(id string) (*Car, error)
- func (repo *CarRepository) Insert(car *Car) error
- func (repo *CarRepository) IsAlreadyExistErr(err error) bool
- func (repo *CarRepository) IsNotFoundErr(err error) bool
- func (repo *CarRepository) Update(car *Car) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateCar ¶
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.
type CarRepository ¶
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.