Add contacts, rework comms schema
This in a pretty huge change. At a high level we're adding the concept of a 'contact' which is a person or organization that has zero or more contact methods (email, phone). This ended up cascading a number of changes, including critically to the publicreprt schema. In the end it seemed safer to get to the point where I'm confident we aren't using any of the old fields for storing reporter information (though I haven't deleted the columns yet) so I removed the code for defining those columns. At this point I think it's not possible for me to regenerate the bob schema due to the interdependencies between my various schemas, so the migration is well-and-truly happening.
This commit is contained in:
parent
085935fa66
commit
f1fe8b4d2b
46 changed files with 1127 additions and 633 deletions
|
|
@ -11,13 +11,15 @@ import (
|
|||
|
||||
"github.com/Gleipnir-Technology/jet/postgres"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
modelcomms "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
||||
tablepublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
||||
modelpublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model"
|
||||
tablepublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/table"
|
||||
querycomms "github.com/Gleipnir-Technology/nidus-sync/db/query/comms"
|
||||
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
||||
querypublicreport "github.com/Gleipnir-Technology/nidus-sync/db/query/publicreport"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/lint"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/email"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/geocode"
|
||||
|
|
@ -106,7 +108,7 @@ func PublicReportInvalid(ctx context.Context, user User, public_id string) error
|
|||
}
|
||||
|
||||
func PublicReportMessageCreate(ctx context.Context, user User, public_id, message string) (message_id *int32, err error) {
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
txn, err := db.BeginTxn(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create txn: %w", err)
|
||||
}
|
||||
|
|
@ -148,8 +150,7 @@ func PublicReportMessageCreate(ctx context.Context, user User, public_id, messag
|
|||
return nil, errors.New("no contact methods available")
|
||||
}
|
||||
}
|
||||
func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_updates querypublicreport.ReportUpdater, compliance_updates querypublicreport.ComplianceUpdater, address *types.Address, location *types.Location) error {
|
||||
//txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_updates querypublicreport.ReportUpdater, compliance_updates querypublicreport.ComplianceUpdater, address *types.Address, location *types.Location, reporter *types.Contact) error {
|
||||
txn, err := db.BeginTxn(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create txn: %w", err)
|
||||
|
|
@ -159,7 +160,6 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
if err != nil {
|
||||
return fmt.Errorf("query report existence: %w", err)
|
||||
}
|
||||
//compliance, err := models.FindPublicreportCompliance(ctx, txn, report.ID)
|
||||
compliance, err := querypublicreport.ComplianceFromID(ctx, txn, int64(report.ID))
|
||||
if err != nil {
|
||||
return fmt.Errorf("find compliance %d: %w", report.ID, err)
|
||||
|
|
@ -224,6 +224,26 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
|||
return fmt.Errorf("update location: %w", err)
|
||||
}
|
||||
}
|
||||
if reporter != nil {
|
||||
if report.ReporterContactID == nil {
|
||||
contact := modelcomms.Contact{
|
||||
Created: time.Now(),
|
||||
Name: reporter.Name,
|
||||
OrganizationID: report.OrganizationID,
|
||||
}
|
||||
_, err = querycomms.ContactInsert(ctx, txn, contact)
|
||||
if err != nil {
|
||||
return fmt.Errorf("insert contact: %w", err)
|
||||
}
|
||||
} else if reporter.Name != "" {
|
||||
err = querycomms.ContactUpdateName(ctx, txn, int64(*report.ReporterContactID), reporter.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("update contact: %w", err)
|
||||
}
|
||||
} else {
|
||||
log.Warn().Int32("report.id", report.ID).Msg("not sure what to do with empty reporter name")
|
||||
}
|
||||
}
|
||||
if err := txn.Commit(ctx); err != nil {
|
||||
return fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue