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 cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbCard {
|
||||||
var curr types.DbCurrency
|
var curr types.DbCurrency
|
||||||
|
symbolPostfixForCard := ""
|
||||||
if inp.Currency != nil {
|
if inp.Currency != nil {
|
||||||
curr = currencyTransform(inp.Currency)
|
curr = currencyTransform(inp.Currency)
|
||||||
|
symbolPostfixForCard = fmt.Sprintf(" (%s)", inp.Currency.Symbol)
|
||||||
} else {
|
} else {
|
||||||
curr = types.DbCurrency{}
|
curr = types.DbCurrency{}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +28,7 @@ var cardTransform func(inp *db.Card) types.DbCard = func(inp *db.Card) types.DbC
|
||||||
LastDigits: inp.LastDigits,
|
LastDigits: inp.LastDigits,
|
||||||
CurrencyID: inp.CurrencyID,
|
CurrencyID: inp.CurrencyID,
|
||||||
Currency: curr,
|
Currency: curr,
|
||||||
DisplayName: fmt.Sprintf("%s •%s", inp.Name, inp.LastDigits),
|
DisplayName: fmt.Sprintf("%s •%s%s", inp.Name, inp.LastDigits, symbolPostfixForCard),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,35 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
||||||
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
"git.qowevisa.me/Qowevisa/fin-check-api/types"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var expenseTransform func(inp *db.Expense) types.DbExpense = func(inp *db.Expense) types.DbExpense {
|
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{
|
return types.DbExpense{
|
||||||
ID: inp.ID,
|
ID: inp.ID,
|
||||||
CardID: inp.CardID,
|
CardID: inp.CardID,
|
||||||
TypeID: inp.TypeID,
|
TypeID: inp.TypeID,
|
||||||
Value: inp.Value,
|
Value: inp.Value,
|
||||||
Comment: inp.Comment,
|
Comment: inp.Comment,
|
||||||
Date: inp.Date,
|
Date: inp.Date,
|
||||||
|
Card: card,
|
||||||
|
ShowValue: showValue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +69,7 @@ func ExpenseGetAll(c *gin.Context) {
|
||||||
}
|
}
|
||||||
dbc := db.Connect()
|
dbc := db.Connect()
|
||||||
var entities []*db.Expense
|
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()})
|
c.JSON(500, types.ErrorResponse{Message: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,9 @@ type DbExpense struct {
|
||||||
Value uint64 `json:"value" example:"20000"`
|
Value uint64 `json:"value" example:"20000"`
|
||||||
Comment string `json:"comment" example:"pizza"`
|
Comment string `json:"comment" example:"pizza"`
|
||||||
Date time.Time `json:"date" example:"29/11/2001 12:00"`
|
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 {
|
type DbTransfer struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user