Mave report ByID to their own resources
This commit is contained in:
parent
9b1de15373
commit
7e2a22c58c
4 changed files with 33 additions and 30 deletions
|
|
@ -85,8 +85,8 @@ func AddRoutes(r *mux.Router) {
|
|||
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")
|
||||
r.Handle("/publicreport/nuisance/{id}", handlerJSON(publicreport.ByIDNuisance)).Methods("GET").Name("publicreport.nuisance.ByIDGet")
|
||||
r.Handle("/publicreport/water/{id}", handlerJSON(publicreport.ByIDWater)).Methods("GET").Name("publicreport.water.ByIDGet")
|
||||
r.Handle("/publicreport/nuisance/{id}", handlerJSON(nuisance.ByID)).Methods("GET").Name("publicreport.nuisance.ByIDGet")
|
||||
r.Handle("/publicreport/water/{id}", handlerJSON(water.ByID)).Methods("GET").Name("publicreport.water.ByIDGet")
|
||||
|
||||
publicreport_notification := resource.PublicreportNotification(router)
|
||||
r.Handle("/publicreport-notification", handlerJSONPost(publicreport_notification.Create)).Methods("POST")
|
||||
|
|
|
|||
|
|
@ -37,34 +37,6 @@ func (res *publicreportR) ByID(ctx context.Context, r *http.Request, query Query
|
|||
populateReportURI(report, res.router)
|
||||
return report, nil
|
||||
}
|
||||
func (res *publicreportR) ByIDNuisance(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportNuisance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provid an ID")
|
||||
}
|
||||
report, err := platform.PublicreportByIDNuisance(ctx, public_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router)
|
||||
return report, nil
|
||||
}
|
||||
func (res *publicreportR) ByIDWater(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportWater, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provid an ID")
|
||||
}
|
||||
report, err := platform.PublicreportByIDWater(ctx, public_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router)
|
||||
return report, nil
|
||||
}
|
||||
|
||||
type image struct {
|
||||
Status string `json:"status"`
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
|
@ -50,6 +51,20 @@ type nuisanceForm struct {
|
|||
TODNight bool `schema:"tod-night"`
|
||||
}
|
||||
|
||||
func (res *nuisanceR) ByID(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportNuisance, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provid an ID")
|
||||
}
|
||||
report, err := platform.PublicreportByIDNuisance(ctx, public_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router)
|
||||
return report, nil
|
||||
}
|
||||
func (res *nuisanceR) Create(ctx context.Context, r *http.Request, n nuisanceForm) (*nuisance, *nhttp.ErrorWithStatus) {
|
||||
user_agent := r.Header.Get("User-Agent")
|
||||
err := platform.EnsureClient(ctx, n.ClientID, user_agent)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
|
@ -54,6 +55,21 @@ type waterForm struct {
|
|||
OwnerPhone string `schema:"owner-phone"`
|
||||
}
|
||||
|
||||
func (res *waterR) ByID(ctx context.Context, r *http.Request, query QueryParams) (*types.PublicReportWater, *nhttp.ErrorWithStatus) {
|
||||
vars := mux.Vars(r)
|
||||
public_id := vars["id"]
|
||||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provid an ID")
|
||||
}
|
||||
report, err := platform.PublicreportByIDWater(ctx, public_id)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get report: %w", err)
|
||||
}
|
||||
populateDistrictURI(&report.PublicReport, res.router)
|
||||
populateReportURI(&report.PublicReport, res.router)
|
||||
return report, nil
|
||||
}
|
||||
|
||||
func (res *waterR) Create(ctx context.Context, r *http.Request, w waterForm) (*water, *nhttp.ErrorWithStatus) {
|
||||
user_agent := r.Header.Get("User-Agent")
|
||||
err := platform.EnsureClient(ctx, w.ClientID, user_agent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue