Inserting a new order
This commit is contained in:
parent
46386b19a3
commit
6d4b8236a5
@ -130,8 +130,37 @@ func (m *DBModel) InsertTransaction(txn Transaction) (int, error) {
|
||||
txn.LastFour,
|
||||
txn.BankReturnCode,
|
||||
txn.TransactionStatusID,
|
||||
txn.CreatedAt,
|
||||
txn.UpdatedAt)
|
||||
time.Now(),
|
||||
time.Now(),
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int(id), nil
|
||||
}
|
||||
|
||||
// InsertOrder inserts a new order, and returns its id
|
||||
func (m *DBModel) InsertOrder(order Order) (int, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
stmt := `INSERT INTO orders
|
||||
(widget_id, transaction_id, status_id, quantity,
|
||||
amount, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
|
||||
result, err := m.DB.ExecContext(ctx, stmt,
|
||||
order.WidgetID,
|
||||
order.TransactionID,
|
||||
order.StatusID,
|
||||
order.Quantity,
|
||||
order.Amount,
|
||||
time.Now(),
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user