customersvc

package module
v0.0.0-...-9b4a7b0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGivenCustomerID indicates that a customer ID was specified where it is not allowed
	ErrGivenCustomerID = errors.New("customer ID must be empty")

	// ErrInvalidCountry indicates that the country code is not valid
	ErrInvalidCountry = errors.New("Country name must be three characters long (use ISO 3166-1 Alpha-3 code)")

	// ErrInvalidHourlyRate indicates that the hourly rate is not valid
	ErrInvalidHourlyRate = errors.New("Hourly rate must be >= 0")

	// ErrNotFound indicates that no customer with the given ID exists
	ErrNotFound = errors.New("not found")

	// ErrInvalidOrderBy indicates that the order-by clause is invalid
	ErrInvalidOrderBy = errors.New("Currently, we can only order by companyName")
)
View Source
var (
	// ErrBadRouting indicates that there is an inconsistency between routs and handlers
	ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)")
)

Functions

func MakeAddCustomerEndpoint

func MakeAddCustomerEndpoint(s CustomerService) endpoint.Endpoint

MakeAddCustomerEndpoint creates an endpoint for the "add customer" operation

func MakeCustomerHTTPHandler

func MakeCustomerHTTPHandler(s CustomerService, logger log.Logger) http.Handler

MakeCustomerHTTPHandler creates a http.Handler for a given service

func MakeDeleteCustomerEndpoint

func MakeDeleteCustomerEndpoint(s CustomerService) endpoint.Endpoint

MakeDeleteCustomerEndpoint creates an endpoint for the "delete customer" operation

func MakeGetCustomerEndpoint

func MakeGetCustomerEndpoint(s CustomerService) endpoint.Endpoint

MakeGetCustomerEndpoint creates an endpoint for the "get customer" operation

func MakeGetCustomersEndpoint

func MakeGetCustomersEndpoint(s CustomerService) endpoint.Endpoint

MakeGetCustomersEndpoint creates an endpoint for the "get customers" operation

func MakePatchCustomerEndpoint

func MakePatchCustomerEndpoint(s CustomerService) endpoint.Endpoint

MakePatchCustomerEndpoint creates an endpoint for the "patch customer" operation

Types

type ByCompanyName

type ByCompanyName []Customer

ByCompanyName is used for sorting customers by company name

func (ByCompanyName) Len

func (c ByCompanyName) Len() int

func (ByCompanyName) Less

func (c ByCompanyName) Less(i, j int) bool

func (ByCompanyName) Swap

func (c ByCompanyName) Swap(i, j int)

type Customer

type Customer struct {
	CustomerID  uuid.UUID       `json:"customerID,omitempty"`
	CompanyName string          `json:"customerName"`
	ContactName string          `json:"contactName"`
	Country     string          `json:"country"`
	HourlyRate  decimal.Decimal `json:"hourlyRate"`
}

Customer holds data of a customer record

type CustomerEndpoints

type CustomerEndpoints struct {
	GetCustomersEndpoint   endpoint.Endpoint
	GetCustomerEndpoint    endpoint.Endpoint
	AddCustomerEndpoint    endpoint.Endpoint
	DeleteCustomerEndpoint endpoint.Endpoint
	PatchCustomerEndpoint  endpoint.Endpoint
}

CustomerEndpoints is a collection of all endpoints that we offer

func MakeCustomerServerEndpoints

func MakeCustomerServerEndpoints(s CustomerService) CustomerEndpoints

MakeCustomerServerEndpoints creates endpoints for a given service

type CustomerMiddleware

type CustomerMiddleware func(CustomerService) CustomerService

CustomerMiddleware wraps a CustomerService to surround business logic methods with additional functionalities like e.g. logging

func CustomerLoggingMiddleware

func CustomerLoggingMiddleware(logger log.Logger) CustomerMiddleware

CustomerLoggingMiddleware returns a factory for a logging middleware for the customer service.

type CustomerService

type CustomerService interface {
	// GetCustomers returns a list of all customers.
	// The resulting list can optionally be sorted (orderBy parameter).
	GetCustomers(ctx context.Context, orderBy string) ([]Customer, error)

	// GetCustomer returns the customer with the given ID.
	GetCustomer(ctx context.Context, cid uuid.UUID) (Customer, error)

	// AddCustomer adds a new customer to the list.
	AddCustomer(ctx context.Context, c Customer) (Customer, error)

	// DeleteCustomer deletes the customer with the given ID.
	DeleteCustomer(ctx context.Context, cid uuid.UUID) error

	// PatchCustomers updates field in the customer with the given ID.
	PatchCustomer(ctx context.Context, cid uuid.UUID, c Customer) (Customer, error)
}

CustomerService is a simple CRUD interface for customer management

func NewCustomerRepository

func NewCustomerRepository() CustomerService

NewCustomerRepository creates a customer repository

type ErrMissingMandatoryValue

type ErrMissingMandatoryValue struct {
	Field string
}

ErrMissingMandatoryValue indicates that a mandatory field does not have a value. This is a custom error type (for more see https://blog.golang.org/go1.13-errors)

func (ErrMissingMandatoryValue) Error

func (r ErrMissingMandatoryValue) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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