ducky/devices
18:b2fdf827758e
Go to Latest
ducky/devices/apiv1/endpoints.go
Add endpoint for retrieving devices.
Add an endpoint for retrieving devices, either as a list or by ID.
Stub endpoints for updating and deleting devices., along with TODOs marking them
as things to still be completed. (Right now, accessing those endpoints is an
insta-panic.)
Simplify our handleCreateDevices by returning StatusUnauthorized if AuthUser
fails, so we can reserve StatusForbidden for when auth succeeds but access is
still denied. Also, delay the instantiation and allocation of a Response
variable until we're actually going to use it.
Create a handleGetDevices handler that authenticates the user, and if no ID is
set, returns a list of all their Devices. If one or more IDs are set, only those
Devices are returned. If ScopeViewPushToken is one of the scopes associated with
the request, the push tokens for each Device will be included in the response.
Otherwise, they will be omitted.
6 "code.secondbit.org/api.hg"
7 "code.secondbit.org/trout.hg"
8 "golang.org/x/net/context"
11 // GetRouter returns a trout Router that is configured to handle
12 // all the routes necessary to serve a devices API server.
13 func GetRouter(ctx context.Context) http.Handler {
14 var router trout.Router
15 router.Endpoint("/").Methods("POST").Handler(api.ContextWrapper(ctx, api.ContextHandler(handleCreateDevices)))
16 router.Endpoint("/").Methods("GET").Handler(api.ContextWrapper(ctx, api.ContextHandler(handleGetDevices)))
17 router.Endpoint("/{id}").Methods("GET").Handler(api.ContextWrapper(ctx, api.ContextHandler(handleGetDevices)))
18 // TODO(paddy): add the update handler
19 router.Endpoint("/{id}").Methods("PATCH").Handler(api.ContextWrapper(ctx, api.ContextHandler(nil)))
20 // TODO(paddy): add the delete handler
21 router.Endpoint("/").Methods("DELETE").Handler(api.ContextWrapper(ctx, api.ContextHandler(nil)))
22 router.Endpoint("/{id}").Methods("DELETE").Handler(api.ContextWrapper(ctx, api.ContextHandler(nil)))