Compare commits
No commits in common. "4d452737cda0afff2ab1602142c8c35a649773c1" and "46ab4ee7a0ff4807743168f1a0c5860c2287161a" have entirely different histories.
4d452737cd
...
46ab4ee7a0
|
@ -12,10 +12,8 @@ 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{}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +26,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%s", inp.Name, inp.LastDigits, symbolPostfixForCard),
|
DisplayName: fmt.Sprintf("%s •%s", inp.Name, inp.LastDigits),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,19 @@
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +53,7 @@ func ExpenseGetAll(c *gin.Context) {
|
||||||
}
|
}
|
||||||
dbc := db.Connect()
|
dbc := db.Connect()
|
||||||
var entities []*db.Expense
|
var entities []*db.Expense
|
||||||
if err := dbc.Preload("Card.Currency").Find(&entities, db.Expense{UserID: userID}).Error; err != nil {
|
if err := dbc.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,9 +82,6 @@ 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