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
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
|
|
@ -20,11 +21,20 @@ import (
|
|||
// Create a lead from the given signal and site
|
||||
func LeadCreate(ctx context.Context, user User, signal_id int32, site_id int32, pool_location *types.Location) (*int32, error) {
|
||||
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
|
||||
defer txn.Rollback(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("start transaction: %w", err)
|
||||
}
|
||||
defer txn.Rollback(ctx)
|
||||
|
||||
lead_id, err := leadCreate(ctx, txn, user, signal_id, site_id, pool_location)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("inner leadcreate: %w", err)
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
return lead_id, nil
|
||||
}
|
||||
|
||||
func leadCreate(ctx context.Context, txn bob.Executor, user User, signal_id int32, site_id int32, pool_location *types.Location) (*int32, error) {
|
||||
lead, err := models.Leads.Insert(&models.LeadSetter{
|
||||
Created: omit.From(time.Now()),
|
||||
Creator: omit.From(int32(user.ID)),
|
||||
|
|
@ -59,6 +69,5 @@ func LeadCreate(ctx context.Context, user User, signal_id int32, site_id int32,
|
|||
return nil, fmt.Errorf("failed to update pool through signal %d: %w", signal_id, err)
|
||||
}
|
||||
}
|
||||
txn.Commit(ctx)
|
||||
return &lead.ID, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue