Restructuring users routes under genus
This commit is contained in:
parent
05ded17aec
commit
99b2ee94bf
1 changed files with 8 additions and 9 deletions
17
handlers.go
17
handlers.go
|
@ -77,26 +77,25 @@ func Handler() http.Handler {
|
||||||
characteristicTypeService := CharacteristicTypeService{}
|
characteristicTypeService := CharacteristicTypeService{}
|
||||||
measurementService := MeasurementService{}
|
measurementService := MeasurementService{}
|
||||||
|
|
||||||
// Non-auth routes
|
|
||||||
m.Handle("/authenticate", tokenHandler(j.GenerateToken())).Methods("POST")
|
m.Handle("/authenticate", tokenHandler(j.GenerateToken())).Methods("POST")
|
||||||
m.Handle("/users", errorHandler(handleCreater(userService))).Methods("POST")
|
|
||||||
m.Handle("/users/verify/{Nonce}", http.HandlerFunc(handleUserVerify)).Methods("GET")
|
|
||||||
|
|
||||||
// Auth routes
|
// Everything past here is lumped under a genus
|
||||||
m.Handle("/users", j.Secure(errorHandler(handleLister(userService)), verifyClaims)).Methods("GET")
|
|
||||||
m.Handle("/users/{Id:.+}", j.Secure(errorHandler(handleGetter(userService)), verifyClaims)).Methods("GET")
|
|
||||||
m.Handle("/users/{Id:.+}", j.Secure(errorHandler(handleUpdater(userService)), verifyClaims)).Methods("PUT")
|
|
||||||
|
|
||||||
// Path-based pattern matching subrouter
|
|
||||||
s := m.PathPrefix("/{genus}").Subrouter()
|
s := m.PathPrefix("/{genus}").Subrouter()
|
||||||
|
|
||||||
|
s.Handle("/users", errorHandler(handleCreater(userService))).Methods("POST")
|
||||||
|
s.Handle("/users/verify/{Nonce}", http.HandlerFunc(handleUserVerify)).Methods("GET")
|
||||||
|
|
||||||
type r struct {
|
type r struct {
|
||||||
f errorHandler
|
f errorHandler
|
||||||
m string
|
m string
|
||||||
p string
|
p string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Everything past this point requires a valid token
|
||||||
routes := []r{
|
routes := []r{
|
||||||
|
r{handleLister(userService), "GET", "/users"},
|
||||||
|
r{handleGetter(userService), "GET", "/users/{Id:.+}"},
|
||||||
|
r{handleUpdater(userService), "PUT", "/users/{Id:.+}"},
|
||||||
r{handleLister(speciesService), "GET", "/species"},
|
r{handleLister(speciesService), "GET", "/species"},
|
||||||
r{handleCreater(speciesService), "POST", "/species"},
|
r{handleCreater(speciesService), "POST", "/species"},
|
||||||
r{handleGetter(speciesService), "GET", "/species/{Id:.+}"},
|
r{handleGetter(speciesService), "GET", "/species/{Id:.+}"},
|
||||||
|
|
Reference in a new issue