mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-11-11 07:41:10 +00:00
add repositories and fixed services
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
type ApiModel struct {
|
||||
BaseModel
|
||||
tableName struct{} `pg:"api,alias:api"`
|
||||
Api string `json:"api"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type FilteredResponse struct {
|
||||
Items interface{} `json:"items"`
|
||||
|
||||
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -45,6 +46,41 @@ type NewSubscriptionBody struct {
|
||||
Amount json.Number `json:"amount" form:"amount"`
|
||||
}
|
||||
|
||||
func (body *SubscriptionEdit) ToSubscription() *Subscription {
|
||||
amount, _ := body.Amount.Float64()
|
||||
tm := new(Subscription)
|
||||
tm.Id = body.Id
|
||||
tm.EndDate = body.EndDate
|
||||
tm.HasEnd = body.HasEnd
|
||||
tm.Description = body.Description
|
||||
tm.WalletID = body.WalletID
|
||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||
|
||||
return tm
|
||||
}
|
||||
|
||||
func (body *NewSubscriptionBody) ToSubscription() *Subscription {
|
||||
tm := new(Subscription)
|
||||
amount, _ := body.Amount.Float64()
|
||||
customRange, _ := body.CustomRange.Int64()
|
||||
|
||||
tm.Init()
|
||||
tm.WalletID = body.WalletID
|
||||
tm.TransactionTypeID = body.TransactionTypeID
|
||||
tm.SubscriptionTypeID = body.SubscriptionTypeID
|
||||
tm.CustomRange = int(customRange)
|
||||
tm.Description = body.Description
|
||||
tm.StartDate = body.StartDate
|
||||
tm.HasEnd = body.HasEnd
|
||||
tm.EndDate = body.EndDate
|
||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||
|
||||
if body.StartDate.IsZero() {
|
||||
tm.StartDate = time.Now()
|
||||
}
|
||||
return tm
|
||||
}
|
||||
|
||||
type SubscriptionEnd struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
}
|
||||
|
||||
@@ -11,3 +11,13 @@ type NewSubscriptionTypeBody struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Type string `json:"type" form:"type"`
|
||||
}
|
||||
|
||||
func (body *NewSubscriptionTypeBody) ToSubscriptionType() *SubscriptionType {
|
||||
tm := new(SubscriptionType)
|
||||
|
||||
tm.Init()
|
||||
tm.Name = body.Name
|
||||
tm.Type = body.Type
|
||||
|
||||
return tm
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -29,6 +30,23 @@ type NewTransactionBody struct {
|
||||
Amount json.Number `json:"amount" form:"amount"`
|
||||
}
|
||||
|
||||
func (body *NewTransactionBody) ToTransaction() *Transaction {
|
||||
tm := new(Transaction)
|
||||
amount, _ := body.Amount.Float64()
|
||||
|
||||
tm.Init()
|
||||
tm.WalletID = body.WalletID
|
||||
tm.TransactionTypeID = body.TransactionTypeID
|
||||
tm.Description = body.Description
|
||||
tm.TransactionDate = body.TransactionDate
|
||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||
|
||||
if body.TransactionDate.IsZero() {
|
||||
tm.TransactionDate = time.Now()
|
||||
}
|
||||
return tm
|
||||
}
|
||||
|
||||
type TransactionEdit struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
WalletID string `json:"walletId" form:"walletId"`
|
||||
@@ -38,3 +56,18 @@ type TransactionEdit struct {
|
||||
Description string `json:"description" form:"description"`
|
||||
Amount json.Number `json:"amount" form:"amount"`
|
||||
}
|
||||
|
||||
func (body *TransactionEdit) ToTransaction() *Transaction {
|
||||
tm := new(Transaction)
|
||||
amount, _ := body.Amount.Float64()
|
||||
|
||||
tm.Id = body.Id
|
||||
tm.Description = body.Description
|
||||
tm.WalletID = body.WalletID
|
||||
tm.TransactionTypeID = body.TransactionTypeID
|
||||
tm.TransactionDate = body.TransactionDate
|
||||
tm.TransactionStatusID = body.TransactionStatusID
|
||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||
|
||||
return tm
|
||||
}
|
||||
|
||||
@@ -11,3 +11,11 @@ type NewTransactionStatusBody struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Status string `json:"status" form:"status"`
|
||||
}
|
||||
|
||||
func (body *NewTransactionStatusBody) ToTransactionStatus() *TransactionStatus {
|
||||
tm := new(TransactionStatus)
|
||||
tm.Init()
|
||||
tm.Name = body.Name
|
||||
tm.Status = body.Status
|
||||
return tm
|
||||
}
|
||||
|
||||
@@ -11,3 +11,11 @@ type NewTransactionTypeBody struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Type string `json:"type" form:"type"`
|
||||
}
|
||||
|
||||
func (body *NewTransactionTypeBody) ToTransactionType() *TransactionType {
|
||||
tm := new(TransactionType)
|
||||
tm.Init()
|
||||
tm.Name = body.Name
|
||||
tm.Type = body.Type
|
||||
return tm
|
||||
}
|
||||
|
||||
@@ -33,3 +33,18 @@ type WalletEdit struct {
|
||||
Id string `json:"id" form:"id"`
|
||||
Name string `json:"name" form:"name"`
|
||||
}
|
||||
|
||||
func (body *NewWalletBody) ToWallet() *Wallet {
|
||||
tm := new(Wallet)
|
||||
tm.Init()
|
||||
tm.Name = body.Name
|
||||
tm.UserID = body.UserID
|
||||
return tm
|
||||
}
|
||||
|
||||
func (body *WalletEdit) ToWallet() *Wallet {
|
||||
tm := new(Wallet)
|
||||
tm.Name = body.Name
|
||||
tm.Id = body.Id
|
||||
return tm
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user