diff --git a/platform/publicreport.go b/platform/publicreport.go index 8b837b54..70ca9075 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -32,12 +32,10 @@ func PublicreportByIDCompliance(ctx context.Context, report_id string) (*types.P return publicreport.ByIDCompliance(ctx, report_id) } func PublicreportByIDNuisance(ctx context.Context, report_id string) (*types.PublicReportNuisance, error) { - //return publicreport.ByIDNuisance(ctx, report_id) - return nil, nil + return publicreport.ByIDNuisance(ctx, report_id) } func PublicreportByIDWater(ctx context.Context, report_id string) (*types.PublicReportWater, error) { - //return publicreport.ByIDWater(ctx, report_id) - return nil, nil + return publicreport.ByIDWater(ctx, report_id) } func PublicreportInvalid(ctx context.Context, user User, report_id string) error { report, err := publicReportFromID(ctx, report_id) diff --git a/platform/publicreport/compliance.go b/platform/publicreport/compliance.go index 4387e98f..5ef307ae 100644 --- a/platform/publicreport/compliance.go +++ b/platform/publicreport/compliance.go @@ -40,18 +40,3 @@ func compliance(ctx context.Context, public_id string, report *types.PublicRepor return &row, nil } -func copyReportContent(src *types.PublicReport, dst *types.PublicReport) { - dst.Address = src.Address - dst.Created = src.Created - dst.ID = src.ID - dst.Images = src.Images - dst.Location = src.Location - dst.Log = src.Log - dst.DistrictID = src.DistrictID - dst.District = src.District - dst.PublicID = src.PublicID - dst.Reporter = src.Reporter - dst.Status = src.Status - dst.Type = src.Type - dst.URI = src.URI -} diff --git a/platform/publicreport/nuisance.go b/platform/publicreport/nuisance.go index 8667fcdf..1e97dba3 100644 --- a/platform/publicreport/nuisance.go +++ b/platform/publicreport/nuisance.go @@ -1,7 +1,6 @@ package publicreport import ( -/* "context" "fmt" @@ -14,12 +13,10 @@ import ( //"github.com/google/uuid" //"github.com/rs/zerolog/log" "github.com/stephenafamo/scan" -*/ ) -/* -func nuisancesByReportID(ctx context.Context, report_ids []int32) (map[int32]*types.Nuisance, error) { - rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( +func nuisance(ctx context.Context, public_id string, report *types.PublicReport) (*types.PublicReportNuisance, error) { + row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( "additional_info", "duration", @@ -40,32 +37,12 @@ func nuisancesByReportID(ctx context.Context, report_ids []int32) (map[int32]*ty ), sm.From("publicreport.nuisance"), sm.Where(psql.Quote("report_id").EQ( - psql.Any(report_ids), + psql.Arg(report.ID), )), - ), scan.StructMapper[types.Nuisance]()) + ), scan.StructMapper[types.PublicReportNuisance]()) if err != nil { return nil, fmt.Errorf("query nuisance: %w", err) } - results := make(map[int32]*types.Nuisance, len(rows)) - for _, row := range rows { - results[row.ReportID] = &types.Nuisance{ - AdditionalInfo: row.AdditionalInfo, - Duration: row.Duration, - IsLocationBackyard: row.IsLocationBackyard, - IsLocationFrontyard: row.IsLocationFrontyard, - IsLocationGarden: row.IsLocationGarden, - IsLocationOther: row.IsLocationOther, - IsLocationPool: row.IsLocationPool, - SourceContainer: row.SourceContainer, - SourceDescription: row.SourceDescription, - SourceGutter: row.SourceGutter, - SourceStagnant: row.SourceStagnant, - TODDay: row.TODDay, - TODEarly: row.TODEarly, - TODEvening: row.TODEvening, - TODNight: row.TODNight, - } - } - return results, nil + copyReportContent(report, &row.PublicReport) + return &row, nil } -*/ diff --git a/platform/publicreport/report.go b/platform/publicreport/report.go index 94e83051..d59117ba 100644 --- a/platform/publicreport/report.go +++ b/platform/publicreport/report.go @@ -30,18 +30,25 @@ func ByID(ctx context.Context, public_id string) (*types.PublicReport, error) { return reports[0], nil } func ByIDCompliance(ctx context.Context, public_id string) (*types.PublicReportCompliance, error) { - query := reportQuery() - query.Apply( - sm.Where(psql.Quote("publicreport", "report", "public_id").EQ(psql.Arg(public_id))), - ) - reports, err := reportQueryToRows(ctx, query) + report, err := ByID(ctx, public_id) if err != nil { - return nil, fmt.Errorf("query to rows: %w", err) + return nil, fmt.Errorf("base report byid: %w", err) } - if len(reports) != 1 { - return nil, fmt.Errorf("reports returned: %d", len(reports)) + return compliance(ctx, public_id, report) +} +func ByIDNuisance(ctx context.Context, public_id string) (*types.PublicReportNuisance, error) { + report, err := ByID(ctx, public_id) + if err != nil { + return nil, fmt.Errorf("base report byid: %w", err) } - return compliance(ctx, public_id, reports[0]) + return nuisance(ctx, public_id, report) +} +func ByIDWater(ctx context.Context, public_id string) (*types.PublicReportWater, error) { + report, err := ByID(ctx, public_id) + if err != nil { + return nil, fmt.Errorf("base report byid: %w", err) + } + return water(ctx, public_id, report) } func ReportsForOrganization(ctx context.Context, org_id int32) ([]*types.PublicReport, error) { query := reportQuery() @@ -126,6 +133,21 @@ func ReportsForOrganizationCount(ctx context.Context, org_id int32) (uint, error } return row.Count, nil } +func copyReportContent(src *types.PublicReport, dst *types.PublicReport) { + dst.Address = src.Address + dst.Created = src.Created + dst.ID = src.ID + dst.Images = src.Images + dst.Location = src.Location + dst.Log = src.Log + dst.DistrictID = src.DistrictID + dst.District = src.District + dst.PublicID = src.PublicID + dst.Reporter = src.Reporter + dst.Status = src.Status + dst.Type = src.Type + dst.URI = src.URI +} func reportQuery() bob.BaseQuery[*dialect.SelectQuery] { return psql.Select( sm.Columns( diff --git a/platform/publicreport/water.go b/platform/publicreport/water.go index 40d5a5ce..93fa7d89 100644 --- a/platform/publicreport/water.go +++ b/platform/publicreport/water.go @@ -1,7 +1,6 @@ package publicreport import ( -/* "context" "fmt" @@ -15,12 +14,10 @@ import ( //"github.com/google/uuid" //"github.com/rs/zerolog/log" "github.com/stephenafamo/scan" -*/ ) -/* -func watersByReportID(ctx context.Context, report_ids []int32) (map[int32]*types.Water, error) { - rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( +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", @@ -42,32 +39,12 @@ func watersByReportID(ctx context.Context, report_ids []int32) (map[int32]*types ), sm.From("publicreport.water"), sm.Where(psql.Quote("report_id").EQ( - psql.Any(report_ids), + psql.Arg(report.ID), )), - ), scan.StructMapper[types.Water]()) + ), scan.StructMapper[types.PublicReportWater]()) if err != nil { return nil, fmt.Errorf("query water: %w", err) } - results := make(map[int32]*types.Water, len(rows)) - for _, row := range rows { - results[row.ReportID] = &types.Water{ - AccessComments: row.AccessComments, - AccessGate: row.AccessGate, - AccessFence: row.AccessFence, - AccessLocked: row.AccessLocked, - AccessDog: row.AccessDog, - AccessOther: row.AccessOther, - Comments: row.Comments, - HasAdult: row.HasAdult, - HasBackyardPermission: row.HasBackyardPermission, - HasLarvae: row.HasLarvae, - HasPupae: row.HasPupae, - IsReporterConfidential: row.IsReporterConfidential, - IsReporterOwner: row.IsReporterOwner, - Owner: row.Owner, - ReportID: row.ReportID, - } - } - return results, nil + copyReportContent(report, &row.PublicReport) + return &row, nil } -*/