quote

package
v0.0.0-...-aabb4b4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpsertMetricName string = "upsert_total"
	UpsertHelp       string = "total number of calls to upsert"
)

Variables

View Source
var (
	// ErrNew represents an error when creating a new Quote
	ErrNew = errors.New("unable to create new quote")
	// ErrEmptyRepository repository cannot be nil
	ErrEmptyRepository = errors.New("empty repository")
	// ErrTypeAssertion arises while trying to perform interface{}.(T)
	ErrTypeAssertion = errors.New("unable to execute type assertion")
)
View Source
var RESTErrorBussines = restError{
	ErrNew:        {"Sorry, we cannot create a new quote", http.StatusInternalServerError},
	sql.ErrNoRows: {"Record not found", http.StatusNotFound},
}

RESTErrorBussines Errors you want to map to more meaning response for clients and set specific HTTP status code should be included here

Functions

func DeleteByID

func DeleteByID(svc ServiceI) endpoint.Endpoint

func FindByID

func FindByID(svc ServiceI) endpoint.Endpoint

func Upsert

func Upsert(svc ServiceI) endpoint.Endpoint

Types

type CountMetric

type CountMetric struct {
	// contains filtered or unexported fields
}

CountMetric is a domain level metric middleware using prometheus.

func NewCountMetric

func NewCountMetric(quoteService ServiceI, counter prometheus.Counter) *CountMetric

func (*CountMetric) Delete

func (mw *CountMetric) Delete(ctx context.Context, id uuid.UUID) error

func (*CountMetric) FindByID

func (mw *CountMetric) FindByID(ctx context.Context, id uuid.UUID) (Quote, error)

func (*CountMetric) Upsert

func (mw *CountMetric) Upsert(ctx context.Context, q *Quote) error

type DeleteRequest

type DeleteRequest struct {
	ID uuid.UUID
}

type Execer

type Execer interface {
	Upsert(context.Context, *Quote) error
	Delete(context.Context, uuid.UUID) error
}

type FindByIDRequest

type FindByIDRequest struct {
	ID uuid.UUID
}

type JSONRequest

type JSONRequest struct {
	ID      *uuid.UUID `json:"id,omitempty"`
	Content string     `json:"content"`
}

type JSONResponse

type JSONResponse struct {
	ID      *uuid.UUID `json:"id,omitempty"`
	Content string     `json:"content,omitempty"`
	Error   string     `json:"error,omitempty"`
}

type Querier

type Querier interface {
	FindByID(context.Context, uuid.UUID) (Quote, error)
}

type Quote

type Quote struct {
	ID      uuid.UUID
	Content string
}

func NewQuote

func NewQuote(id *uuid.UUID, content string) (Quote, error)

type RepositoryI

type RepositoryI interface {
	// Queries is a "Readeble" interface responsible to read data from source
	Querier

	// Execer is a "Writable" interface responsible for write data into source
	Execer
}

RepositoryI is a interface to communicate with a external source of data (ex: Postgres, Firebase FireStore or an API) It is using the concept of having a readable interface called "Querier" and a Writable interface called "Execer", which exec actions into the external source of data.

type RepositoryMemory

type RepositoryMemory struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(logger log.Logger) *RepositoryMemory

func (*RepositoryMemory) Delete

func (r *RepositoryMemory) Delete(ctx context.Context, id uuid.UUID) error

func (*RepositoryMemory) FindByID

func (r *RepositoryMemory) FindByID(ctx context.Context, id uuid.UUID) (Quote, error)

func (*RepositoryMemory) Upsert

func (r *RepositoryMemory) Upsert(ctx context.Context, q *Quote) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(repository RepositoryI, log log.Logger) (*Service, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id uuid.UUID) error

func (*Service) FindByID

func (s *Service) FindByID(ctx context.Context, id uuid.UUID) (Quote, error)

func (*Service) Upsert

func (s *Service) Upsert(ctx context.Context, q *Quote) error

type ServiceI

type ServiceI interface {
	FindByID(context.Context, uuid.UUID) (Quote, error)
	Upsert(context.Context, *Quote) error
	Delete(context.Context, uuid.UUID) error
}

type UpsertRequest

type UpsertRequest struct {
	JSONRequest
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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