added transaction status routes

This commit is contained in:
Fran Jurmanović
2021-09-05 11:40:21 +02:00
parent fa09e2ee08
commit 862aded788
9 changed files with 259 additions and 5 deletions

View File

@@ -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()