route

package
v0.0.0-...-234aa62 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2014 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOne

func CreateOne(investment model.InvestmentRequest, params martini.Params,
	sesh *mgo.Database, r render.Render)

CreateOne is the handler for when a new resource is being created with a POST request. It will take an Investment model and return the investment model after it was inserted as JSON.

func DeleteOne

func DeleteOne(params martini.Params, sesh *mgo.Database, r render.Render)

DeleteOne will take an id from the url params and request that the resource be deleted from the database. Returns a 404 response if the resource was not found, a 500 for other errors and a success response with no data on success.

curl -i -H "Accept: application/json" -X DELETE http://localhost:49182/api/v0/investment/{id}

func GetMultiple

func GetMultiple(req *http.Request, sesh *mgo.Database, r render.Render)

GetMultiple will get multiple resources. It will look for query params and get by query params if valid ones exist. Otherwise it will get all investments. curl -i -H "Accept: application/json"

http://localhost:49182/api/v0/investments
http://localhost:49182/api/v0/investments?cap=20&price=15
http://localhost:49182/api/v0/investments?group-name=test

func GetOne

func GetOne(params martini.Params, sesh *mgo.Database, r render.Render)

GetOne will attempt to find a resource by id in the database and return it if exists, 404 error if it doesn't.

curl -i -H "Accept: application/json" http://localhost:49182/api/v0/investment/{id}

func GetOneByName

func GetOneByName(params martini.Params,
	sesh *mgo.Database, r render.Render)

GetOneByName takes martini params and a database session and returns one Group model. Should search for the one by name which should be present in params.

func GetOneBySymbol

func GetOneBySymbol(req *http.Request, sesh *mgo.Database, r render.Render)

GetOneBySymbol will attempt to find a resource by symbol name in the database and return it if exists, 404 error if it doesn't.

curl -i -H "Accept: application/json"

http://localhost:49182/api/v0/investment?symbol={symbol}

func InitGroupRoutes

func InitGroupRoutes(api martini.Router, db *mgo.Database) (
	martini.Router, error)

InitGroupRoutes Initializes all routes for the group schema. Takes a router to add routes to and config for the api. Returns the same router with new routes added.

func InitHomeRoutes

func InitHomeRoutes(api martini.Router, config map[string]string) (
	martini.Router, error)

func InitInvestmentRoutes

func InitInvestmentRoutes(api martini.Router, db *mgo.Database) (
	martini.Router, error)

InitInvestmentRoutes Initializes all routes for the investment schema. Takes a router to add routes to and config for the api. Returns the same router with new routes added.

func ResponseBadRequest

func ResponseBadRequest(err error) (int, map[string]interface{})

func ResponseCreated

func ResponseCreated(resource interface{}, resourceName string) (int,
	map[string]interface{})

ResponseCreated takes a resource of any type, a resource name and returns the 201 created status code with a map of data to send back as json.

func ResponseInternalServerError

func ResponseInternalServerError(err error) (int, map[string]interface{})

func ResponseNotFound

func ResponseNotFound() (int, map[string]interface{})

func ResponseSuccess

func ResponseSuccess(resource interface{}, resourceName string) (int,
	map[string]interface{})

func ResponseSuccessNoData

func ResponseSuccessNoData() (int, map[string]interface{})

ResponseSuccessNoData will return a 200 success response for when no data has to be sent back to the client. The struct will still include a data attribute for consistency.

func TransformQueryToMapping

func TransformQueryToMapping(query url.Values) (map[string]interface{}, []error)

TransformQueryToMapping will transform a url query to a mapping that is searchable in the database.

func UpdateOne

func UpdateOne(toUpdateInvestment model.Investment, params martini.Params,
	sesh *mgo.Database, r render.Render)

UpdateOne will take an id from the url params and a json object from the PUT data and will update the resource in the database. If the resource to update is not found, it will return a Not Found error, otherwise an internal error.

curl -i -H "Accept: application/json" -X PUT -d '{"symbol": "YHOO"}' http://localhost:49182/api/v0/investment/{id}

Types

This section is empty.

Jump to

Keyboard shortcuts

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