added transaction status to model

This commit is contained in:
Fran Jurmanović
2021-12-12 19:19:43 +01:00
parent 5c188f032e
commit 796efcdf5c
2 changed files with 19 additions and 17 deletions

View File

@@ -8,17 +8,17 @@ import (
type Transaction struct { type Transaction struct {
tableName struct{} `pg:"transactions,alias:transactions"` tableName struct{} `pg:"transactions,alias:transactions"`
BaseModel BaseModel
Description string `json:"description" pg:"description"` Description string `json:"description" pg:"description"`
TransactionTypeID string `json:"transactionTypeId", pg:"transaction_type_id"` TransactionTypeID string `json:"transactionTypeId", pg:"transaction_type_id"`
TransactionType *TransactionType `json:"transactionType", pg:"rel:has-one, fk:transaction_type_id"` TransactionType *TransactionType `json:"transactionType", pg:"rel:has-one, fk:transaction_type_id"`
TransactionStatusID string `json:"transactionStatusId", pg:"transaction_status_id"` TransactionStatusID string `json:"transactionStatusId", pg:"transaction_status_id"`
TransactionStatus *TransactionStatus `json:"transactionStatus", pg:"rel:has-one, fk:transaction_status_id"` TransactionStatus *TransactionStatus `json:"transactionStatus", pg:"rel:has-one, fk:transaction_status_id"`
WalletID string `json:"walletId", pg:"wallet_id"` WalletID string `json:"walletId", pg:"wallet_id"`
Amount float32 `json:"amount", pg:"amount,default:0"` Amount float32 `json:"amount", pg:"amount,default:0"`
Wallet *Wallet `json:"wallet" pg:"rel:has-one, fk:wallet_id"` Wallet *Wallet `json:"wallet" pg:"rel:has-one, fk:wallet_id"`
TransactionDate time.Time `json:"transactionDate" pg:"transaction_date, type:timestamptz"` TransactionDate time.Time `json:"transactionDate" pg:"transaction_date, type:timestamptz"`
SubscriptionID string `json:"subscriptionId", pg:"subscription_id"` SubscriptionID string `json:"subscriptionId", pg:"subscription_id"`
Subscription *Subscription `json:"subscription", pg:"rel:has-one, fk:subscription_id"` Subscription *Subscription `json:"subscription", pg:"rel:has-one, fk:subscription_id"`
} }
type NewTransactionBody struct { type NewTransactionBody struct {
@@ -30,10 +30,11 @@ type NewTransactionBody struct {
} }
type TransactionEdit struct { type TransactionEdit struct {
Id string `json:"id" form:"id"` Id string `json:"id" form:"id"`
WalletID string `json:"walletId" form:"walletId"` WalletID string `json:"walletId" form:"walletId"`
TransactionTypeID string `json:"transactionTypeId" form:"transactionTypeId"` TransactionTypeID string `json:"transactionTypeId" form:"transactionTypeId"`
TransactionDate time.Time `json:"transactionDate" form:"transactionDate"` TransactionDate time.Time `json:"transactionDate" form:"transactionDate"`
Description string `json:"description" form:"description"` TransactionStatusID string `json:"transactionStatusId" form:"transactionStatusId"`
Amount json.Number `json:"amount" form:"amount"` Description string `json:"description" form:"description"`
Amount json.Number `json:"amount" form:"amount"`
} }

View File

@@ -158,6 +158,7 @@ func (as *TransactionService) Edit(ctx context.Context, body *models.Transaction
tm.WalletID = body.WalletID tm.WalletID = body.WalletID
tm.TransactionTypeID = body.TransactionTypeID tm.TransactionTypeID = body.TransactionTypeID
tm.TransactionDate = body.TransactionDate tm.TransactionDate = body.TransactionDate
tm.TransactionStatusID = body.TransactionStatusID
tm.Amount = float32(math.Round(amount*100) / 100) tm.Amount = float32(math.Round(amount*100) / 100)
tx, _ := db.Begin() tx, _ := db.Begin()