fix(router): change route declaration

This commit is contained in:
2021-11-04 02:04:19 +01:00
parent a25fd2d265
commit 2676b09728
2 changed files with 16 additions and 19 deletions

View File

@@ -22,7 +22,7 @@ func NewRouter(config *handler.Config) *gin.Engine {
router.HandleMethodNotAllowed = true
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowOrigins: []string{"http://localhost:8080/", "http://localhost:8080"},
AllowMethods: []string{"*"},
AllowHeaders: []string{"*"},
ExposeHeaders: []string{"*"},
@@ -44,33 +44,28 @@ func NewRouter(config *handler.Config) *gin.Engine {
public.Handle(http.MethodGet, "/_health", hc.GetHealth)
userRoute := public.Group("/users")
userRoute.Handle("LOGIN", "", uh.ConnectUser)
userRoute.Handle("GET", "", uh.ConnectUser)
userRoute.Handle(http.MethodPost, "", uh.CreateUser)
securedUserRoute := userRoute.Group("")
//TODO add secure auth
securedUserRoute.Handle(http.MethodGet, "/:userId", uh.GetUser)
// end: user routes
securedAccountRoute := securedUserRoute.Group("/:userId/accounts")
//account route
securedAccountRoute.Handle(http.MethodGet, "/", ah.GetAllAccountOfUser)
securedAccountRoute.Handle(http.MethodPost, "/:accountId", ah.CreateAccountOfUser)
securedAccountRoute.Handle(http.MethodDelete, "/:accountId", ah.DeleteAccountOfUser)
securedAccountRoute.Handle(http.MethodGet, "/", ah.GetSpecificAccountOfUser)
securedUserRoute.Handle(http.MethodGet, "/:userId/accounts", ah.GetAllAccountOfUser)
securedUserRoute.Handle(http.MethodPost, "/:userId/accounts/:accountId", ah.CreateAccountOfUser)
securedUserRoute.Handle(http.MethodDelete, "/:userId/accounts/:accountId", ah.DeleteAccountOfUser)
securedUserRoute.Handle(http.MethodGet, "/:userId/accounts/:accountId", ah.GetSpecificAccountOfUser)
securedSharedAccountRoute := securedUserRoute.Group("/:userId/sharedaccounts")
//shared route
securedSharedAccountRoute.Handle(http.MethodPost, "/:accountId", sah.ShareAnAccount)
securedSharedAccountRoute.Handle(http.MethodDelete, "/:accountId", sah.DeleteSharedAccount)
securedSharedAccountRoute.Handle(http.MethodGet, "/", sah.GetAllSharedAccountOfUser)
securedSharedAccountRoute.Handle(http.MethodGet, "/:sharedAccountId", sah.GetSpecificSharedAccountOfUser)
securedUserRoute.Handle(http.MethodPost, "/:userId/sharedaccounts/:accountId", sah.ShareAnAccount)
securedUserRoute.Handle(http.MethodDelete, "/:userId/sharedaccounts/:accountId", sah.DeleteSharedAccount)
securedUserRoute.Handle(http.MethodGet, "/:userId/sharedaccounts", sah.GetAllSharedAccountOfUser)
securedUserRoute.Handle(http.MethodGet, "/:userId/sharedaccounts/:sharedAccountId", sah.GetSpecificSharedAccountOfUser)
securedExpenseRoute := securedUserRoute.Group("/:userId/accounts/:accountId/expenses")
//expense route
securedExpenseRoute.Handle(http.MethodPost, "/", eh.CreateAnExpense)
securedExpenseRoute.Handle(http.MethodDelete, "/:expenseId", eh.DeleteExpense)
securedExpenseRoute.Handle(http.MethodGet, "/", eh.GetAllExpenses)
securedExpenseRoute.Handle(http.MethodGet, "/:expenseId", eh.GetAnExpenses)
securedUserRoute.Handle(http.MethodPost, "/:userId/accounts/:accountId/expenses", eh.CreateAnExpense)
securedUserRoute.Handle(http.MethodDelete, "/:userId/accounts/:accountId/expenses/:expenseId", eh.DeleteExpense)
securedUserRoute.Handle(http.MethodGet, "/:userId/accounts/:accountId/expenses", eh.GetAllExpenses)
securedUserRoute.Handle(http.MethodGet, "/:userId/accounts/:accountId/expenses/:expenseId", eh.GetAnExpenses)
return router
}