api

package
v0.0.0-...-ade036e Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2018 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultImageStorageProvider = "local"
	DefaultDatabaseProvider     = "postgres"
)
View Source
const (
	// DefaultLimit is the number of results we will return per page if the user doesn't specify another amount
	DefaultLimit = 25
	// MaxLimit is the maximum number of objects Dairycart will return in a response
	MaxLimit = 50
)
View Source
const (
	ProductCreatedWebhookEvent  = "product_created"
	ProductUpdatedWebhookEvent  = "product_updated"
	ProductArchivedWebhookEvent = "product_archived"
)
View Source
const (
	// ValidURLCharactersPattern represents the valid characters a sku can contain
	ValidURLCharactersPattern = `[a-zA-Z\-_]+`
	// NumericPattern repesents numeric values
	NumericPattern = `[0-9]+`
)

Variables

This section is empty.

Functions

func InitializeServerComponents

func InitializeServerComponents(cfg *viper.Viper, config *ServerConfig) error

InitializeServerComponents calls Init on all the relevant server components, and migrates the database.

func LoadServerConfig

func LoadServerConfig(altCfgFilePath string) (*viper.Viper, error)

func SetupAPIRouter

func SetupAPIRouter(config *ServerConfig)

SetupAPIRouter takes a mux router and a database connection and creates all the API routes for the API

Types

type DisplayUser

type DisplayUser struct {
	ID         uint64            `json:"id"`
	FirstName  string            `json:"first_name"`
	LastName   string            `json:"last_name"`
	Email      string            `json:"email"`
	IsAdmin    bool              `json:"is_admin"`
	CreatedOn  time.Time         `json:"created_on"`
	UpdatedOn  *models.Dairytime `json:"updated_on,omitempty"`
	ArchivedOn *models.Dairytime `json:"archived_on,omitempty"`
}

DisplayUser represents a Dairycart user we can return in responses TODO: the main reason for doing this is so we don't end up returning the password hash to the user, but there's bound to be a way to reuse that struct

type ErrorResponse

type ErrorResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

ErrorResponse is a handy struct we can respond with in the event we have an error to report

type ListResponse

type ListResponse struct {
	Count uint64      `json:"count"`
	Limit uint8       `json:"limit"`
	Page  uint64      `json:"page"`
	Data  interface{} `json:"data"`
}

ListResponse is a generic list response struct containing values that represent pagination, meant to be embedded into other object response structs

type ProductCreationInput

type ProductCreationInput struct {
	models.Product
	Options []models.ProductOption `json:"options"`
}

ProductCreationInput is a struct that represents a product creation body

type ServerConfig

type ServerConfig struct {
	Router          *chi.Mux
	DB              *sql.DB
	CookieStore     *sessions.CookieStore
	DatabaseClient  database.Storer
	WebhookExecutor WebhookExecutor
	ImageStorer     images.ImageStorer
}

func BuildServerConfig

func BuildServerConfig(config *viper.Viper) (*ServerConfig, error)

type UserLoginInput

type UserLoginInput struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

UserLoginInput represents the payload used to log in a Dairycart user

type WebhookExecutor

type WebhookExecutor interface {
	CallWebhook(models.Webhook, interface{}, database.Querier, database.Storer)
}

Jump to

Keyboard shortcuts

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