Skip to content

Commit bdc1125

Browse files
committed
Minor linting fixes
1 parent 6cdf011 commit bdc1125

File tree

5 files changed

+34
-67
lines changed

5 files changed

+34
-67
lines changed

frontend/src/components/accounts/AccountCard.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,18 @@ export function AccountCard({ account }: AccountCardProps) {
9595
className="p-2 md:p-2.5 rounded-xl flex-shrink-0"
9696
style={{ backgroundColor: `${account.color}15` }}
9797
>
98-
<Icon className="w-4 md:w-5 h-4 md:h-5" style={{ color: account.color }} />
98+
<Icon
99+
className="w-4 md:w-5 h-4 md:h-5"
100+
style={{ color: account.color }}
101+
/>
99102
</div>
100103
<div className="min-w-0">
101-
<h3 className="font-semibold text-quaternary text-sm md:text-base truncate">{account.name}</h3>
102-
<p className="text-xs md:text-sm text-quaternary/60 truncate">{accountType.label}</p>
104+
<h3 className="font-semibold text-quaternary text-sm md:text-base truncate">
105+
{account.name}
106+
</h3>
107+
<p className="text-xs md:text-sm text-quaternary/60 truncate">
108+
{accountType.label}
109+
</p>
103110
</div>
104111
</div>
105112
<ChevronRight className="w-4 md:w-5 h-4 md:h-5 text-quaternary/30 group-hover:text-quaternary/60 group-hover:translate-x-1 transition-all flex-shrink-0" />

frontend/src/components/reports/DonutChart.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,22 @@ export function DonutChart({
4646
const entries = data
4747
.map((cat) => [cat.category, cat.amount] as [string, number])
4848
.sort((a, b) => b[1] - a[1]);
49-
let currentAngle = 0;
5049
const radius = 80;
5150
const circumference = 2 * Math.PI * radius;
5251

53-
return entries.map(([category, amount]) => {
52+
return entries.map(([category, amount], index) => {
5453
const percentage = total > 0 ? (amount / total) * 100 : 0;
54+
55+
// Calculate current angle based on all previous segments
56+
const currentAngle = entries
57+
.slice(0, index)
58+
.reduce((sum, [, prevAmount]) => {
59+
const prevPercentage = total > 0 ? (prevAmount / total) * 100 : 0;
60+
return sum + (prevPercentage / 100) * 360;
61+
}, 0);
62+
5563
const strokeDasharray = (percentage / 100) * circumference;
5664
const strokeDashoffset = -currentAngle * (circumference / 360);
57-
currentAngle += (percentage / 100) * 360;
5865

5966
return {
6067
category,

frontend/src/pages/Reports.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function Reports() {
122122
};
123123

124124
fetchReport();
125-
}, [period, currentDate]);
125+
}, [period, currentDate, getDateParam]);
126126

127127
// Currency formatting
128128
const currencyInfo = CURRENCIES.find((c) => c.code === report?.currency);

internal/handlers/reports.go

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,14 @@ func NewReportHandler(db *sql.DB, exchangeService *services.ExchangeService) *Re
1818
return &ReportHandler{db: db, exchangeService: exchangeService}
1919
}
2020

21-
type CategoryReport struct {
22-
Category string `json:"category"`
23-
Amount float64 `json:"amount"`
24-
Budget *float64 `json:"budget,omitempty"`
25-
Percentage *float64 `json:"percentage,omitempty"`
26-
Remaining *float64 `json:"remaining,omitempty"`
27-
}
28-
2921
type ReportResponse struct {
30-
PeriodStart string `json:"period_start"`
31-
PeriodEnd string `json:"period_end"`
32-
Currency string `json:"currency"`
33-
TotalIncome float64 `json:"total_income"`
34-
TotalExpenses float64 `json:"total_expenses"`
35-
ExpensesByCategory []CategoryReport `json:"expenses_by_category"`
36-
FirstTransactionDate *string `json:"first_transaction_date"`
22+
PeriodStart string `json:"period_start"`
23+
PeriodEnd string `json:"period_end"`
24+
Currency string `json:"currency"`
25+
TotalIncome float64 `json:"total_income"`
26+
TotalExpenses float64 `json:"total_expenses"`
27+
ExpensesByCategory map[string]float64 `json:"expenses_by_category"`
28+
FirstTransactionDate *string `json:"first_transaction_date"`
3729
}
3830

3931
func (h *ReportHandler) GetReport(w http.ResponseWriter, r *http.Request) {
@@ -139,7 +131,7 @@ func (h *ReportHandler) GetReport(w http.ResponseWriter, r *http.Request) {
139131
Currency: baseCurrency,
140132
TotalIncome: 0,
141133
TotalExpenses: 0,
142-
ExpensesByCategory: []CategoryReport{},
134+
ExpensesByCategory: make(map[string]float64),
143135
}, http.StatusOK)
144136
return
145137
}
@@ -185,9 +177,10 @@ func (h *ReportHandler) GetReport(w http.ResponseWriter, r *http.Request) {
185177
}
186178

187179
// Categorize based on transaction type
188-
if txType == "deposit" {
180+
switch txType {
181+
case "deposit":
189182
totalIncome += convertedAmount
190-
} else if txType == "withdrawal" || txType == "expense" {
183+
case "withdrawal", "expense":
191184
totalExpenses += convertedAmount
192185
expensesByCategory[category] += convertedAmount
193186
}
@@ -209,53 +202,13 @@ func (h *ReportHandler) GetReport(w http.ResponseWriter, r *http.Request) {
209202
firstTxDate = &dateStr
210203
}
211204

212-
// Fetch user's budgets (only for monthly reports)
213-
budgets := make(map[string]float64)
214-
if period == "month" {
215-
budgetRows, err := h.db.Query(`
216-
SELECT category, monthly_limit
217-
FROM category_budgets
218-
WHERE user_id = ?
219-
`, userID)
220-
if err == nil {
221-
defer budgetRows.Close()
222-
for budgetRows.Next() {
223-
var category string
224-
var limit float64
225-
if err := budgetRows.Scan(&category, &limit); err == nil {
226-
budgets[category] = limit
227-
}
228-
}
229-
}
230-
}
231-
232-
// Build category reports with budget information
233-
categoryReports := make([]CategoryReport, 0, len(expensesByCategory))
234-
for category, amount := range expensesByCategory {
235-
catReport := CategoryReport{
236-
Category: category,
237-
Amount: amount,
238-
}
239-
240-
// Add budget info if exists for this category
241-
if budget, hasBudget := budgets[category]; hasBudget {
242-
catReport.Budget = &budget
243-
percentage := (amount / budget) * 100
244-
catReport.Percentage = &percentage
245-
remaining := budget - amount
246-
catReport.Remaining = &remaining
247-
}
248-
249-
categoryReports = append(categoryReports, catReport)
250-
}
251-
252205
report := ReportResponse{
253206
PeriodStart: startDate.Format("2006-01-02"),
254207
PeriodEnd: endDate.Format("2006-01-02"),
255208
Currency: baseCurrency,
256209
TotalIncome: totalIncome,
257210
TotalExpenses: totalExpenses,
258-
ExpensesByCategory: categoryReports,
211+
ExpensesByCategory: expensesByCategory,
259212
FirstTransactionDate: firstTxDate,
260213
}
261214

internal/handlers/transactions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func (h *TransactionHandler) Transfer(w http.ResponseWriter, r *http.Request) {
542542
}
543543

544544
// Helper to get account type from string
545-
func (h *TransactionHandler) isAssetAccount(accountType models.AccountType) bool {
545+
func (h *TransactionHandler) IsAssetAccount(accountType models.AccountType) bool {
546546
return accountType == models.AccountTypeCash ||
547547
accountType == models.AccountTypeDebit ||
548548
accountType == models.AccountTypeSaving ||

0 commit comments

Comments
 (0)