jsonapi

package
v0.0.0-...-7fd672d Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jsonapi provides JSON API responses and request binding for commodities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AreaData

type AreaData struct {
	ID         string       `json:"id,omitempty"`
	Type       string       `json:"type" example:"areas" enums:"areas"`
	Attributes *models.Area `json:"attributes"`
}

AreaData is an object that holds area data information.

func (*AreaData) Validate

func (lr *AreaData) Validate() error

type AreaRequest

type AreaRequest struct {
	Data *AreaData `json:"data"`
}

AreaRequest is an object that holds area data information.

func (*AreaRequest) Bind

func (lr *AreaRequest) Bind(r *http.Request) error

func (*AreaRequest) Validate

func (lr *AreaRequest) Validate() error

type AreaResponse

type AreaResponse struct {
	HTTPStatusCode int               `json:"-"` // http response status code
	Data           *AreaResponseData `json:"data"`
}

func NewAreaResponse

func NewAreaResponse(area *models.Area) *AreaResponse

func (*AreaResponse) Render

func (rd *AreaResponse) Render(w http.ResponseWriter, r *http.Request) error

func (*AreaResponse) WithStatusCode

func (rd *AreaResponse) WithStatusCode(statusCode int) *AreaResponse

type AreaResponseData

type AreaResponseData struct {
	ID         string      `json:"id"`
	Type       string      `json:"type" example:"areas" enums:"areas"`
	Attributes models.Area `json:"attributes"`
}

AreaResponseData is an object that holds area information.

type AreasMeta

type AreasMeta struct {
	Areas int `json:"areas" example:"1" format:"int64"`
}

AreasMeta is a meta information for AreasResponse.

type AreasResponse

type AreasResponse struct {
	Data []AreaData `json:"data"`
	Meta AreasMeta  `json:"meta"`
}

AreasResponse is an object that holds area list information.

func NewAreasResponse

func NewAreasResponse(areas []*models.Area, total int) *AreasResponse

func (*AreasResponse) Render

func (rd *AreasResponse) Render(w http.ResponseWriter, r *http.Request) error

type CommoditiesMeta

type CommoditiesMeta struct {
	Commodities int `json:"commodities" example:"1" format:"int64"`
}

CommoditiesMeta is a meta information for CommoditiesResponse.

type CommoditiesResponse

type CommoditiesResponse struct {
	Data []CommodityData `json:"data"`
	Meta CommoditiesMeta `json:"meta"`
}

CommoditiesResponse is an object that holds a list of commodities information.

func NewCommoditiesResponse

func NewCommoditiesResponse(commodities []*models.Commodity, total int) *CommoditiesResponse

NewCommoditiesResponse creates a new CommoditiesResponse instance.

func (*CommoditiesResponse) Render

Render renders the CommoditiesResponse as an HTTP response.

type CommodityData

type CommodityData struct {
	ID         string            `json:"id,omitempty"`
	Type       string            `json:"type" example:"commodities" enums:"commodities"`
	Attributes *models.Commodity `json:"attributes"`
}

CommodityData is an object that holds commodity data information.

func (*CommodityData) Validate

func (cd *CommodityData) Validate() error

type CommodityMeta

type CommodityMeta struct {
	Images        []string `json:"images"`
	Manuals       []string `json:"manuals"`
	Invoices      []string `json:"invoices"`
	ImagesError   string   `json:"images_error,omitempty"`
	ManualsError  string   `json:"manuals_error,omitempty"`
	InvoicesError string   `json:"invoices_error,omitempty"`
}

func (*CommodityMeta) MarshalJSON

func (a *CommodityMeta) MarshalJSON() ([]byte, error)

type CommodityRequest

type CommodityRequest struct {
	Data *CommodityData `json:"data"`
}

CommodityRequest is an object that holds commodity data information.

func (*CommodityRequest) Bind

func (cr *CommodityRequest) Bind(r *http.Request) error

Bind binds the commodity data from the request to the CommodityRequest object.

func (*CommodityRequest) Validate

func (cr *CommodityRequest) Validate() error

Validate validates the commodity request data.

type CommodityResponse

type CommodityResponse struct {
	HTTPStatusCode int                    `json:"-"` // HTTP response status code
	Data           *CommodityResponseData `json:"data"`
}

CommodityResponse is an object that holds commodity information.

func NewCommodityResponse

