feat(savings): Add savings module with categories, transactions, recurring plans

- Categories: regular, deposits, credits, recurring, multi-user, accounts
- Transactions: deposits and withdrawals with user tracking
- Recurring plans: monthly payment obligations per user
- Stats: overdues calculation with allocation algorithm
- Excludes is_account categories from total sums
- Documentation: docs/SAVINGS.md
This commit is contained in:
Cosmo
2026-02-16 06:48:09 +00:00
parent 9e90aa6d95
commit 2a50e50771
18 changed files with 2910 additions and 162 deletions

View File

@@ -38,11 +38,13 @@ func main() {
habitRepo := repository.NewHabitRepository(db)
taskRepo := repository.NewTaskRepository(db)
emailTokenRepo := repository.NewEmailTokenRepository(db)
habitFreezeRepo := repository.NewHabitFreezeRepository(db)
savingsRepo := repository.NewSavingsRepository(db)
// Initialize services
emailService := service.NewEmailService(cfg.ResendAPIKey, cfg.FromEmail, cfg.FromName, cfg.AppURL)
authService := service.NewAuthService(userRepo, emailTokenRepo, emailService, cfg.JWTSecret)
habitService := service.NewHabitService(habitRepo)
habitService := service.NewHabitService(habitRepo, habitFreezeRepo)
taskService := service.NewTaskService(taskRepo)
// Initialize Telegram bot
@@ -57,7 +59,7 @@ func main() {
}
// Initialize scheduler
sched := scheduler.New(telegramBot, userRepo, taskRepo, habitRepo)
sched := scheduler.New(telegramBot, userRepo, taskRepo, habitRepo, habitFreezeRepo)
sched.Start()
defer sched.Stop()
@@ -67,6 +69,8 @@ func main() {
taskHandler := handler.NewTaskHandler(taskService)
healthHandler := handler.NewHealthHandler()
profileHandler := handler.NewProfileHandler(userRepo)
habitFreezeHandler := handler.NewHabitFreezeHandler(habitFreezeRepo, habitRepo)
savingsHandler := handler.NewSavingsHandler(savingsRepo)
// Initialize middleware
authMiddleware := customMiddleware.NewAuthMiddleware(cfg.JWTSecret)
@@ -124,6 +128,11 @@ func main() {
r.Get("/habits/{id}/logs", habitHandler.GetLogs)
r.Delete("/habits/{id}/logs/{logId}", habitHandler.DeleteLog)
// Habit freezes
r.Get("/habits/{id}/freezes", habitFreezeHandler.List)
r.Post("/habits/{id}/freezes", habitFreezeHandler.Create)
r.Delete("/habits/{id}/freezes/{freezeId}", habitFreezeHandler.Delete)
// Stats
r.Get("/habits/stats", habitHandler.Stats)
r.Get("/habits/{id}/stats", habitHandler.HabitStats)
@@ -137,6 +146,34 @@ func main() {
r.Delete("/tasks/{id}", taskHandler.Delete)
r.Post("/tasks/{id}/complete", taskHandler.Complete)
r.Post("/tasks/{id}/uncomplete", taskHandler.Uncomplete)
// Savings routes
r.Get("/savings/categories", savingsHandler.ListCategories)
r.Post("/savings/categories", savingsHandler.CreateCategory)
r.Get("/savings/categories/{id}", savingsHandler.GetCategory)
r.Put("/savings/categories/{id}", savingsHandler.UpdateCategory)
r.Delete("/savings/categories/{id}", savingsHandler.DeleteCategory)
// Savings category members
r.Get("/savings/categories/{id}/members", savingsHandler.ListMembers)
r.Post("/savings/categories/{id}/members", savingsHandler.AddMember)
r.Delete("/savings/categories/{id}/members/{userId}", savingsHandler.RemoveMember)
// Savings recurring plans
r.Get("/savings/categories/{id}/recurring-plans", savingsHandler.ListRecurringPlans)
r.Post("/savings/categories/{id}/recurring-plans", savingsHandler.CreateRecurringPlan)
r.Delete("/savings/recurring-plans/{planId}", savingsHandler.DeleteRecurringPlan)
r.Put("/savings/recurring-plans/{planId}", savingsHandler.UpdateRecurringPlan)
// Savings transactions
r.Get("/savings/transactions", savingsHandler.ListTransactions)
r.Post("/savings/transactions", savingsHandler.CreateTransaction)
r.Get("/savings/transactions/{id}", savingsHandler.GetTransaction)
r.Put("/savings/transactions/{id}", savingsHandler.UpdateTransaction)
r.Delete("/savings/transactions/{id}", savingsHandler.DeleteTransaction)
// Savings stats
r.Get("/savings/stats", savingsHandler.Stats)
})
port := os.Getenv("PORT")