Fix populating water report from ID, make ContactSimple
ContactSimple is the replacement for ContactReporter, which was the simplified form of a contact from a report. I made the name more generic and use it in the general report structures for consistency.
This commit is contained in:
parent
75d0283453
commit
5e103f46a0
14 changed files with 103 additions and 108 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/config"
|
||||
)
|
||||
|
||||
|
|
@ -104,6 +105,7 @@ const (
|
|||
)
|
||||
|
||||
func Created(t ResourceType, organization_id int32, uri_id string) {
|
||||
log.Debug().Int("resource type", int(t)).Int32("org", organization_id).Str("uri", uri_id).Msg("created event")
|
||||
go Send(Envelope{
|
||||
Event: Event{
|
||||
Resource: resourceString(t),
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ func PublicReportByIDNuisance(ctx context.Context, report_id string, is_public b
|
|||
return publicreport.ByIDNuisance(ctx, report_id, is_public)
|
||||
}
|
||||
func PublicReportByIDWater(ctx context.Context, report_id string, is_public bool) (*types.PublicReportWater, error) {
|
||||
return publicreport.ByIDWater(ctx, report_id, is_public)
|
||||
result, err := publicreport.ByIDWater(ctx, report_id, is_public)
|
||||
return &result, err
|
||||
}
|
||||
func PublicReportInvalid(ctx context.Context, user User, public_id string) error {
|
||||
report, err := querypublicreport.ReportFromPublicID(ctx, db.PGInstance.PGXPool, public_id)
|
||||
|
|
|
|||
|
|
@ -38,15 +38,20 @@ func ByIDNuisance(ctx context.Context, public_id string, is_public bool) (*types
|
|||
}
|
||||
return nuisance(ctx, public_id, *report)
|
||||
}
|
||||
func ByIDWater(ctx context.Context, public_id string, is_public bool) (*types.PublicReportWater, error) {
|
||||
func ByIDWater(ctx context.Context, public_id string, is_public bool) (types.PublicReportWater, error) {
|
||||
report, err := byID(ctx, public_id, is_public)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base report byid: %w", err)
|
||||
return types.PublicReportWater{}, fmt.Errorf("base report byid: %w", err)
|
||||
}
|
||||
if report == nil {
|
||||
return nil, nil
|
||||
return types.PublicReportWater{}, nil
|
||||
}
|
||||
return water(ctx, public_id, *report)
|
||||
txn := db.PGInstance.PGXPool
|
||||
water, err := querypublicreport.WaterFromReportID(ctx, txn, int64(report.ID))
|
||||
if err != nil {
|
||||
return types.PublicReportWater{}, fmt.Errorf("water from report id %d: %w", report.ID, err)
|
||||
}
|
||||
return types.PublicReportWaterFromModel(*report, water), nil
|
||||
}
|
||||
func UnreviewedForOrganization(ctx context.Context, txn db.Ex, org_id int64, is_public bool) ([]types.PublicReport, error) {
|
||||
reports, err := querypublicreport.ReportsUnreviewedForOrganization(ctx, txn, org_id)
|
||||
|
|
@ -143,10 +148,10 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
|||
DistrictID: &row.OrganizationID,
|
||||
District: nil,
|
||||
PublicID: row.PublicID,
|
||||
Reporter: types.ContactReporter{
|
||||
Reporter: types.ContactSimple{
|
||||
Email: row.ReporterEmail,
|
||||
Name: row.ReporterName,
|
||||
Phone: types.PhoneReporter{
|
||||
Phone: types.PhoneSimple{
|
||||
CanSMS: row.ReporterPhoneCanSms,
|
||||
Number: row.ReporterPhone,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
package publicreport
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
//"source.gleipnir.technology/Gleipnir/nidus-sync/config"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
||||
//"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
|
||||
//"github.com/google/uuid"
|
||||
//"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
func water(ctx context.Context, public_id string, report types.PublicReport) (*types.PublicReportWater, error) {
|
||||
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
"access_comments",
|
||||
"access_gate",
|
||||
"access_fence",
|
||||
"access_locked",
|
||||
"access_dog",
|
||||
"access_other",
|
||||
"comments",
|
||||
"has_adult",
|
||||
"has_backyard_permission",
|
||||
"has_larvae",
|
||||
"has_pupae",
|
||||
"is_reporter_confidential",
|
||||
"is_reporter_owner",
|
||||
"owner_email AS \"owner.email\"",
|
||||
"owner_name AS \"owner.name\"",
|
||||
"owner_phone AS \"owner.phone\"",
|
||||
"report_id",
|
||||
),
|
||||
sm.From("publicreport.water"),
|
||||
sm.Where(psql.Quote("report_id").EQ(
|
||||
psql.Arg(report.ID),
|
||||
)),
|
||||
), scan.StructMapper[types.PublicReportWater]())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query water: %w", err)
|
||||
}
|
||||
copyReportContent(report, &row.PublicReport)
|
||||
return &row, nil
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
//"github.com/rs/zerolog/log"
|
||||
// "github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Contact struct {
|
||||
|
|
@ -10,16 +10,16 @@ type Contact struct {
|
|||
Name string `json:"name"`
|
||||
Phones []Phone `json:"phones"`
|
||||
}
|
||||
type ContactReporter struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Phone PhoneReporter `json:"phone"`
|
||||
type ContactSimple struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Phone PhoneSimple `json:"phone"`
|
||||
}
|
||||
type Phone struct {
|
||||
E164 string `json:"e164"`
|
||||
CanSMS bool `json:"can_sms"`
|
||||
}
|
||||
type PhoneReporter struct {
|
||||
type PhoneSimple struct {
|
||||
CanSMS bool `json:"can_sms"`
|
||||
Number string `json:"number"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package types
|
|||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/publicreport/model"
|
||||
)
|
||||
|
||||
type PublicReport struct {
|
||||
|
|
@ -15,7 +17,7 @@ type PublicReport struct {
|
|||
DistrictID *int32 `db:"organization_id" json:"-"`
|
||||
District *string `db:"-" json:"district"`
|
||||
PublicID string `db:"public_id" json:"public_id"`
|
||||
Reporter ContactReporter `db:"reporter" json:"reporter"`
|
||||
Reporter ContactSimple `db:"reporter" json:"reporter"`
|
||||
Status string `db:"status" json:"status"`
|
||||
Type string `db:"report_type" json:"type"`
|
||||
URI string `db:"-" json:"uri"`
|
||||
|
|
@ -56,19 +58,47 @@ type PublicReportNuisance struct {
|
|||
}
|
||||
type PublicReportWater struct {
|
||||
PublicReport
|
||||
AccessComments string `db:"access_comments" json:"access_comments"`
|
||||
AccessGate bool `db:"access_gate" json:"access_gate"`
|
||||
AccessFence bool `db:"access_fence" json:"access_fence"`
|
||||
AccessLocked bool `db:"access_locked" json:"access_locked"`
|
||||
AccessDog bool `db:"access_dog" json:"access_dog"`
|
||||
AccessOther bool `db:"access_other" json:"access_other"`
|
||||
Comments string `db:"comments" json:"comments"`
|
||||
HasAdult bool `db:"has_adult" json:"has_adult"`
|
||||
HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"`
|
||||
HasLarvae bool `db:"has_larvae" json:"has_larvae"`
|
||||
HasPupae bool `db:"has_pupae" json:"has_pupae"`
|
||||
IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"`
|
||||
IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"`
|
||||
Owner Contact `db:"owner" json:"owner"`
|
||||
ReportID int32 `db:"report_id" json:"-"`
|
||||
AccessComments string `db:"access_comments" json:"access_comments"`
|
||||
AccessGate bool `db:"access_gate" json:"access_gate"`
|
||||
AccessFence bool `db:"access_fence" json:"access_fence"`
|
||||
AccessLocked bool `db:"access_locked" json:"access_locked"`
|
||||
AccessDog bool `db:"access_dog" json:"access_dog"`
|
||||
AccessOther bool `db:"access_other" json:"access_other"`
|
||||
Comments string `db:"comments" json:"comments"`
|
||||
HasAdult bool `db:"has_adult" json:"has_adult"`
|
||||
HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"`
|
||||
HasLarvae bool `db:"has_larvae" json:"has_larvae"`
|
||||
HasPupae bool `db:"has_pupae" json:"has_pupae"`
|
||||
IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"`
|
||||
IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"`
|
||||
Owner ContactSimple `db:"owner" json:"owner"`
|
||||
ReportID int32 `db:"report_id" json:"-"`
|
||||
}
|
||||
|
||||
func PublicReportWaterFromModel(report PublicReport, water model.Water) PublicReportWater {
|
||||
return PublicReportWater{
|
||||
PublicReport: report,
|
||||
AccessComments: water.AccessComments,
|
||||
AccessGate: water.AccessGate,
|
||||
AccessFence: water.AccessFence,
|
||||
AccessLocked: water.AccessLocked,
|
||||
AccessDog: water.AccessDog,
|
||||
AccessOther: water.AccessOther,
|
||||
Comments: water.Comments,
|
||||
HasAdult: water.HasAdult,
|
||||
HasBackyardPermission: water.HasBackyardPermission,
|
||||
HasLarvae: water.HasLarvae,
|
||||
HasPupae: water.HasPupae,
|
||||
IsReporterConfidential: water.IsReporterConfidential,
|
||||
IsReporterOwner: water.IsReporterOwner,
|
||||
Owner: ContactSimple{
|
||||
Email: water.OwnerEmail,
|
||||
Name: water.OwnerName,
|
||||
Phone: PhoneSimple{
|
||||
CanSMS: false,
|
||||
Number: water.OwnerPhone,
|
||||
},
|
||||
},
|
||||
ReportID: water.ReportID,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue