service

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewDB added in v1.1.0

func NewDB(cfg *DBConfig) (*sql.DB, error)

NewDB initializes a new DB connection object using the configuration paraemters provided

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

func (dbpr *DBPaymentRepository) Add(payment *models.Payment) (*models.Payment, error)

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

func (dbpr *DBPaymentRepository) Get(paymentID strfmt.UUID) (*models.Payment, error)

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

CreatePayment Adds a new payment with the data included in params

func (*PaymentsService) DeletePayment

DeletePayment Deletes a payment identified by its ID

func (*PaymentsService) GetPayment

GetPayment Returns details of a payment identified by its ID

func (*PaymentsService) ListPayments

ListPayments Returns details of a collection of payments

func (*PaymentsService) UpdatePayment

UpdatePayment Adds a new payment with the data included in params

Jump to

Keyboard shortcuts

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