Mave report ByID to their own resources

This commit is contained in:
Eli Ribble 2026-04-14 15:31:10 +00:00
parent 9b1de15373
commit 7e2a22c58c
No known key found for this signature in database
4 changed files with 33 additions and 30 deletions

View file

@ -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)