validation

package
v0.0.0-...-ae1d368 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCollection

func CreateCollection(collection *model.Collection, userID int64, store store.Store) (int64, error)

CreateCollection tries to create a collection and returns a validation error or regular error if the creation fails

func CreatePosition

func CreatePosition(position *model.Position, userID int64, store store.Store) (int64, error)

CreatePosition tries to create a position and returns a validation error or regular error if the creation fails

func CreateShapeCollection

func CreateShapeCollection(shapeCollection *model.ShapeCollection, userID int64, store store.Store) (int64, error)

CreateShapeCollection tries to create a shape collection and returns a validation error or regular error if the creation fails

func CreateSubscription

func CreateSubscription(subscription *service.Subscription, userID int64, store store.Store) (int64, error)

CreateSubscription tries to create a collection and returns a validation error or regular error if the creation fails

func CreateTeam

func CreateTeam(team *model.Team, store store.Store) (int64, error)

CreateTeam tries to create a team and returns a regular error if the creation fails

func CreateToken

func CreateToken(collection *model.Token, store store.Store) (string, error)

CreateToken tries to create a token and returns a regular error if the creation fails

func CreateTracker

func CreateTracker(tracker *model.Tracker, userID int64, store store.Store) (int64, error)

CreateTracker tries to create a tracker and returns a validation error or regular error if the creation fails

func DeleteCollection

func DeleteCollection(collectionID int64, userID int64, store store.Store) error

DeleteCollection tries to delete a collection and returns a validation error or regular error if the delete fails

func DeletePosition

func DeletePosition(positionID int64, userID int64, store store.Store) error

DeletePosition tries to delete a position and returns a validation error or regular error if the delete fails

func DeleteShapeCollection

func DeleteShapeCollection(shapeCollectionID int64, userID int64, store store.Store) error

DeleteShapeCollection tries to delete a collection and returns a validation error or regular error if the delete fails

func DeleteSubscription

func DeleteSubscription(subscriptionID int64, userID int64, store store.Store) error

DeleteSusbcription tries to delete a subscription and returns a validation error or regular error if the delete fails

func DeleteTeam

func DeleteTeam(teamID int64, userID int64, store store.Store) error

DeleteTeam tries to delete a team and returns a validation error or regular error if the delete fails

func DeleteToken

func DeleteToken(tokenID string, userID int64, store store.Store) error

DeleteToken tries to delete a token and returns a validation error or regular error if the delete fails

func DeleteTracker

func DeleteTracker(trackerID int64, userID int64, store store.Store) error

DeleteTracker tries to delete a tracker and returns a validation error or regular error if the delete fails

func GetCollection

func GetCollection(collectionID int64, userId int64, store store.Store) (*service.Collection, error)

GetCollection returns a collection from store. Returns a validation error or regular error if the fetch fails.

func GetCollectionFromBody

func GetCollectionFromBody(body io.ReadCloser) (*service.Collection, error)

GetCollectionFromBody retrieves a collection from given body and decodes it. Returns a validation error containing an ErrorResponse if something went wrong

func GetCollectionFromHandlerParams

func GetCollectionFromHandlerParams(handlerParams HandlerParameterMap, userId int64, store store.Store) (*service.Collection, error)

GetCollectionFromHandlerParams validates collection ID (if) found in params and returns a collection from store. Returns a validation error containing an ErrorResponse if something went wrong

func GetCollectionID

func GetCollectionID(handlerParams HandlerParameterMap) (int64, error)

GetCollectionID returns a collectionID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetPosition

func GetPosition(positionID int64, userId int64, store store.Store) (*service.Position, error)

GetPosition returns a position from store. Returns a validation error or regular error if the fetch fails.

func GetPositionFromBody

func GetPositionFromBody(body io.ReadCloser) (*service.Position, error)

GetPositionFromBody retrieves a position from given body and decodes it. Returns a validation error containing an ErrorResponse if something went wrong

func GetPositionFromHandlerParams

func GetPositionFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*service.Position, error)

GetPositionFromHandlerParams validates position (if) found in params and returns a position from store. Returns a validation error containing an ErrorResponse if something went wrong

func GetPositionID

func GetPositionID(handlerParams HandlerParameterMap) (int64, error)

GetPositionID returns a positionID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetShape

func GetShape(shapeCollectionID int64, shapeID int64, userID int64, store store.Store) (*service.Shape, error)

GetShape returns a shape from store. Returns a validation error or regular error if the fetch fails.

func GetShapeCollection

func GetShapeCollection(shapeCollectionID int64, userID int64, store store.Store) (*service.ShapeCollection, error)

GetShapeCollection returns a shape collection from store. Returns a validation error or regular error if the fetch fails.

func GetShapeCollectionFromBody

func GetShapeCollectionFromBody(body io.ReadCloser) (*service.ShapeCollection, error)

GetShapeCollectionFromBody retrieves shape-collection from given body. Returns a validation error or regular error if the fetch fails.

func GetShapeCollectionFromHandlerParams

func GetShapeCollectionFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*service.ShapeCollection, error)

GetShapeCollectionFromHandlerParams validates shape collection (if) found in params and returns a shape collection from store. Returns a validation error containing an ErrorResponse based on what went wrong

func GetShapeCollectionID

func GetShapeCollectionID(handlerParams HandlerParameterMap) (int64, error)

GetShapeCollectionID returns a ShapeCollectionID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetShapeFromBody

func GetShapeFromBody(body io.ReadCloser) (geometry.Shape, error)

ValidateAndGetShapeFromBody retrieves shapes from a GeoJSON Feature in given body, decodes it and performs a triangulation on the given Feature Returns a validation error containing an ErrorResponse if something went wrong

func GetShapeFromHandlerParams

func GetShapeFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*service.Shape, error)

GetShapeFromHandlerParams validates shape (if) found in params and returns a shape from store. Returns a validation error containing an ErrorResponse based on what went wrong

func GetShapeGeoJSON

func GetShapeGeoJSON(shapeCollectionID int64, shapeID int64, userID int64, store store.Store) (*geojson.Feature, error)

GetShape returns a shape from store. Returns a validation error or regular error if the fetch fails.

func GetShapeGeoJSONFromHandlerParams

func GetShapeGeoJSONFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*geojson.Feature, error)

GetShapeFromHandlerParams validates shape (if) found in params and returns a GeoJSON Feature belonging to the shape from store. Returns a validation error containing an ErrorResponse based on what went wrong

func GetShapeID

func GetShapeID(handlerParams HandlerParameterMap) (int64, error)

GetShapeID returns a shapeID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetShapesAsFeatureCollection

func GetShapesAsFeatureCollection(shapeCollectionID int64, userID int64, filterParams FilterParams, store store.Store) (geojson.FeatureCollection, error)

GetShapesAsFeatureCollection returns a feature collection based on shapeCollectionID and userID and returns a store error if the list fails

func GetShapesFromBody

func GetShapesFromBody(body io.ReadCloser) ([]geometry.Shape, error)

GetShapesFromBody retrieves shapes from a FeatureCollection in given body, decodes it and performs a triangulation on the given geojson Features Returns a validation error containing an ErrorResponse if something went wrong

func GetSubscription

func GetSubscription(subscriptionID int64, userId int64, store store.Store) (*service.Subscription, error)

GetSubscription returns a subscription from store. Returns a validation error or regular error if the fetch fails.

func GetSubscriptionFromBody

func GetSubscriptionFromBody(body io.ReadCloser) (*service.Subscription, error)

GetSubscriptionFromBody retrieves a subscription from given body and decodes it. Returns a validation error containing an ErrorResponse if something went wrong

func GetSubscriptionFromHandlerParams

func GetSubscriptionFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*service.Subscription, error)

GetSubscriptionFromHandlerParams validates subscription (if) found in params and returns a subscription from store. Returns a validation error containing an ErrorResponse if something went wrong

func GetSubscriptionID

func GetSubscriptionID(handlerParams HandlerParameterMap) (int64, error)

GetSubscriptionID returns a SubscriptionID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetTeam

func GetTeam(teamID int64, userID int64, store store.Store) (*service.Team, error)

GetTeam validates team (if) found in params and returns a team from store. Returns a validation error containing an ErrorResponse based on what went wrong

func GetTeamFromHandlerParams

func GetTeamFromHandlerParams(handlerParams HandlerParameterMap, userId int64, store store.Store) (*service.Team, error)

GetTeamFromHandlerParams validates team ID (if) found in params and returns a team from store. Returns a validation error containing an ErrorResponse if something went wrong

func GetTeamID

func GetTeamID(handlerParams HandlerParameterMap) (int64, error)

GetTeamID returns a teamID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetToken

func GetToken(tokenID string, userId int64, store store.Store) (*service.Token, error)

GetToken returns a token from store. Returns a validation error or regular error if the fetch fails.

func GetTokenFromBody

func GetTokenFromBody(body io.ReadCloser) (*service.Token, error)

GetTokenFromBody retrieves a token from given body and decodes it. Returns a validation error containing an ErrorResponse if something went wrong

func GetTokenFromHandlerParams

func GetTokenFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*service.Token, error)

GetTokenFromHandlerParams validates token (if) found in params and returns a token from store. Returns a validation error containing an ErrorResponse if something went wrong

func GetTokenID

func GetTokenID(handlerParams HandlerParameterMap) (string, error)

GetTokenID returns a tokenID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func GetTracker

func GetTracker(trackerID int64, userId int64, store store.Store) (*service.Tracker, error)

GetTracker returns a tracker from store. Returns a validation error or regular error if the fetch fails.

func GetTrackerFromBody

func GetTrackerFromBody(body io.ReadCloser) (*service.Tracker, error)

GetTrackerFromBody retrieves a tracker from given body and decodes it. Returns a validation error containing an ErrorResponse if something went wrong

func GetTrackerFromHandlerParams

func GetTrackerFromHandlerParams(handlerParams HandlerParameterMap, userID int64, store store.Store) (*service.Tracker, error)

GetTrackerFromHandlerParams validates tracker (if) found in params and returns a tracker from store. Returns a validation error containing an ErrorResponse if something went wrong

func GetTrackerID

func GetTrackerID(handlerParams HandlerParameterMap) (int64, error)

GetTrackerID returns a trackerID from given HandlerParameterMap. If missing or corrupt, returns a validationError

func ListCollections

func ListCollections(userID int64, filterParams FilterParams, store store.Store) ([]*service.Collection, error)

ListCollections lists collections based on userID and returns a store error if the list fails

func ListPositionsByTrackerID

func ListPositionsByTrackerID(trackerID int64, userID int64, filterParams FilterParams, store store.Store) ([]*service.Position, error)

ListPositionsByTrackerID lists collections based on userID and returns a store error if the list fails

func ListShapeCollections

func ListShapeCollections(userID int64, filterParams FilterParams, store store.Store) ([]*service.ShapeCollection, error)

ListShapeCollections lists shape collections based on userID and returns a store error if the list fails

func ListShapes

func ListShapes(shapeCollectionID int64, userID int64, filterParams FilterParams, store store.Store) ([]*service.Shape, error)

ListShapes lists the shapes in a shape collection based on given filters. Returns a validation error if the list fails.

func ListSubscriptions

func ListSubscriptions(userID int64, filterParams FilterParams, store store.Store) ([]*service.Subscription, error)

ListSubscriptions lists subscriptions based on userID and returns a store error if the list fails

func ListSubscriptionsByCollectionID

func ListSubscriptionsByCollectionID(collectionID int64, userID int64, filterParams FilterParams, store store.Store) ([]*service.Subscription, error)

ListSubscriptionsByCollectionID lists subscriptions based on userID and trackerID and returns a store error if the list fails

func ListSubscriptionsByTrackerID

func ListSubscriptionsByTrackerID(trackerID int64, userID int64, filterParams FilterParams, store store.Store) ([]*service.Subscription, error)

ListSubscriptionsByTrackerID lists subscriptions based on userID and trackerID and returns a store error if the list fails

func ListTeams

func ListTeams(userID int64, filterParams FilterParams, store store.Store) ([]*service.Team, error)

ListTeams lists teams based on userID and returns a store error if the list fails

func ListTokens

func ListTokens(userID int64, filterParams FilterParams, store store.Store) ([]*service.Token, error)

ListTokens lists tokens based on userID and returns a store error if the list fails

func ListTrackersByCollectionID

func ListTrackersByCollectionID(collectionID int64, userID int64, filterParams FilterParams, store store.Store) ([]*service.Tracker, error)

ListCollections lists collections based on userID and returns a store error if the list fails

func ReplaceShapesInShapeCollection

func ReplaceShapesInShapeCollection(shapeCollectionID int64, userID int64, shapes []*model.Shape, store store.Store) error

ReplaceShapesInShapeCollection takes in a list and replaces the existing shapes in an existing shape collection. Returns a validation error if the update and replace fails

func SetTeamMember

func SetTeamMember(userID int64, teamID int64, admin bool, store store.Store) error

SetTeamMember sets a user - team relation and returns a regular error if the connection fails

func UpdateCollection

func UpdateCollection(collection *model.Collection, userID int64, store store.Store) error

UpdateCollection tries to update a collection and returns a validation error or regular error if the update fails

func UpdateShape

func UpdateShape(shape *model.Shape, userID int64, store store.Store) error

UpdateShape tries to update a shape and returns a validation error or regular error if the update fails

func UpdateShapeCollection

func UpdateShapeCollection(shapeCollection *model.ShapeCollection, userID int64, store store.Store) error

UpdateShapeCollection tries to update a shape collection and returns a validation error or regular error if the update fails

func UpdateSubscription

func UpdateSubscription(subscription *service.Subscription, userID int64, store store.Store) error

UpdateSubscription tries to update a subscription and returns a validation error or regular error if the update fails

func UpdateTeam

func UpdateTeam(team *model.Team, userID int64, store store.Store) error

UpdateTeam tries to update a team and returns a validation error or regular error if the update fails

func UpdateToken

func UpdateToken(token *model.Token, store store.Store) error

UpdateToken tries to update a token and returns a validation error or regular error if the update fails

func UpdateTracker

