diff options
author | 2025-04-26 01:06:54 +0530 | |
---|---|---|
committer | 2025-04-26 01:06:54 +0530 | |
commit | 9d65a782ca3e2084ef0f560500f6014d7bd09bc0 (patch) | |
tree | e97195e8b967267d8d40098ae40a940fa2d44571 /backend/internal/router/router.go | |
parent | 84622698f6c0e9d76ebe434c00df587908a37015 (diff) | |
download | finance-9d65a782ca3e2084ef0f560500f6014d7bd09bc0.tar.gz finance-9d65a782ca3e2084ef0f560500f6014d7bd09bc0.tar.bz2 finance-9d65a782ca3e2084ef0f560500f6014d7bd09bc0.zip |
finance/backend: mvfeat: moved the backend api handlers to api/handlers and added couple of more api request handlers
Diffstat (limited to 'backend/internal/router/router.go')
-rw-r--r-- | backend/internal/router/router.go | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/backend/internal/router/router.go b/backend/internal/router/router.go index b82e1af..3a4d413 100644 --- a/backend/internal/router/router.go +++ b/backend/internal/router/router.go @@ -1,8 +1,7 @@ package router import ( - "finance/backend/internal/api/auth" - "finance/backend/internal/api/v1/users" + "finance/backend/internal/api/handlers" "finance/backend/internal/config" "finance/backend/internal/database" "net/http" @@ -66,21 +65,57 @@ func SetupRouter(cfg *config.Config) *gin.Engine { }) }) + // Initialize handlers + authHandler := handlers.NewAuthHandler(cfg) + goalHandler := handlers.NewGoalHandler() + userHandler := handlers.NewUserHandler() + accountHandler := handlers.NewAccountHandler() + transactionHandler := handlers.NewTransactionHandler() + loanHandler := handlers.NewLoanHandler() + // API v1 routes v1 := r.Group("/api/v1") { // Auth routes (public) - v1.POST("/auth/signup", auth.Signup(cfg)) - v1.POST("/auth/login", auth.Login(cfg)) + v1.POST("/auth/signup", authHandler.Register) + v1.POST("/auth/login", authHandler.Login) // Protected routes protected := v1.Group("") - protected.Use(auth.AuthMiddleware(cfg)) + protected.Use(authHandler.JWTAuth) { // User routes - protected.GET("/users/me", users.GetCurrentUser) + protected.GET("/users/me", userHandler.GetCurrentUser) + protected.PUT("/users/me", userHandler.UpdateCurrentUser) + + // Account routes + protected.GET("/accounts", accountHandler.GetAccounts) + protected.GET("/accounts/:id", accountHandler.GetAccountByID) + protected.POST("/accounts", accountHandler.CreateAccount) + protected.PUT("/accounts/:id", accountHandler.UpdateAccount) + protected.DELETE("/accounts/:id", accountHandler.DeleteAccount) + + // Transaction routes + protected.GET("/transactions", transactionHandler.GetTransactions) + protected.GET("/transactions/:id", transactionHandler.GetTransactionByID) + protected.POST("/transactions", transactionHandler.CreateTransaction) + protected.PUT("/transactions/:id", transactionHandler.UpdateTransaction) + protected.DELETE("/transactions/:id", transactionHandler.DeleteTransaction) + + // Goal routes + protected.GET("/goals", goalHandler.GetGoals) + protected.GET("/goals/:id", goalHandler.GetGoal) + protected.POST("/goals", goalHandler.CreateGoal) + protected.PUT("/goals/:id", goalHandler.UpdateGoal) + protected.DELETE("/goals/:id", goalHandler.DeleteGoal) + protected.PATCH("/goals/:id/progress", goalHandler.UpdateGoalProgress) - // Add other protected routes here + // Loan routes + protected.GET("/loans", loanHandler.GetLoans) + protected.GET("/loans/:id", loanHandler.GetLoanByID) + protected.POST("/loans", loanHandler.CreateLoan) + protected.PUT("/loans/:id", loanHandler.UpdateLoan) + protected.DELETE("/loans/:id", loanHandler.DeleteLoan) } } |