Compare commits
3 Commits
46ab4ee7a0
...
4d452737cd
Author | SHA1 | Date | |
---|---|---|---|
4d452737cd | |||
e608e64cce | |||
d61d083ed6 |
|
@ -12,8 +12,10 @@ import (
|
|||
|
||||
var cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbCard {
|
||||
var curr types.DbCurrency
|
||||
symbolPostfixForCard := ""
|
||||
if inp.Currency != nil {
|
||||
curr = currencyTransform(inp.Currency)
|
||||
symbolPostfixForCard = fmt.Sprintf(" (%s)", inp.Currency.Symbol)
|
||||
} else {
|
||||
curr = types.DbCurrency{}
|
||||
}
|
||||
|
@ -26,7 +28,7 @@ var cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbC
|
|||
LastDigits: inp.LastDigits,
|
||||
CurrencyID: inp.CurrencyID,
|
||||
Currency: curr,
|
||||
DisplayName: fmt.Sprintf("%s •%s", inp.Name, inp.LastDigits),
|
||||
DisplayName: fmt.Sprintf("%s •%s%s", inp.Name, inp.LastDigits, symbolPostfixForCard),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
||||
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var expenseTransform func(inp *db.Expense) types.DbExpense = func(inp *db.Expense) types.DbExpense {
|
||||
var card types.DbCard
|
||||
expenseValueSymbolPostfix := ""
|
||||
if inp.Card != nil {
|
||||
card = cardTransform(inp.Card)
|
||||
if inp.Card.Currency != nil {
|
||||
expenseValueSymbolPostfix = fmt.Sprintf(" (%s)", inp.Card.Currency.Symbol)
|
||||
}
|
||||
} else {
|
||||
card = types.DbCard{}
|
||||
}
|
||||
var showValue string
|
||||
showValue = fmt.Sprintf("%d.%02d%s", inp.Value/100, inp.Value%100, expenseValueSymbolPostfix)
|
||||
return types.DbExpense{
|
||||
ID: inp.ID,
|
||||
CardID: inp.CardID,
|
||||
|
@ -14,6 +28,8 @@ var expenseTransform func(inp *db.Expense) types.DbExpense = func(inp *db.Expens
|
|||
Value: inp.Value,
|
||||
Comment: inp.Comment,
|
||||
Date: inp.Date,
|
||||
Card: card,
|
||||
ShowValue: showValue,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +69,7 @@ func ExpenseGetAll(c *gin.Context) {
|
|||
}
|
||||
dbc := db.Connect()
|
||||
var entities []*db.Expense
|
||||
if err := dbc.Find(&entities, db.Expense{UserID: userID}).Error; err != nil {
|
||||
if err := dbc.Preload("Card.Currency").Find(&entities, db.Expense{UserID: userID}).Error; err != nil {
|
||||
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -82,6 +82,9 @@ type DbExpense struct {
|
|||
Value uint64 `json:"value" example:"20000"`
|
||||
Comment string `json:"comment" example:"pizza"`
|
||||
Date time.Time `json:"date" example:"29/11/2001 12:00"`
|
||||
// Purely UI things
|
||||
Card DbCard `json:"card"`
|
||||
ShowValue string `json:"show_value" example:"10.35$"`
|
||||
}
|
||||
|
||||
type DbTransfer struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user