Documentation ¶
Overview ¶
Package client provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.
Index ¶
- Variables
- type Client
- type Core
- func (c Core) Create(ctx context.Context, nc NewClient, userID string, now time.Time) (Client, error)
- func (c Core) Delete(ctx context.Context, clientID string) error
- func (c Core) Query(ctx context.Context, userID string, pageNumber int, rowsPerPage int) ([]Client, error)
- func (c Core) QueryByID(ctx context.Context, clientID string) (Client, error)
- func (c Core) QueryWorkspaceClients(ctx context.Context, workspaceID string, pageNumber, rowsPerPage int) ([]Client, error)
- func (c Core) Update(ctx context.Context, clientID string, uc UpdateClient, now time.Time) error
- type NewClient
- type UpdateClient
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("user not found") ErrInvalidID = errors.New("ID is not in its proper form") )
Set of error variables for CRUD operations.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { ID string `json:"id"` Name string `json:"name"` Uid string `json:"uid"` Wid string `json:"wid"` Notes string `json:"notes"` DateCreated time.Time `json:"date_created"` DateUpdated time.Time `json:"date_updated"` }
Client represents an individual client.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of APIs for user access.
func NewCore ¶
func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core
NewCore constructs a core for user api access.
func (Core) Create ¶
func (c Core) Create(ctx context.Context, nc NewClient, userID string, now time.Time) (Client, error)
Create inserts a new client into the database.
func (Core) Query ¶
func (c Core) Query(ctx context.Context, userID string, pageNumber int, rowsPerPage int) ([]Client, error)
Query retrieves a list of existing client from the database.
type NewClient ¶
type NewClient struct { Name string `json:"name" validate:"required"` Wid string `json:"wid"` Notes string `json:"notes"` }
NewClient contains information needed to create a new client.
type UpdateClient ¶
UpdateClient defines what information may be provided to modify an existing client. All fields are optional so clients can send just the fields they want changed. It uses pointer fields ,so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types ,but we make exceptions around marshalling/unmarshalling.