Documentation
¶
Index ¶
- Constants
- func NewDB(cfg *DBConfig) (*sql.DB, error)
- type DBConfig
- type DBPaymentRepository
- func (dbpr *DBPaymentRepository) Add(payment *models.Payment) (*models.Payment, error)
- func (dbpr *DBPaymentRepository) Close() error
- func (dbpr *DBPaymentRepository) Delete(paymentID strfmt.UUID) error
- func (dbpr *DBPaymentRepository) DeleteAll() error
- func (dbpr *DBPaymentRepository) Get(paymentID strfmt.UUID) (*models.Payment, error)
- func (dbpr *DBPaymentRepository) List(offset, limit int64) ([]*models.Payment, error)
- func (dbpr *DBPaymentRepository) Update(paymentID strfmt.UUID, payment *models.Payment) (*models.Payment, error)
- type ErrBadOffsetLimit
- type ErrConflict
- type ErrNoResults
- type PaymentRepository
- type PaymentsService
- func (papi *PaymentsService) CreatePayment(ctx context.Context, params payments.CreatePaymentParams) middleware.Responder
- func (papi *PaymentsService) DeletePayment(ctx context.Context, params payments.DeletePaymentParams) middleware.Responder
- func (papi *PaymentsService) GetPayment(ctx context.Context, params payments.GetPaymentParams) middleware.Responder
- func (papi *PaymentsService) ListPayments(ctx context.Context, params payments.ListPaymentsParams) middleware.Responder
- func (papi *PaymentsService) UpdatePayment(ctx context.Context, params payments.UpdatePaymentParams) middleware.Responder
Constants ¶
const TYPE_PAYMENT = "Payment"
TYPE_PAYMENT is a constant string that contains the value of the Type attribute of every payment resource
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DBConfig ¶ added in v1.1.0
type DBConfig struct { // Address of the server that hosts the DB Host string // Port where the DB server is listening for connections Port int // User to use when accessing the DB User string // Password to use when accessing the DB Pass string // Name of the DB to connect to Name string // Path to the folder that contains the migration files MigrationsPath string }
DBConfig contains the parameters needed to connect to a DB
type DBPaymentRepository ¶ added in v1.1.0
type DBPaymentRepository struct {
// contains filtered or unexported fields
}
DBPaymentRepository stores a collection of payment resources using an external database as data backend
func NewDBPaymentRepository ¶ added in v1.1.0
func NewDBPaymentRepository(db *sql.DB, dbName, migrationsPath string) (*DBPaymentRepository, error)
NewDBPaymentRepository creates a new DBPaymentRepository that uses a previously configured sql.DB to connect to the DB
func (*DBPaymentRepository) Add ¶ added in v1.1.0
Add adds a new payment resource to the repository
Add returns an error if a payment with the same ID as the one to be added already exists
func (*DBPaymentRepository) Close ¶ added in v1.1.0
func (dbpr *DBPaymentRepository) Close() error
Close closes the underlying db instance and frees its associated resources
func (*DBPaymentRepository) Delete ¶ added in v1.1.0
func (dbpr *DBPaymentRepository) Delete(paymentID strfmt.UUID) error
Delete deletes the payment resource associated to the given paymentID
Delete returns an error if the paymentID is not present in the respository
func (*DBPaymentRepository) DeleteAll ¶ added in v1.1.0
func (dbpr *DBPaymentRepository) DeleteAll() error
DeleteAll deletes every payment in the DB
func (*DBPaymentRepository) Get ¶ added in v1.1.0
Get returns the payment resource associated with the given paymentID
Get returns an error if the paymentID does not exist in the collection
func (*DBPaymentRepository) List ¶ added in v1.1.0
func (dbpr *DBPaymentRepository) List(offset, limit int64) ([]*models.Payment, error)
List returns a slice of payment resources. An empty slice will be returned if no payment exists.
List implements basic pagination by means of offset and limit parameters. List will return an error if offset is beyond the number of elements available. Limit must be between 1 and 100.
func (*DBPaymentRepository) Update ¶ added in v1.1.0
func (dbpr *DBPaymentRepository) Update(paymentID strfmt.UUID, payment *models.Payment) (*models.Payment, error)
Update updates the details associated with the given paymentID. The current implementation is a basic one that doesn't support updating fields selectively.
Update returns an error if the paymentID does not exist in the collection
type ErrBadOffsetLimit ¶ added in v1.1.0
type ErrBadOffsetLimit string
ErrBadOffsetLimit is returned when invalid pagination parameters are passed when listing payments
func (ErrBadOffsetLimit) Error ¶ added in v1.1.0
func (e ErrBadOffsetLimit) Error() string
Error satisfies stdlib's error interface
type ErrConflict ¶ added in v1.1.0
type ErrConflict string
ErrConflict signals an attempt to add a new payment with the same id as one already present
func (ErrConflict) Error ¶ added in v1.1.0
func (e ErrConflict) Error() string
Error satisfies stdlib's error interface
type ErrNoResults ¶ added in v1.1.0
type ErrNoResults string
ErrNoResults is returned when a get, delete or update is attempted for a non-existent id
func (ErrNoResults) Error ¶ added in v1.1.0
func (e ErrNoResults) Error() string
Error satisfies stdlib's error interface
type PaymentRepository ¶
type PaymentRepository interface { // Add adds a new payment resource to the repository // // Add returns an error if a payment with the same ID as the one // to be added already exists Add(payment *models.Payment) (*models.Payment, error) // Delete deletes the payment resource associated to the given paymentID // // Delete returns an error if the paymentID is not present in the respository Delete(paymentID strfmt.UUID) error // Get returns the payment resource associated with the given paymentID // // Get returns an error if the paymentID does not exist in the collection Get(paymentID strfmt.UUID) (*models.Payment, error) // List returns a slice of payment resources. An empty slice will be returned // if no payment exists. // // List implements basic pagination by means of offset and limit parameters. // List will return an error if offset is beyond the number of elements available. // A limit of 0 will return all elements available. Both parameters default to 0. List(offset, limit int64) ([]*models.Payment, error) // Update updates the details associated with the given paymentID // // Update returns an error if the paymentID does not exist in the collection Update(paymentID strfmt.UUID, payment *models.Payment) (*models.Payment, error) }
PaymentRepository stores a collection of payment resources that is safe for concurrent use
type PaymentsService ¶
type PaymentsService struct { // Repo is a repository for payments Repo PaymentRepository // Logger will be use to write logs. Only unexpected errors will be logged Logger *log.Logger }
PaymentsService implements the business logic needed to fulfill the API's requirements
func (*PaymentsService) CreatePayment ¶
func (papi *PaymentsService) CreatePayment(ctx context.Context, params payments.CreatePaymentParams) middleware.Responder
CreatePayment Adds a new payment with the data included in params
func (*PaymentsService) DeletePayment ¶
func (papi *PaymentsService) DeletePayment(ctx context.Context, params payments.DeletePaymentParams) middleware.Responder
DeletePayment Deletes a payment identified by its ID
func (*PaymentsService) GetPayment ¶
func (papi *PaymentsService) GetPayment(ctx context.Context, params payments.GetPaymentParams) middleware.Responder
GetPayment Returns details of a payment identified by its ID
func (*PaymentsService) ListPayments ¶
func (papi *PaymentsService) ListPayments(ctx context.Context, params payments.ListPaymentsParams) middleware.Responder
ListPayments Returns details of a collection of payments
func (*PaymentsService) UpdatePayment ¶
func (papi *PaymentsService) UpdatePayment(ctx context.Context, params payments.UpdatePaymentParams) middleware.Responder
UpdatePayment Adds a new payment with the data included in params