Skip to content

Commit

Permalink
GetRequest Removed from authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
alnck committed Feb 13, 2022
1 parent adb6ed0 commit 64acd17
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/services/blog-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ func main() {
r.POST("/login", handler.LoginHandler)

api := r.Group("/api")
api.Use(middleware.ValidateToken())

initBlogRouteMap(api)
initUserRouteMap(api)
validateTokenHandle := middleware.ValidateToken()
authHandle := middleware.Authorization([]int{1})

initBlogRouteMap(api, validateTokenHandle, authHandle)
initUserRouteMap(api, validateTokenHandle, authHandle)

r.Run(":5000")
}

func initBlogRouteMap(route *gin.RouterGroup) {
func initBlogRouteMap(route *gin.RouterGroup, validateTokenHandle, authHandle gin.HandlerFunc) {
blog := route.Group("/blog")
blog.Use(middleware.Authorization([]int{1}))

blog.POST("/", handler.CreateStory)
blog.POST("/:id", handler.UpdateStory)
blog.POST("/", handler.CreateStory, validateTokenHandle, authHandle)
blog.POST("/:id", handler.UpdateStory, validateTokenHandle, authHandle)
blog.DELETE("/:id", handler.DeleteStory, validateTokenHandle, authHandle)

blog.GET("/", handler.GetStories)

blog.DELETE("/:id", handler.DeleteStory)

}

func initUserRouteMap(route *gin.RouterGroup) {
user := route.Group("/user")
func initUserRouteMap(route *gin.RouterGroup, validateTokenHandle, authHandle gin.HandlerFunc) {
user := route.Group("/user", validateTokenHandle, authHandle)

user.GET("/", func(c *gin.Context) {
c.AbortWithStatusJSON(200, gin.H{
"status": "ok",
Expand Down

0 comments on commit 64acd17

Please sign in to comment.