Files
ExpSplitter/src/expenses/models/expenseRepoMap.go
T
esilva 06aafa4ee1 Adding the PaidOff column to the Apps logic
Also had to readd a schema.sql file because sqlc was failing
at parsing the migrations directory correctly
2025-08-13 23:49:03 +01:00

80 lines
1.9 KiB
Go

package models
import (
repo "expenses/expenses/db/repository"
"github.com/shopspring/decimal"
)
func mapRepoGetExpenseRow(e repo.GetExpenseRow) Expense {
value, _ := decimal.NewFromString(e.Expense.Value)
return Expense{
ExpID: e.Expense.ExpID,
Description: e.Expense.Description,
Value: value,
Store: Store{
StoreID: e.Store.StoreID,
StoreName: e.Store.StoreName,
},
Type: Type{
TypeID: e.ExpenseType.TypeID,
TypeName: e.ExpenseType.TypeName,
},
Category: Category{
CategoryID: e.Category.CategoryID,
CategoryName: e.Category.CategoryName,
},
Owner: User{
UserID: e.User.UserID,
UserName: e.User.UserName,
},
Date: e.Expense.ExpDate,
Shares: []ExpenseShare{},
Payments: []ExpensePayment{},
PaidOff: e.Expense.PaidOff,
SharesEven: e.Expense.SharesEven,
CreationDate: e.Expense.CreationDate,
}
}
func mapRepoGetExpenseRowMulti(e repo.GetExpensesRow) Expense {
value, _ := decimal.NewFromString(e.Expense.Value)
return Expense{
ExpID: e.Expense.ExpID,
Description: e.Expense.Description,
Value: value,
Store: Store{
StoreID: e.Store.StoreID,
StoreName: e.Store.StoreName,
},
Type: Type{
TypeID: e.ExpenseType.TypeID,
TypeName: e.ExpenseType.TypeName,
},
Category: Category{
CategoryID: e.Category.CategoryID,
CategoryName: e.Category.CategoryName,
},
Owner: User{
UserID: e.User.UserID,
UserName: e.User.UserName,
},
Date: e.Expense.ExpDate,
Shares: []ExpenseShare{},
Payments: []ExpensePayment{},
PaidOff: e.Expense.PaidOff,
SharesEven: e.Expense.SharesEven,
CreationDate: e.Expense.CreationDate,
}
}
func mapRepoGetExpensesRows(er []repo.GetExpensesRow) []Expense {
expenses := make([]Expense, len(er))
for k, exp := range er {
expenses[k] = mapRepoGetExpenseRowMulti(exp)
}
return expenses
}