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

View File

@@ -3,6 +3,7 @@ package account
import ( import (
"nos-comptes/internal/storage/dao" "nos-comptes/internal/storage/dao"
"nos-comptes/internal/storage/model" "nos-comptes/internal/storage/model"
"nos-comptes/internal/utils"
) )
type Service struct { type Service struct {
@@ -11,6 +12,7 @@ type Service struct {
func (s *Service) GetAllAccountOfUser(userId string) ([]*Account, error) { func (s *Service) GetAllAccountOfUser(userId string) ([]*Account, error) {
accounts, err := s.db.GetAllAccountOfUser(userId) accounts, err := s.db.GetAllAccountOfUser(userId)
utils.GetLogger().Warn(err)
if e, ok := err.(*dao.Error); ok { if e, ok := err.(*dao.Error); ok {
switch { switch {
case e.Type == dao.ErrTypeNotFound: case e.Type == dao.ErrTypeNotFound: