image

package
v0.0.0-...-ab07b4f Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func (c Core) Create(ctx context.Context, np NewImage, now time.Time) (Image, error)

Create adds an Image to the database. It returns the created Image with fields like ID and DateCreated populated.

func (Core) Delete

func (c Core) Delete(ctx context.Context, productID string) error

Delete removes the image identified by a given ID.

func (Core) Query

func (c Core) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Image, error)

Query gets all Products from the database.

func (Core) QueryByID

func (c Core) QueryByID(ctx context.Context, productID string) (Image, error)

QueryByID finds the image identified by a given ID.

func (Core) QueryByUserID

func (c Core) QueryByUserID(ctx context.Context, userID string) ([]Image, error)

QueryByUserID finds the products identified by a given User ID.

func (Core) Update

func (c Core) Update(ctx context.Context, productID string, up UpdateImage, now time.Time) error

Update modifies data about a Product. It will error if the specified ID is invalid or does not reference an existing Product.

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

type UpdateImage struct {
	ImageURL *string `json:"image_url"`
	UserID   *string `json:"user_id"`
}

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.

Directories

Path Synopsis
Package db contains image related CRUD functionality.
Package db contains image related CRUD functionality.

Jump to

Keyboard shortcuts

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