implemented wallet headers

This commit is contained in:
Fran Jurmanović
2021-06-10 00:13:35 +02:00
parent 636a367d3e
commit 0fc69a0af2
7 changed files with 113 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package services
import (
"time"
"wallet-api/pkg/models"
"github.com/go-pg/pg/v10"
@@ -13,11 +14,18 @@ type TransactionService struct {
func (as *TransactionService) New(body *models.NewTransactionBody) *models.Transaction {
tm := new(models.Transaction)
amount, _ := body.Amount.Int64()
tm.Init()
tm.WalletID = body.WalletID
tm.TransactionTypeID = body.TransactionTypeID
tm.Description = body.Description
tm.TransactionDate = body.TransactionDate
tm.Amount = int(amount)
if body.TransactionDate.IsZero() {
tm.TransactionDate = time.Now()
}
as.Db.Model(tm).Insert()