2026-04-08 17:49:32 +00:00
|
|
|
package platform
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-05-19 15:33:57 +00:00
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
|
|
|
|
querypublicreport "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/publicreport"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/lint"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/publicreport"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
2026-04-08 17:49:32 +00:00
|
|
|
//"github.com/rs/zerolog/log"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PublicreportNotification struct {
|
|
|
|
|
Consent bool
|
|
|
|
|
Email string
|
|
|
|
|
Name string
|
|
|
|
|
Notification bool
|
|
|
|
|
Phone *types.E164
|
|
|
|
|
ReportID string
|
|
|
|
|
Subscription bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PublicreportNotificationCreate(ctx context.Context, pn PublicreportNotification) error {
|
2026-05-15 16:58:28 +00:00
|
|
|
txn, err := db.BeginTxn(ctx)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("begin txn: %w", err)
|
|
|
|
|
}
|
lint: fix remaining errcheck issues across multiple files
- Fix renderShim errcheck in district.go, image.go
- Fix txn.Rollback/Commit in publicreport.go, notification, review, signal, upload
- Fix addError calls in csv/flyover.go, csv/pool.go
- Fix cW/write calls in logger.go, recoverer.go, voipms.go
- Fix resendInitialText, handleWaitingTextJobs, setPhoneStatus in text/send.go, text.go
- Fix populateDistrictURI/populateReportURI in resource files
2026-05-09 03:06:56 +00:00
|
|
|
defer lint.LogOnErrRollback(txn.Rollback, ctx, "rollback")
|
2026-05-15 16:58:28 +00:00
|
|
|
|
|
|
|
|
report, err := querypublicreport.ReportFromPublicID(ctx, txn, pn.ReportID)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("find report '%s': %w", pn.ReportID, err)
|
|
|
|
|
}
|
2026-05-15 16:58:28 +00:00
|
|
|
if report == nil {
|
|
|
|
|
return fmt.Errorf("no such report '%s'", pn.ReportID)
|
|
|
|
|
}
|
2026-04-08 17:49:32 +00:00
|
|
|
|
2026-05-15 16:58:28 +00:00
|
|
|
contact, err := publicreport.SaveReporter(ctx, txn, *report, pn.Name)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("save reporter: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if pn.Email != "" {
|
|
|
|
|
if pn.Subscription {
|
2026-05-15 16:58:28 +00:00
|
|
|
err = publicreport.RegisterSubscriptionEmail(ctx, txn, contact, pn.Email)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("register subscription email: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if pn.Notification {
|
2026-05-15 16:58:28 +00:00
|
|
|
err = publicreport.RegisterNotificationEmail(ctx, txn, *report, contact, pn.Email)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("register notification email: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if pn.Phone != nil {
|
|
|
|
|
if pn.Subscription {
|
2026-05-15 16:58:28 +00:00
|
|
|
err = publicreport.RegisterSubscriptionPhone(ctx, txn, contact, *pn.Phone)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("register subscription phone: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if pn.Notification {
|
2026-05-15 16:58:28 +00:00
|
|
|
err = publicreport.RegisterNotificationPhone(ctx, txn, *report, contact, *pn.Phone)
|
2026-04-08 17:49:32 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("register notification phone: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
lint: fix remaining errcheck issues across multiple files
- Fix renderShim errcheck in district.go, image.go
- Fix txn.Rollback/Commit in publicreport.go, notification, review, signal, upload
- Fix addError calls in csv/flyover.go, csv/pool.go
- Fix cW/write calls in logger.go, recoverer.go, voipms.go
- Fix resendInitialText, handleWaitingTextJobs, setPhoneStatus in text/send.go, text.go
- Fix populateDistrictURI/populateReportURI in resource files
2026-05-09 03:06:56 +00:00
|
|
|
if err := txn.Commit(ctx); err != nil {
|
|
|
|
|
return fmt.Errorf("commit: %w", err)
|
|
|
|
|
}
|
2026-05-15 16:58:28 +00:00
|
|
|
PublicReportReporterUpdated(ctx, report.OrganizationID, pn.ReportID)
|
2026-04-08 17:49:32 +00:00
|
|
|
return nil
|
|
|
|
|
}
|