Skip to content

Commit

Permalink
phone| feat: add get summary expense func
Browse files Browse the repository at this point in the history
  • Loading branch information
varissara-techup committed May 18, 2024
1 parent fe22498 commit e53f400
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions api/transaction/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,50 @@ type Balance struct {
TotalAmountSpent float64 `json:"total_amount_spent"`
TotalAmountSaved float64 `json:"total_amount_saved"`
}

func getTransection() []Transaction {
mockTransaction := []Transaction{
{
Id: 1,
Date: "2024-04-30T09:00:00.000Z",
Amount: 1000,
Catergory: "Food",
TransectionType: "expense",
Note: "Lunch",
ImageUrl: "https://example.com/image1.jpg",
SpenderId: 1,
},
{
Id: 2,
Date: "2024-04-29T19:00:00.000Z",
Amount: 2000,
Catergory: "Transport",
TransectionType: "income",
Note: "Salary",
ImageUrl: "https://example.com/image2.jpg",
SpenderId: 1,
},
}

return mockTransaction
}

func GetSummaryExpenses() SummaryExpenses {
transactions := getTransection()
totalAmountSpent := 0.0
totalNumberSpent := 0

for _, transaction := range transactions {
if transaction.TransectionType == "expense" {
totalAmountSpent += transaction.Amount
totalNumberSpent++
}
}

return SummaryExpenses{
TotalAmountSpent: totalAmountSpent,
AvgAmountSpentPerDay: totalAmountSpent / float64(totalNumberSpent),
TotalNumberSpent: totalNumberSpent,
}

}

0 comments on commit e53f400

Please sign in to comment.