Start wiring together request for a mailer to database
This commit is contained in:
parent
74e24b7de3
commit
2ea47f03f4
14 changed files with 321 additions and 83 deletions
|
|
@ -2,10 +2,7 @@ package report
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
|
|
@ -31,31 +28,6 @@ func DistrictForReport(ctx context.Context, report_id string) (*models.Organizat
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// GenerateReportID creates a 12-character random string using only unambiguous
|
||||
// capital letters and numbers
|
||||
func GenerateReportID() (string, error) {
|
||||
// Define character set (no O/0, I/l/1, 2/Z to avoid confusion)
|
||||
const charset = "ABCDEFGHJKLMNPQRSTUVWXY3456789"
|
||||
const length = 12
|
||||
|
||||
var builder strings.Builder
|
||||
builder.Grow(length)
|
||||
|
||||
// Use crypto/rand for secure randomness
|
||||
for i := 0; i < length; i++ {
|
||||
// Generate a random index within our charset
|
||||
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to generate random number: %w", err)
|
||||
}
|
||||
|
||||
// Add the randomly selected character to our ID
|
||||
builder.WriteByte(charset[n.Int64()])
|
||||
}
|
||||
|
||||
return builder.String(), nil
|
||||
}
|
||||
|
||||
func RegisterNotificationEmail(ctx context.Context, txn bob.Executor, report_id string, destination string) error {
|
||||
report, e := reportByPublicID(ctx, db.PGInstance.BobDB, report_id)
|
||||
if e != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue