Last active
May 22, 2021 10:32
-
-
Save dipeshhkc/077750fdca6b26c9306c11cd239df887 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package route | |
func RunAPI(address string) error { | |
userHandler := handler.NewUserHandler() | |
productHandler := handler.NewProductHandler() | |
orderHandler := handler.NewOrderHandler() | |
r := gin.Default() | |
r.GET("/", func(ctx *gin.Context) { | |
ctx.String(http.StatusOK, "Welcome to Our Mini Ecommerce") | |
}) | |
apiRoutes := r.Group("/api") | |
userRoutes := apiRoutes.Group("/user") | |
{ | |
userRoutes.POST("/register", userHandler.AddUser) | |
userRoutes.POST("/signin", userHandler.SignInUser) | |
} | |
userProtectedRoutes := apiRoutes.Group("/users", middleware.AuthorizeJWT()) | |
{ | |
userProtectedRoutes.GET("/", userHandler.GetAllUser) | |
userProtectedRoutes.GET("/:user", userHandler.GetUser) | |
userProtectedRoutes.GET("/:user/products", userHandler.GetProductOrdered) | |
userProtectedRoutes.PUT("/:user", userHandler.UpdateUser) | |
userProtectedRoutes.DELETE("/:user", userHandler.DeleteUser) | |
} | |
productProtectedRoutes := apiRoutes.Group("/products", middleware.AuthorizeJWT()) | |
{ | |
productProtectedRoutes.GET("/", productHandler.GetAllProduct) | |
productProtectedRoutes.GET("/:product", productHandler.GetProduct) | |
productProtectedRoutes.POST("/", productHandler.AddProduct) | |
productProtectedRoutes.PUT("/:product", productHandler.UpdateProduct) | |
productProtectedRoutes.DELETE("/:product", productHandler.DeleteProduct) | |
} | |
orderProtectedRoutes := apiRoutes.Group("/order", middleware.AuthorizeJWT()) | |
{ | |
orderProtectedRoutes.POST("/product/:product/quantity/:quantity", orderHandler.OrderProduct) | |
} | |
return r.Run(address) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment