From ba76c8b1dbe1f78325108e90aa19b2f770a93401 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 13 Apr 2026 19:32:22 +0000 Subject: [PATCH] Return full compliance report on PUT --- api/routes.go | 2 +- platform/publicreport.go | 4 ++-- resource/publicreport.go | 35 ----------------------------- resource/publicreport_compliance.go | 32 ++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/api/routes.go b/api/routes.go index dd2f25c6..c393af16 100644 --- a/api/routes.go +++ b/api/routes.go @@ -84,7 +84,7 @@ func AddRoutes(r *mux.Router) { r.Handle("/publicreport/{id}", handlerJSON(publicreport.ByID)).Methods("GET").Name("publicreport.ByIDGet") r.Handle("/publicreport/{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(publicreport.UpdateCompliance)).Methods("PUT") + 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") diff --git a/platform/publicreport.go b/platform/publicreport.go index 79d8b1c4..970ac9c5 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -97,7 +97,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, public_id, messag return nil, errors.New("no contact methods available") } } -func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReport, error) { +func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReportCompliance, error) { txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) if err != nil { return nil, fmt.Errorf("create txn: %w", err) @@ -130,7 +130,7 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_ } } txn.Commit(ctx) - return publicreport.ByID(ctx, public_id) + return publicreport.ByIDCompliance(ctx, public_id) } func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id string) { event.Updated(event.TypeRMOPublicReport, org_id, report_id) diff --git a/resource/publicreport.go b/resource/publicreport.go index 50b8b534..cc0a83ca 100644 --- a/resource/publicreport.go +++ b/resource/publicreport.go @@ -5,9 +5,6 @@ import ( "fmt" "net/http" - "github.com/aarondl/opt/omit" - //"github.com/aarondl/opt/omitnull" - "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/html" nhttp "github.com/Gleipnir-Technology/nidus-sync/http" "github.com/Gleipnir-Technology/nidus-sync/platform" @@ -100,38 +97,6 @@ type publicreportComplianceForm struct { Reporter *types.Contact `schema:"reporter"` } -func (res *publicreportR) UpdateCompliance(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReport, *nhttp.ErrorWithStatus) { - vars := mux.Vars(r) - public_id := vars["id"] - if public_id == "" { - return nil, nhttp.NewBadRequest("You must provide an ID") - } - report_setter := models.PublicreportReportSetter{} - if prf.Location != nil { - //report_setter.Latitude = omit.From(prf.Location.Latitude) - //report_setter.Longitude = omit.From(prf.Location.Longitude) - if prf.Location.Accuracy != nil { - report_setter.LatlngAccuracyValue = omit.From(*prf.Location.Accuracy) - } - } - if prf.Reporter != nil { - if prf.Reporter.Email != nil { - report_setter.ReporterEmail = omit.From(*prf.Reporter.Email) - } - if prf.Reporter.Name != nil { - report_setter.ReporterName = omit.From(*prf.Reporter.Name) - } - if prf.Reporter.Phone != nil { - report_setter.ReporterPhone = omit.From(*prf.Reporter.Phone) - } - } - report, err := platform.PublicReportUpdateCompliance(ctx, public_id, report_setter, prf.Address, prf.Location) - if err != nil { - return nil, nhttp.NewError("platform update report compliance: %w", err) - } - return report, nil -} - func populateDistrictURI(report *types.PublicReport, r *router) error { var district_uri string var err error diff --git a/resource/publicreport_compliance.go b/resource/publicreport_compliance.go index 1fd1ef56..c10ce374 100644 --- a/resource/publicreport_compliance.go +++ b/resource/publicreport_compliance.go @@ -95,3 +95,35 @@ func (res *complianceR) Create(ctx context.Context, r *http.Request, n publicrep URI: uri, }, nil } + +func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { + vars := mux.Vars(r) + public_id := vars["id"] + if public_id == "" { + return nil, nhttp.NewBadRequest("You must provide an ID") + } + report_setter := models.PublicreportReportSetter{} + if prf.Location != nil { + //report_setter.Latitude = omit.From(prf.Location.Latitude) + //report_setter.Longitude = omit.From(prf.Location.Longitude) + if prf.Location.Accuracy != nil { + report_setter.LatlngAccuracyValue = omit.From(*prf.Location.Accuracy) + } + } + if prf.Reporter != nil { + if prf.Reporter.Email != nil { + report_setter.ReporterEmail = omit.From(*prf.Reporter.Email) + } + if prf.Reporter.Name != nil { + report_setter.ReporterName = omit.From(*prf.Reporter.Name) + } + if prf.Reporter.Phone != nil { + report_setter.ReporterPhone = omit.From(*prf.Reporter.Phone) + } + } + report, err := platform.PublicReportUpdateCompliance(ctx, public_id, report_setter, prf.Address, prf.Location) + if err != nil { + return nil, nhttp.NewError("platform update report compliance: %w", err) + } + return report, nil +}