Documentation ¶
Index ¶
- func CreateOne(investment model.InvestmentRequest, params martini.Params, sesh *mgo.Database, ...)
- func DeleteOne(params martini.Params, sesh *mgo.Database, r render.Render)
- func GetMultiple(req *http.Request, sesh *mgo.Database, r render.Render)
- func GetOne(params martini.Params, sesh *mgo.Database, r render.Render)
- func GetOneByName(params martini.Params, sesh *mgo.Database, r render.Render)
- func GetOneBySymbol(req *http.Request, sesh *mgo.Database, r render.Render)
- func InitGroupRoutes(api martini.Router, db *mgo.Database) (martini.Router, error)
- func InitHomeRoutes(api martini.Router, config map[string]string) (martini.Router, error)
- func InitInvestmentRoutes(api martini.Router, db *mgo.Database) (martini.Router, error)
- func ResponseBadRequest(err error) (int, map[string]interface{})
- func ResponseCreated(resource interface{}, resourceName string) (int, map[string]interface{})
- func ResponseInternalServerError(err error) (int, map[string]interface{})
- func ResponseNotFound() (int, map[string]interface{})
- func ResponseSuccess(resource interface{}, resourceName string) (int, map[string]interface{})
- func ResponseSuccessNoData() (int, map[string]interface{})
- func TransformQueryToMapping(query url.Values) (map[string]interface{}, []error)
- func UpdateOne(toUpdateInvestment model.Investment, params martini.Params, sesh *mgo.Database, ...)
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 InitInvestmentRoutes ¶
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 ResponseCreated ¶
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 ResponseNotFound ¶
func ResponseSuccess ¶
func ResponseSuccessNoData ¶
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 ¶
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.