Populate nuisance and water public reports by ID
This commit is contained in:
parent
ae10e4fee8
commit
5306f8ba62
5 changed files with 45 additions and 86 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue