resource

package
v0.0.0-...-b52bd72 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PostFilterableFields = map[string]bool{
	"id":         true,
	"created-at": false,
	"updated-at": false,
	"permalink":  true,
}

PostFilterableFields is a map of fields a post can sort or filter by, where the key is the jsonapi field name and the value is whether a filter should be performed using strict equality (true), or using a LIKE statement (false), in the SQL generated for the query

View Source
var PostRelationships = map[string]RelationshipFunc{
	"usersID": getPostsByUsersID,
}

PostRelationships defines the functions for modifying a Query to select...

View Source
var UserFilterableFields = map[string]bool{
	"id":         true,
	"created-at": false,
	"updated-at": false,
	"email":      true,
	"username":   true,
}

UserFilterableFields is a map of fields a user can sort or filter by, where the key is the jsonapi field name and the value is whether a filter should be performed using strict equality (true), or using a LIKE statement (false), in the SQL generated for the query

View Source
var UserRelationshipsByParam = map[string]RelationshipFunc{
	"postsID": getUsersByPostsID,
}

UserRelationshipsByParam defines a map where the key is the query param and the function is the RelationshipFunc for modifying the query to get the given relationship

Functions

func ParseQueryParams

func ParseQueryParams(r api2go.Request, filterableFields map[string]bool, relationshipsByParam map[string]RelationshipFunc) (*query.Query, error)

ParseQueryParams parses request for query params

Types

type PostResource

type PostResource struct {
	PostStorage *storage.PostStorage
}

PostResource defines interface to storage layer

func (PostResource) Create

func (s PostResource) Create(obj interface{}, r api2go.Request) (api2go.Responder, error)

Create method to satisfy `api2go.DataSource` interface

func (PostResource) Delete

func (s PostResource) Delete(id string, r api2go.Request) (api2go.Responder, error)

Delete to satisfy `api2go.DataSource` interface

func (PostResource) FindAll

func (s PostResource) FindAll(r api2go.Request) (api2go.Responder, error)

FindAll to satisfy api2go data source interface

func (PostResource) FindOne

func (s PostResource) FindOne(id string, r api2go.Request) (api2go.Responder, error)

FindOne to satisfy `api2go.DataSource` interface this method should return the post with the given ID, otherwise an error

func (PostResource) PaginatedFindAll

func (s PostResource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder, error)

PaginatedFindAll can be used to load posts in chunks

func (PostResource) Update

func (s PostResource) Update(obj interface{}, r api2go.Request) (api2go.Responder, error)

Update stores all changes on the post

type RelationshipFunc

type RelationshipFunc func(api2go.Request, *query.Query) *query.Query

RelationshipFunc defines the function type for modifying a Query to select a relationship

type Response

type Response struct {
	Res  interface{}
	Code int
}

Implementation of api2go.Responder

func (Response) Metadata

func (r Response) Metadata() map[string]interface{}

func (Response) Result

func (r Response) Result() interface{}

Result returns the actual payload

func (Response) StatusCode

func (r Response) StatusCode() int

StatusCode returns the HTTP status code

type UserResource

type UserResource struct {
	UserStorage *storage.UserStorage
}

UserResource defines interface to storage layer

func (UserResource) Create

func (s UserResource) Create(obj interface{}, r api2go.Request) (api2go.Responder, error)

Create method to satisfy `api2go.DataSource` interface

func (UserResource) Delete

func (s UserResource) Delete(id string, r api2go.Request) (api2go.Responder, error)

Delete to satisfy `api2go.DataSource` interface

func (UserResource) FindAll

func (s UserResource) FindAll(r api2go.Request) (api2go.Responder, error)

FindAll to satisfy api2go data source interface

func (UserResource) FindOne

func (s UserResource) FindOne(id string, r api2go.Request) (api2go.Responder, error)

FindOne to satisfy `api2go.DataSource` interface this method should return the user with the given ID, otherwise an error

func (UserResource) PaginatedFindAll

func (s UserResource) PaginatedFindAll(r api2go.Request) (uint, api2go.Responder, error)

PaginatedFindAll can be used to load users in chunks

func (UserResource) Update

func (s UserResource) Update(obj interface{}, r api2go.Request) (api2go.Responder, error)

Update stores all changes on the user

Jump to

Keyboard shortcuts

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