Return full compliance report on PUT
This commit is contained in:
parent
9bca15ae7e
commit
ba76c8b1db
4 changed files with 35 additions and 38 deletions
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue