mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
added transaction status routes
This commit is contained in:
@@ -16,24 +16,26 @@ type TransactionService struct {
|
||||
}
|
||||
|
||||
/*
|
||||
GetAll
|
||||
New new row into transaction table
|
||||
|
||||
Gets all rows from subscription type table.
|
||||
Inserts
|
||||
Args:
|
||||
context.Context: Application context
|
||||
string: Relations to embed
|
||||
*models.NewTransactionBody: Transaction body object
|
||||
Returns:
|
||||
*[]models.SubscriptionType: List of subscription type objects.
|
||||
*models.Transaction: Transaction object
|
||||
*/
|
||||
// Inserts new row to transaction table.
|
||||
func (as *TransactionService) New(ctx context.Context, body *models.NewTransactionBody) *models.Transaction {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
tm := new(models.Transaction)
|
||||
transactionStatus := new(models.TransactionStatus)
|
||||
|
||||
tx, _ := db.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
tx.Model(transactionStatus).Where("? = ?", pg.Ident("status"), "completed").Select()
|
||||
|
||||
amount, _ := body.Amount.Float64()
|
||||
|
||||
tm.Init()
|
||||
@@ -42,6 +44,7 @@ func (as *TransactionService) New(ctx context.Context, body *models.NewTransacti
|
||||
tm.Description = body.Description
|
||||
tm.TransactionDate = body.TransactionDate
|
||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||
tm.TransactionStatusID = transactionStatus.Id
|
||||
|
||||
if body.TransactionDate.IsZero() {
|
||||
tm.TransactionDate = time.Now()
|
||||
|
||||
Reference in New Issue
Block a user