Make publicreport by ID base redirect to detailed information
This commit is contained in:
parent
4a28a16639
commit
fe41df3e16
4 changed files with 44 additions and 14 deletions
|
|
@ -23,6 +23,7 @@ type ErrorAPI struct {
|
|||
|
||||
var decoder = schema.NewDecoder()
|
||||
|
||||
type handlerBase func(context.Context, http.ResponseWriter, *http.Request) *nhttp.ErrorWithStatus
|
||||
type handlerFunctionDelete func(context.Context, *http.Request, platform.User) *nhttp.ErrorWithStatus
|
||||
type handlerFunctionGet[T any] func(context.Context, *http.Request, resource.QueryParams) (*T, *nhttp.ErrorWithStatus)
|
||||
type handlerFunctionGetAuthenticated[T any] func(context.Context, *http.Request, platform.User, resource.QueryParams) (*T, *nhttp.ErrorWithStatus)
|
||||
|
|
@ -190,6 +191,16 @@ func authenticatedHandlerPostMultipart[ResponseType any](f handlerFunctionPostAu
|
|||
w.Write(body)
|
||||
})
|
||||
}
|
||||
func handlerBasic(f handlerBase) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
e := f(ctx, w, r)
|
||||
if e != nil {
|
||||
respondErrorStatus(w, e)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
func handlerJSON[T any](f handlerFunctionGet[T]) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func AddRoutes(r *mux.Router) {
|
|||
r.Handle("/geocode/reverse", handlerJSONPost(geocode.Reverse)).Methods("POST")
|
||||
r.Handle("/geocode/suggestion", handlerJSONSlice(geocode.SuggestionList)).Methods("GET")
|
||||
publicreport := resource.Publicreport(router)
|
||||
r.Handle("/publicreport/{id}", handlerJSON(publicreport.ByID)).Methods("GET").Name("publicreport.ByIDGet")
|
||||
r.Handle("/publicreport/{id}", handlerBasic(publicreport.ByID)).Methods("GET").Name("publicreport.ByIDGet")
|
||||
r.Handle("/publicreport/compliance/{id}/image", handlerFormPost(publicreport.ImageCreate)).Methods("POST")
|
||||
r.Handle("/publicreport/compliance/{id}", handlerJSON(compliance.ByID)).Methods("GET").Name("publicreport.compliance.ByIDGet")
|
||||
r.Handle("/publicreport/compliance/{id}", handlerJSONPut(compliance.Update)).Methods("PUT")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue