Split public report URIs by type

This allows us to have different signatures for the different types
This commit is contained in:
Eli Ribble 2026-04-12 17:01:30 +00:00
parent 875298fe88
commit a3c340f787
No known key found for this signature in database
7 changed files with 49 additions and 53 deletions

View file

@ -25,7 +25,7 @@ import (
"github.com/rs/zerolog/log"
)
func PublicreportByID(ctx context.Context, report_id string) (*types.Report, error) {
func PublicreportByID(ctx context.Context, report_id string) (*types.PublicReport, error) {
return publicreport.Report(ctx, report_id)
}
func PublicreportInvalid(ctx context.Context, user User, report_id string) error {
@ -87,7 +87,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, report_id, messag
return nil, errors.New("no contact methods available")
}
}
func PublicReportUpdate(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.Report, error) {
func PublicReportUpdate(ctx context.Context, report_id string, report_setter models.PublicreportReportSetter, address *types.Address, location *types.Location) (*types.PublicReport, error) {
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
if err != nil {
return nil, fmt.Errorf("create txn: %w", err)

View file

@ -8,16 +8,14 @@ import (
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
//"github.com/Gleipnir-Technology/nidus-sync/config"
"github.com/Gleipnir-Technology/nidus-sync/db"
//"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
//"github.com/google/uuid"
"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
)
func ReportsForOrganization(ctx context.Context, org_id int32) ([]*types.Report, error) {
func ReportsForOrganization(ctx context.Context, org_id int32) ([]*types.PublicReport, error) {
query := reportQuery()
query.Apply(
sm.Where(psql.Quote("publicreport", "report", "organization_id").EQ(psql.Arg(org_id))),
@ -25,8 +23,8 @@ func ReportsForOrganization(ctx context.Context, org_id int32) ([]*types.Report,
)
return reportQueryToRows(ctx, query)
}
func reportQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQuery]) ([]*types.Report, error) {
rows, err := bob.All(ctx, db.PGInstance.BobDB, query, scan.StructMapper[types.Report]())
func reportQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQuery]) ([]*types.PublicReport, error) {
rows, err := bob.All(ctx, db.PGInstance.BobDB, query, scan.StructMapper[types.PublicReport]())
if err != nil {
return nil, fmt.Errorf("get reports: %w", err)
@ -51,16 +49,8 @@ func reportQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQ
if err != nil {
return nil, fmt.Errorf("log entries for reports: %w", err)
}
nuisances_by_report_id, err := nuisancesByReportID(ctx, report_ids)
if err != nil {
return nil, fmt.Errorf("nuisances: %w", err)
}
waters_by_report_id, err := watersByReportID(ctx, report_ids)
if err != nil {
return nil, fmt.Errorf("waters: %w", err)
}
results := make([]*types.Report, len(rows))
results := make([]*types.PublicReport, len(rows))
for i, row := range rows {
if row.Address.ID != nil {
address, ok := addresses_by_id[*row.Address.ID]
@ -77,8 +67,6 @@ func reportQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQ
row.Images = []types.Image{}
}
row.Log = logs_by_report_id[row.ID]
row.Nuisance = nuisances_by_report_id[row.ID]
row.Water = waters_by_report_id[row.ID]
if row.Location.Latitude == 0.0 || row.Location.Longitude == 0.0 {
row.Location = nil
}
@ -86,7 +74,7 @@ func reportQueryToRows(ctx context.Context, query bob.BaseQuery[*dialect.SelectQ
}
return results, nil
}
func Report(ctx context.Context, public_id string) (*types.Report, error) {
func Report(ctx context.Context, public_id string) (*types.PublicReport, error) {
query := reportQuery()
query.Apply(
sm.Where(psql.Quote("publicreport", "report", "public_id").EQ(psql.Arg(public_id))),
@ -100,7 +88,7 @@ func Report(ctx context.Context, public_id string) (*types.Report, error) {
}
return reports[0], nil
}
func Reports(ctx context.Context, org_id int32, ids []int32) ([]*types.Report, error) {
func Reports(ctx context.Context, org_id int32, ids []int32) ([]*types.PublicReport, error) {
query := reportQuery()
query.Apply(
sm.Where(psql.Quote("publicreport", "report", "organization_id").EQ(psql.Arg(org_id))),

View file

@ -26,17 +26,17 @@ import (
)
type Signal struct {
Address *types.Address `db:"address" json:"address"`
Addressed *time.Time `db:"addressed" json:"addressed"`
Addressor *int32 `db:"addressor" json:"addressor"`
Created time.Time `db:"created" json:"created"`
Creator int32 `db:"creator" json:"creator"`
ID int32 `db:"id" json:"id"`
Location types.Location `db:"location" json:"location"`
Pool *Pool `db:"pool" json:"pool"`
Report *types.Report `db:"report" json:"report"`
Species *string `db:"species" json:"species"`
Type string `db:"type" json:"type"`
Address *types.Address `db:"address" json:"address"`
Addressed *time.Time `db:"addressed" json:"addressed"`
Addressor *int32 `db:"addressor" json:"addressor"`
Created time.Time `db:"created" json:"created"`
Creator int32 `db:"creator" json:"creator"`
ID int32 `db:"id" json:"id"`
Location types.Location `db:"location" json:"location"`
Pool *Pool `db:"pool" json:"pool"`
Report *types.PublicReport `db:"report" json:"report"`
Species *string `db:"species" json:"species"`
Type string `db:"type" json:"type"`
}
// Create a lead from the given signal and site
@ -212,7 +212,7 @@ func SignalList(ctx context.Context, user User, limit int) ([]*Signal, error) {
pool_map[pool.ID] = pool
log.Debug().Int32("pool", pool.ID).Msg("Added to map")
}
report_map := make(map[int32]*types.Report, len(report_ids))
report_map := make(map[int32]*types.PublicReport, len(report_ids))
for _, report := range reports {
report_map[report.ID] = report
}

View file

@ -1,4 +0,0 @@
package types
type PublicReport interface {
}

View file

@ -4,14 +4,13 @@ import (
"time"
)
type Report struct {
type PublicReport struct {
Address Address `db:"address" json:"address"`
Created time.Time `db:"created" json:"created"`
ID int32 `db:"id" json:"-"`
Images []Image `db:"images" json:"images"`
Location *Location `db:"location" json:"location"`
Log []LogEntry `db:"-" json:"log"`
Nuisance *Nuisance `db:"nuisance" json:"nuisance"`
DistrictID *int32 `db:"organization_id" json:"-"`
District *string `db:"-" json:"district"`
PublicID string `db:"public_id" json:"public_id"`
@ -19,5 +18,4 @@ type Report struct {
Status string `db:"status" json:"status"`
Type string `db:"report_type" json:"type"`
URI string `db:"-" json:"uri"`
Water *Water `db:"water" json:"water"`
}