get sale
This commit is contained in:
@ -360,3 +360,56 @@ func (m *DBModel) GetAllOrders(isRecurring bool) ([]*Order, error) {
|
||||
}
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
func (m *DBModel) GetOrderByID(ID int) (Order, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
o.id, o.widget_id, o.transaction_id, o.customer_id,
|
||||
o.status_id, o.quantity, o.amount, o.created_at, o.updated_at,
|
||||
w.id, w.name, t.id, t.amount, t.currency, t.last_four,
|
||||
t.expiry_month, t.expiry_year, t.payment_intent, t.bank_return_code,
|
||||
c.id, c.first_name, c.last_name, c.email
|
||||
FROM orders o
|
||||
LEFT JOIN widgets w on (o.widget_id = w.id)
|
||||
LEFT JOIN transactions t on (o.transaction_id = t.id)
|
||||
LEFT JOIN customers c on (o.customer_id = c.id)
|
||||
WHERE
|
||||
o.id = ?
|
||||
`
|
||||
|
||||
var o Order
|
||||
row := m.DB.QueryRowContext(ctx, query, ID)
|
||||
|
||||
err := row.Scan(
|
||||
&o.ID,
|
||||
&o.WidgetID,
|
||||
&o.TransactionID,
|
||||
&o.CustomerID,
|
||||
&o.StatusID,
|
||||
&o.Quantity,
|
||||
&o.Amount,
|
||||
&o.CreatedAt,
|
||||
&o.UpdatedAt,
|
||||
&o.Widget.ID,
|
||||
&o.Widget.Name,
|
||||
&o.Transaction.ID,
|
||||
&o.Transaction.Amount,
|
||||
&o.Transaction.Currency,
|
||||
&o.Transaction.LastFour,
|
||||
&o.Transaction.ExpiryMonth,
|
||||
&o.Transaction.ExpiryYear,
|
||||
&o.Transaction.PaymentIntent,
|
||||
&o.Transaction.BankReturnCode,
|
||||
&o.Customer.ID,
|
||||
&o.Customer.FirstName,
|
||||
&o.Customer.LastName,
|
||||
&o.Customer.Email,
|
||||
)
|
||||
if err != nil {
|
||||
return o, err
|
||||
}
|
||||
return o, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user