Documentation ¶
Overview ¶
Package image provides an example of a core business API. Right now these calls are just wrapping the data/store layer. But at some point you will want auditing or something that isn't specific to the data/store layer.
Index ¶
- Variables
- type Core
- func (c Core) Create(ctx context.Context, np NewImage, now time.Time) (Image, error)
- func (c Core) Delete(ctx context.Context, productID string) error
- func (c Core) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Image, error)
- func (c Core) QueryByID(ctx context.Context, productID string) (Image, error)
- func (c Core) QueryByUserID(ctx context.Context, userID string) ([]Image, error)
- func (c Core) Update(ctx context.Context, productID string, up UpdateImage, now time.Time) error
- type Image
- type NewImage
- type UpdateImage
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("image 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 Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of APIs for image access.
func NewCore ¶
func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core
NewCore constructs a core for image api access.
func (Core) Create ¶
Create adds an Image to the database. It returns the created Image with fields like ID and DateCreated populated.
func (Core) QueryByUserID ¶
QueryByUserID finds the products identified by a given User ID.
type Image ¶
type Image struct { ID string `json:"id"` // Unique identifier. ImageURL string `json:"image_url"` // Display image url of the image. UserID string `json:"user_id"` // User who uploaded the image. DateUploaded time.Time `json:"date_uploaded"` // When the image was added. }
Image represents an individual image.
type NewImage ¶
type NewImage struct { ImageURL string `json:"image_url" validate:"required"` UserID string `json:"user_id" validate:"required"` }
NewImage is what we require from clients when adding an image.
type UpdateImage ¶
UpdateImage defines what information may be provided to modify an existing Image. 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.