diff options
author | 2025-04-26 01:06:54 +0530 | |
---|---|---|
committer | 2025-04-26 01:06:54 +0530 | |
commit | 9d65a782ca3e2084ef0f560500f6014d7bd09bc0 (patch) | |
tree | e97195e8b967267d8d40098ae40a940fa2d44571 /backend/cmd/api/main.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/cmd/api/main.go')
-rw-r--r-- | backend/cmd/api/main.go | 59 |
1 files changed, 3 insertions, 56 deletions
diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index f882175..4884d12 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -6,12 +6,12 @@ import ( "os" "time" - "finance/backend/handlers" "finance/backend/internal/config" "finance/backend/internal/database" "finance/backend/internal/logger" "finance/backend/internal/middleware" "finance/backend/internal/models" + "finance/backend/internal/router" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" @@ -53,17 +53,8 @@ func main() { log.Fatal("Failed to migrate database:", err) } - // Initialize handlers - goalHandler := handlers.NewGoalHandler() - // Initialize other handlers as needed - // userHandler := handlers.NewUserHandler() - // accountHandler := handlers.NewAccountHandler() - // transactionHandler := handlers.NewTransactionHandler() - // loanHandler := handlers.NewLoanHandler() - // authHandler := handlers.NewAuthHandler() - - // Create a new Gin router without default middleware - r := gin.New() + // Initialize the router from the internal/router package + r := router.SetupRouter(cfg) // Add custom middleware r.Use(middleware.RequestLogger(log)) @@ -102,50 +93,6 @@ func main() { c.JSON(http.StatusOK, gin.H{"status": "ok", "message": "Database connection is healthy"}) }) - // API v1 routes - v1 := r.Group("/api/v1") - - // Authentication routes (no JWT required) - // v1.POST("/register", authHandler.Register) - // v1.POST("/login", authHandler.Login) - - // Protected routes (JWT required) - protected := v1.Group("") - // protected.Use(authHandler.JWTAuth) - - // User routes - // 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) - - // 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) - // Start server serverAddr := fmt.Sprintf("%s:%d", cfg.ServerHost, cfg.ServerPort) log.Info("Server starting on", serverAddr) |