usersummary

package
v0.0.0-...-9d47661 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package usersummary provides an example of a core business API that is based on a view.

Index

Constants

View Source
const (
	OrderByUserID   = "userid"
	OrderByUserName = "username"
)

Set of fields that the results can be ordered by. These are the names that should be used by the application layer.

Variables

View Source
var DefaultOrderBy = order.NewBy(OrderByUserID, order.ASC)

DefaultOrderBy represents the default way we sort.

Functions

This section is empty.

Types

type Core

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

Core manages the set of API's for user summaries.

func NewCore

func NewCore(storer Storer) *Core

NewCore constructs a Core for user summary api access.

func (*Core) Count

func (c *Core) Count(ctx context.Context, filter QueryFilter) (int, error)

Count returns the number of usersummary records in the database.

func (*Core) Query

func (c *Core) Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, rowsPerPage int) ([]Summary, error)

Query retrieves a list of usersummary based on the provided filter.

type QueryFilter

type QueryFilter struct {
	UserID   *uuid.UUID `validate:"omitempty"`
	UserName *string    `validate:"omitempty,min=3"`
}

QueryFilter holds the available fields a query can be filtered on.

func (*QueryFilter) Validate

func (qf *QueryFilter) Validate() error

func (*QueryFilter) WithUserID

func (qf *QueryFilter) WithUserID(userID uuid.UUID)

WithUserID sets the UserID field of the QueryFilter value.

func (*QueryFilter) WithUserName

func (qf *QueryFilter) WithUserName(userName string)

WithUserName sets the UserName field of the QueryFilter value.

type Storer

type Storer interface {
	Query(ctx context.Context, filter QueryFilter, orderBy order.By, pageNumber int, rowsPerPage int) ([]Summary, error)
	Count(ctx context.Context, filter QueryFilter) (int, error)
}

Storer interface declares the behavior this package needs to persist and retrieve data.

type Summary

type Summary struct {
	UserID     uuid.UUID
	UserName   string
	TotalCount int
	TotalCost  float64
}

Summary repesents information about an individual user and their products.

Jump to

Keyboard shortcuts

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