Documentation
¶
Index ¶
- type Adapter
- type BikesRepository
- func (r *BikesRepository) Create(ctx context.Context, b bikerental.Bike) error
- func (r *BikesRepository) Delete(ctx context.Context, id string) error
- func (r *BikesRepository) Get(ctx context.Context, id string) (*bikerental.Bike, error)
- func (r *BikesRepository) List(ctx context.Context) ([]bikerental.Bike, error)
- func (r *BikesRepository) Update(ctx context.Context, id string, b bikerental.Bike) error
- type CustomersRepository
- func (r *CustomersRepository) Create(ctx context.Context, c bikerental.Customer) error
- func (r *CustomersRepository) CreateInTx(ctx context.Context, tx *sqlx.Tx, c bikerental.Customer) error
- func (r *CustomersRepository) Delete(ctx context.Context, id string) error
- func (r *CustomersRepository) Get(ctx context.Context, id string) (*bikerental.Customer, error)
- func (r *CustomersRepository) GetInTx(ctx context.Context, tx *sqlx.Tx, id string) (*bikerental.Customer, error)
- type ReservationsRepository
- func (r *ReservationsRepository) Create(ctx context.Context, reservation bikerental.Reservation) (*bikerental.Reservation, error)
- func (r *ReservationsRepository) Delete(ctx context.Context, id string) error
- func (r *ReservationsRepository) Get(ctx context.Context, id string) (*bikerental.Reservation, error)
- func (r *ReservationsRepository) List(ctx context.Context, query reservation.ListReservationsQuery) ([]bikerental.Reservation, error)
- func (r *ReservationsRepository) SetStatus(ctx context.Context, id string, status bikerental.ReservationStatus) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is a storage adapter for app.
func NewAdapter ¶
func NewAdapter( hostport string, dbname string, user string, pass string, migrationsDir string, log logrus.FieldLogger, ) (*Adapter, error)
NewAdapter creates new db adapter.
func (*Adapter) Customers ¶
func (a *Adapter) Customers() *CustomersRepository
Customers returns customers repository.
func (*Adapter) Reservations ¶
func (a *Adapter) Reservations() *ReservationsRepository
Reservations returns reservations repository.
type BikesRepository ¶
type BikesRepository struct {
// contains filtered or unexported fields
}
BikesRepository manages bikes in db.
func (*BikesRepository) Create ¶
func (r *BikesRepository) Create(ctx context.Context, b bikerental.Bike) error
Create creates new bike in db.
func (*BikesRepository) Delete ¶
func (r *BikesRepository) Delete(ctx context.Context, id string) error
Delete deletes a bike from db by id. If bike is not in db, returns app.ErrNotFound error.
func (*BikesRepository) Get ¶
func (r *BikesRepository) Get(ctx context.Context, id string) (*bikerental.Bike, error)
Get returns a bike by id. If it doesn't exists, returns app.ErrNotFound error.
func (*BikesRepository) List ¶
func (r *BikesRepository) List(ctx context.Context) ([]bikerental.Bike, error)
List returns list of all bikes from db sorted by name ascending.
func (*BikesRepository) Update ¶
func (r *BikesRepository) Update(ctx context.Context, id string, b bikerental.Bike) error
Update updates a bike in db by id. If bike is not in db, returns app.ErrNotFound error.
type CustomersRepository ¶
type CustomersRepository struct {
// contains filtered or unexported fields
}
CustomersRepository manages customers in db.
func (*CustomersRepository) Create ¶
func (r *CustomersRepository) Create(ctx context.Context, c bikerental.Customer) error
Create creates new customer in db.
func (*CustomersRepository) CreateInTx ¶
func (r *CustomersRepository) CreateInTx(ctx context.Context, tx *sqlx.Tx, c bikerental.Customer) error
CreateInTx creates new customer in db using existing db transaction.
func (*CustomersRepository) Delete ¶
func (r *CustomersRepository) Delete(ctx context.Context, id string) error
Delete removes customer from db.
func (*CustomersRepository) Get ¶
func (r *CustomersRepository) Get(ctx context.Context, id string) (*bikerental.Customer, error)
Get returns a customer by id. If it doesn't exists, returns app.ErrNotFound error.
type ReservationsRepository ¶
type ReservationsRepository struct {
// contains filtered or unexported fields
}
ReservationsRepository manages reservation data in db.
func (*ReservationsRepository) Create ¶
func (r *ReservationsRepository) Create(ctx context.Context, reservation bikerental.Reservation) (*bikerental.Reservation, error)
Create creates new reservation in db. Bike id must be provided. If customer doesn't exists, it is created with reservation.
func (*ReservationsRepository) Delete ¶
func (r *ReservationsRepository) Delete(ctx context.Context, id string) error
Delete deletes reservation from db.
func (*ReservationsRepository) Get ¶
func (r *ReservationsRepository) Get(ctx context.Context, id string) (*bikerental.Reservation, error)
Get returns a reservation by id. Returns app.ErrNotFound if reservation doesn't exists.
func (*ReservationsRepository) List ¶
func (r *ReservationsRepository) List(ctx context.Context, query reservation.ListReservationsQuery) ([]bikerental.Reservation, error)
List returns list of reservations matching request criteria.
func (*ReservationsRepository) SetStatus ¶
func (r *ReservationsRepository) SetStatus(ctx context.Context, id string, status bikerental.ReservationStatus) error
SetStatus updates the status of the reservation by its id. Returns app.ErrNotFound if reservation doesn't exists.