func UpdateTracker(tracker *model.Tracker, userID int64, store store.Store) error

UpdateTracker tries to update a tracker and returns a validation error or regular error if the update fails

func ValidateAndGetTeamFromBody

func ValidateAndGetTeamFromBody(body io.ReadCloser) (*service.Team, error)

ValidateAndGetTeamFromBody retrieves a team from given body and decodes it. Returns a validation error containing an ErrorResponse if something went wrong

Types

type Error

type Error struct {
	ErrorResponse *ErrorResponse
}

Error is an error who occured when trying to validate an entity It contains an ErrorResponse which can be used to write an http error message

func (*Error) Error

func (validationError *Error) Error() string

type ErrorDetail

type ErrorDetail struct {
	Field  string `json:"field"`
	Reason string `json:"reason"`
}

ErrorDetail details an error

func NewParameterErrorDetail

func NewParameterErrorDetail(field, reason string) ErrorDetail

NewParameterErrorDetail returns an error struct containing which field and the reason behind the error

func (*ErrorDetail) MarshalJSON

func (errorDetail *ErrorDetail) MarshalJSON() ([]byte, error)

MarshalJSON marshals a JSON string from the ErrorResponse

type ErrorResponse

type ErrorResponse struct {
	Title   string        `json:"title"`
	Detail  string        `json:"detail,omitempty"`
	Status  int           `json:"status"`
	Type    string        `json:"type"`
	Details []ErrorDetail `json:"details,omitempty"`
}

ErrorResponse is a generic response type for errors in HTTP requests

func NewErrorResponse

func NewErrorResponse(statusCode int, details ...ErrorDetail) *ErrorResponse

NewErrorResponse returns a new ErrorResponse based on given status code and details

func (*ErrorResponse) MarshalJSON

func (errorResponse *ErrorResponse) MarshalJSON() ([]byte, error)

MarshalJSON marshals a JSON string from the ErrorResponse

func (*ErrorResponse) WriteHTTPError

func (errorResponse *ErrorResponse) WriteHTTPError(writer http.ResponseWriter)

WriteHTTPError writes error to a writer as JSON

type FilterParams

type FilterParams struct {
	Since  int64
	Until  int64
	Limit  int64
	Offset int64
}

FilterParams contains parameters regarding listing normal list parameters

func NewFilterParamsFromQueryParams

func NewFilterParamsFromQueryParams(values url.Values) (FilterParams, error)

NewFilterParamsFromQueryParams returns FilterParams from given Query values. It returns a validation error if invalid filter paramters is provided

type HandlerParameterMap

type HandlerParameterMap map[string]string

HandlerParameterMap is a list of parameter

func (*HandlerParameterMap) AsInt64

func (parameterMap *HandlerParameterMap) AsInt64(id string) (int64, error)

AsInt64 returns the parameter as an int64

func (*HandlerParameterMap) AsString

func (parameterMap *HandlerParameterMap) AsString(id string) (string, error)

AsIntString returns the parameter as an int64

func (*HandlerParameterMap) CollectionID

func (parameterMap *HandlerParameterMap) CollectionID() (int64, error)

CollectionID retrieves the collectionID from the parameterMap

func (*HandlerParameterMap) PositionID

func (parameterMap *HandlerParameterMap) PositionID() (int64, error)

PositionID retrieves the PositionID from the parameterMap

func (*HandlerParameterMap) ShapeCollectionID

func (parameterMap *HandlerParameterMap) ShapeCollectionID() (int64, error)

ShapeCollectionID retrieves the ShapeCollectionID from the parameterMap

func (*HandlerParameterMap) ShapeID

func (parameterMap *HandlerParameterMap) ShapeID() (int64, error)

ShapeID retrieves the ShapeID from the parameterMap

func (*HandlerParameterMap) SubscriptionID

func (parameterMap *HandlerParameterMap) SubscriptionID() (int64, error)

SubscriptionID retrieves the SubscriptionID from the parameterMap

func (*HandlerParameterMap) TeamID

func (parameterMap *HandlerParameterMap) TeamID() (int64, error)

TeamID retrieves the TeamID from the parameterMap

func (*HandlerParameterMap) TokenID

func (parameterMap *HandlerParameterMap) TokenID() (string, error)

TokenID retrieves the tokenID from the parameterMap

func (*HandlerParameterMap) TrackerID

func (parameterMap *HandlerParameterMap) TrackerID() (int64, error)

TrackerID retrieves the collectionID from the parameterMap

type KeyNotFoundError

type KeyNotFoundError struct {
	// contains filtered or unexported fields
}

KeyNotFoundError is a error returned when no parameter was found on the parameter map

func (*KeyNotFoundError) Error

func (parameterNotFoundError *KeyNotFoundError) Error() string

Jump to

Keyboard shortcuts

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