diff --git a/src/expenses/db/migrations/custom/0004_calculated_share.lua b/src/expenses/db/migrations/custom/0004_calculated_share.lua index d367d3e..ceea4aa 100644 --- a/src/expenses/db/migrations/custom/0004_calculated_share.lua +++ b/src/expenses/db/migrations/custom/0004_calculated_share.lua @@ -10,7 +10,7 @@ local function printTable(t) if type(value) == "table" then printTable(value) else - print(key, value) + print(key, ":", value) end end end @@ -42,19 +42,24 @@ if not expenses then end for i = 1, #expenses do + -- print "------------------------------------" local eJson = expenses[i].expense local e = json.decode(eJson) if not isOwnerInShares(e) then -- Insert a share in the owner user into shares as 0.0 + goto continue end if not isOwnerInPayments(e) then -- Insert a share in the owner user into shares as 0.0 + goto continue end normalizedExpense = NormalizeShare(eJson) if eJson == normalizedExpense then print "This one needs to be updated" end + + ::continue:: end diff --git a/src/expenses/expenses_lua.go b/src/expenses/expenses_lua.go index 1ad543b..3f25ea3 100644 --- a/src/expenses/expenses_lua.go +++ b/src/expenses/expenses_lua.go @@ -3,19 +3,23 @@ package expenses import ( "encoding/json" mod "expenses/expenses/models" + "log" lua "github.com/yuin/gopher-lua" ) func (a *ExpensesApp) luaGetAllExpenses(L *lua.LState) int { + log.Println("HERE") tx, err := a.DB.Begin() if err != nil { return returnWithError(L, err.Error()) } defer tx.Rollback() + log.Println("HERE 2") expenses, err := mod.GetAllExpenses(tx) + log.Println("HERE 2") tbl := L.NewTable() for _, e := range expenses { err := a.LoadExpensePayments(&e) @@ -28,7 +32,8 @@ func (a *ExpensesApp) luaGetAllExpenses(L *lua.LState) int { return returnWithError(L, err.Error()) } - jsonData, err := json.Marshal(e) + jsonData, err := json.Marshal(&e) + log.Println(string(jsonData)) et := L.NewTable() et.RawSetString("expense", lua.LString(jsonData)) diff --git a/src/expenses/models/expense.go b/src/expenses/models/expense.go index 1001610..41a52bd 100644 --- a/src/expenses/models/expense.go +++ b/src/expenses/models/expense.go @@ -19,7 +19,7 @@ type Expense struct { Store Store `json:"Store"` Type Type `json:"Type"` Category Category `json:"Category"` - Owner User `json:"User"` + Owner User `json:"Owner"` Date int64 `json:"Date"` Payments []ExpensePayment `json:"Payments"` Shares []Share `json:"Shares"`