func NewCommodityResponse(commodity *models.Commodity, meta *CommodityMeta) *CommodityResponse

NewCommodityResponse creates a new CommodityResponse instance.

func (*CommodityResponse) Render

Render renders the CommodityResponse as an HTTP response.

func (*CommodityResponse) WithStatusCode

func (cr *CommodityResponse) WithStatusCode(statusCode int) *CommodityResponse

WithStatusCode sets the HTTP response status code for the CommodityResponse.

type CommodityResponseData

type CommodityResponseData struct {
	ID         string            `json:"id"`
	Type       string            `json:"type" example:"commodities" enums:"commodities"`
	Attributes *models.Commodity `json:"attributes"`
	Meta       *CommodityMeta    `json:"meta"`
}

CommodityResponseData is an object that holds commodity information.

type Error

type Error struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string          `json:"status"`                               // user-level status message
	UserError  json.RawMessage `json:"error,omitempty" swaggertype:"object"` // user-level error message

}

Error renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

type Errors

type Errors struct {
	HTTPStatusCode int     `json:"-"` // http response status code
	Errors         []Error `json:"errors"`
}

func NewErrors

func NewErrors(errs ...Error) *Errors

func (*Errors) Render

func (e *Errors) Render(w http.ResponseWriter, r *http.Request) error

type ImageResponse

type ImageResponse struct {
	HTTPStatusCode int `json:"-"` // HTTP response status code

	ID         string       `json:"id"`
	Type       string       `json:"type" example:"images" enums:"images"`
	Attributes models.Image `json:"attributes"`
}

ImageResponse is an object that holds image information.

func NewImageResponse

func NewImageResponse(image *models.Image) *ImageResponse

NewImageResponse creates a new ImageResponse instance.

func (*ImageResponse) Render

func (ir *ImageResponse) Render(w http.ResponseWriter, r *http.Request) error

Render renders the ImageResponse as an HTTP response.

func (*ImageResponse) WithStatusCode

func (ir *ImageResponse) WithStatusCode(statusCode int) *ImageResponse

WithStatusCode sets the HTTP response status code for the ImageResponse.

type ImagesMeta

type ImagesMeta struct {
	Images int `json:"images" example:"1" format:"int64"`
}

ImagesMeta is a meta information for ImagesResponse.

type ImagesResponse

type ImagesResponse struct {
	Data []*models.Image `json:"data"`
	Meta ImagesMeta      `json:"meta"`
}

ImagesResponse is an object that holds a list of image information.

func NewImagesResponse

func NewImagesResponse(images []*models.Image, total int) *ImagesResponse

NewImagesResponse creates a new ImagesResponse instance.

func (*ImagesResponse) Render

func (ir *ImagesResponse) Render(w http.ResponseWriter, r *http.Request) error

Render renders the ImagesResponse as an HTTP response.

type InvoiceResponse

type InvoiceResponse struct {
	HTTPStatusCode int `json:"-"` // HTTP response status code

	ID         string         `json:"id"`
	Type       string         `json:"type" example:"invoices" enums:"invoices"`
	Attributes models.Invoice `json:"attributes"`
}

InvoiceResponse is an object that holds invoice information.

func NewInvoiceResponse

func NewInvoiceResponse(invoice *models.Invoice) *InvoiceResponse

NewInvoiceResponse creates a new InvoiceResponse instance.

func (*InvoiceResponse) Render

Render renders the InvoiceResponse as an HTTP response.

func (*InvoiceResponse) WithStatusCode

func (ir *InvoiceResponse) WithStatusCode(statusCode int) *InvoiceResponse

WithStatusCode sets the HTTP response status code for the InvoiceResponse.

type InvoicesMeta

type InvoicesMeta struct {
	Invoices int `json:"invoices" example:"1" format:"int64"`
}

InvoicesMeta is a meta information for InvoicesResponse.

type InvoicesResponse

type InvoicesResponse struct {
	Data []*models.Invoice `json:"data"`
	Meta InvoicesMeta      `json:"meta"`
}

InvoicesResponse is an object that holds a list of invoice information.

func NewInvoicesResponse

func NewInvoicesResponse(invoices []*models.Invoice, total int) *InvoicesResponse

NewInvoicesResponse creates a new InvoicesResponse instance.

func (*InvoicesResponse) Render

Render renders the InvoicesResponse as an HTTP response.

type Location

