Return full compliance report on PUT
This commit is contained in:
parent
9bca15ae7e
commit
ba76c8b1db
4 changed files with 35 additions and 38 deletions
|
|
@ -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