feat: Refactor API routes to separate public and protected endpoints for better organization
This commit is contained in:
parent
460235b832
commit
baf656c093
@ -16,22 +16,28 @@ func SetupRouter(r *gin.Engine) {
|
||||
projectHandler := handlers.NewProjectHandler()
|
||||
timeEntryHandler := handlers.NewTimeEntryHandler()
|
||||
|
||||
// Public routes
|
||||
r.POST("/auth/login", userHandler.Login)
|
||||
r.POST("/auth/register", userHandler.Register)
|
||||
|
||||
// API routes (protected)
|
||||
// API routes
|
||||
api := r.Group("/api")
|
||||
api.Use(middleware.AuthMiddleware())
|
||||
{
|
||||
// Auth routes
|
||||
// Auth routes (public)
|
||||
auth := api.Group("/auth")
|
||||
{
|
||||
auth.GET("/me", userHandler.GetCurrentUser)
|
||||
auth.POST("/login", userHandler.Login)
|
||||
auth.POST("/register", userHandler.Register)
|
||||
}
|
||||
|
||||
// Protected routes
|
||||
protected := api.Group("")
|
||||
protected.Use(middleware.AuthMiddleware())
|
||||
{
|
||||
// Auth routes (protected)
|
||||
protectedAuth := protected.Group("/auth")
|
||||
{
|
||||
protectedAuth.GET("/me", userHandler.GetCurrentUser)
|
||||
}
|
||||
|
||||
// User routes
|
||||
users := api.Group("/users")
|
||||
users := protected.Group("/users")
|
||||
{
|
||||
users.GET("", userHandler.GetUsers)
|
||||
users.GET("/:id", userHandler.GetUserByID)
|
||||
@ -41,7 +47,7 @@ func SetupRouter(r *gin.Engine) {
|
||||
}
|
||||
|
||||
// Activity routes
|
||||
activities := api.Group("/activities")
|
||||
activities := protected.Group("/activities")
|
||||
{
|
||||
activities.GET("", activityHandler.GetActivities)
|
||||
activities.GET("/:id", activityHandler.GetActivityByID)
|
||||
@ -51,7 +57,7 @@ func SetupRouter(r *gin.Engine) {
|
||||
}
|
||||
|
||||
// Company routes
|
||||
companies := api.Group("/companies")
|
||||
companies := protected.Group("/companies")
|
||||
{
|
||||
companies.GET("", companyHandler.GetCompanies)
|
||||
companies.GET("/:id", companyHandler.GetCompanyByID)
|
||||
@ -61,7 +67,7 @@ func SetupRouter(r *gin.Engine) {
|
||||
}
|
||||
|
||||
// Customer routes
|
||||
customers := api.Group("/customers")
|
||||
customers := protected.Group("/customers")
|
||||
{
|
||||
customers.GET("", customerHandler.GetCustomers)
|
||||
customers.GET("/:id", customerHandler.GetCustomerByID)
|
||||
@ -72,7 +78,7 @@ func SetupRouter(r *gin.Engine) {
|
||||
}
|
||||
|
||||
// Project routes
|
||||
projects := api.Group("/projects")
|
||||
projects := protected.Group("/projects")
|
||||
{
|
||||
projects.GET("", projectHandler.GetProjects)
|
||||
projects.GET("/with-customers", projectHandler.GetProjectsWithCustomers)
|
||||
@ -84,7 +90,7 @@ func SetupRouter(r *gin.Engine) {
|
||||
}
|
||||
|
||||
// Time Entry routes
|
||||
timeEntries := api.Group("/time-entries")
|
||||
timeEntries := protected.Group("/time-entries")
|
||||
{
|
||||
timeEntries.GET("", timeEntryHandler.GetTimeEntries)
|
||||
timeEntries.GET("/me", timeEntryHandler.GetMyTimeEntries)
|
||||
@ -97,4 +103,5 @@ func SetupRouter(r *gin.Engine) {
|
||||
timeEntries.DELETE("/:id", timeEntryHandler.DeleteTimeEntry)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user