type Location struct {
	*models.Location
	Areas []string `json:"areas"`
}

type LocationData

type LocationData struct {
	ID         string           `json:"id,omitempty"`
	Type       string           `json:"type" example:"locations" enums:"locations"`
	Attributes *models.Location `json:"attributes"`
}

LocationData is an object that holds location data information.

func (*LocationData) Validate

func (ld *LocationData) Validate() error

type LocationRequest

type LocationRequest struct {
	Data *LocationData `json:"data"`
}

func (*LocationRequest) Bind

func (lr *LocationRequest) Bind(r *http.Request) error

func (*LocationRequest) Validate

func (lr *LocationRequest) Validate() error

type LocationResponse

type LocationResponse struct {
	HTTPStatusCode int                   `json:"-"` // http response status code
	Data           *LocationResponseData `json:"data"`
}

func NewLocationResponse

func NewLocationResponse(location *Location) *LocationResponse

func (*LocationResponse) Render

func (*LocationResponse) WithStatusCode

func (rd *LocationResponse) WithStatusCode(statusCode int) *LocationResponse

type LocationResponseData

type LocationResponseData struct {
	ID         string    `json:"id"`
	Type       string    `json:"type" example:"locations" enums:"locations"`
	Attributes *Location `json:"attributes"`
}

LocationResponseData is an object that holds location information.

type LocationsMeta

type LocationsMeta struct {
	Locations int `json:"locations" example:"1" format:"int64"`
}

LocationsMeta is a meta information for LocationsResponse.

type LocationsResponse

type LocationsResponse struct {
	Data []LocationData `json:"data"`
	Meta LocationsMeta  `json:"meta"`
}

LocationsResponse is an object that holds location list information.

func NewLocationsResponse

func NewLocationsResponse(locations []*models.Location, total int) *LocationsResponse

func (*LocationsResponse) Render

type ManualResponse

type ManualResponse struct {
	HTTPStatusCode int `json:"-"` // HTTP response status code

	ID         string        `json:"id"`
	Type       string        `json:"type" example:"manuals" enums:"manuals"`
	Attributes models.Manual `json:"attributes"`
}

ManualResponse is an object that holds manual information.

func NewManualResponse

func NewManualResponse(manual *models.Manual) *ManualResponse

NewManualResponse creates a new ManualResponse instance.

func (*ManualResponse) Render

func (mr *ManualResponse) Render(w http.ResponseWriter, r *http.Request) error

Render renders the ManualResponse as an HTTP response.

func (*ManualResponse) WithStatusCode

func (mr *ManualResponse) WithStatusCode(statusCode int) *ManualResponse

WithStatusCode sets the HTTP response status code for the ManualResponse.

type ManualsMeta

type ManualsMeta struct {
	Manuals int `json:"manuals" example:"1" format:"int64"`
}

ManualsMeta is a meta information for ManualsResponse.

type ManualsResponse

type ManualsResponse struct {
	Data []*models.Manual `json:"data"`
	Meta ManualsMeta      `json:"meta"`
}

ManualsResponse is an object that holds a list of manual information.

func NewManualsResponse

func NewManualsResponse(manuals []*models.Manual, total int) *ManualsResponse

NewManualsResponse creates a new ManualsResponse instance.

func (*ManualsResponse) Render

Render renders the ManualsResponse as an HTTP response.

type UploadData

type UploadData struct {
	Type      string   `json:"type" example:"images"`
	FileNames []string `json:"fileNames"`
}

UploadData is an object that holds upload data information.

type UploadResponse

type UploadResponse struct {
	HTTPStatusCode int `json:"-"` // HTTP response status code

	ID         string     `json:"id"`
	Type       string     `json:"type" example:"uploads" enums:"uploads"`
	Attributes UploadData `json:"attributes"`
}

UploadResponse is an object that holds upload information.

func NewUploadResponse

func NewUploadResponse(entityID string, uploadData UploadData) *UploadResponse

NewUploadResponse creates a new UploadResponse instance.

func (*UploadResponse) Render

func (cr *UploadResponse) Render(w http.ResponseWriter, r *http.Request) error

Render renders the UploadResponse as an HTTP response.

func (*UploadResponse) WithStatusCode

func (cr *UploadResponse) WithStatusCode(statusCode int) *UploadResponse

WithStatusCode sets the HTTP response status code for the UploadResponse.

Jump to

Keyboard shortcuts

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