Skip to content

Commit

Permalink
Merge pull request #41 from fy23-gw-gackathon/fix/#40_auth_error_resp…
Browse files Browse the repository at this point in the history
…onse

ref #40 fix auth response
  • Loading branch information
gari8 committed May 17, 2023
2 parents 685cbfa + a87bf4e commit 425b851
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions infrastructure/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Authentication(
} else {
uid, err := repo.GetUserIDFromToken(context.Background(), token)
if err != nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, err.Error())
c.JSON(http.StatusUnauthorized, entity.ErrorResponse{Message: err.Error()})
return
}
userID = *uid
Expand All @@ -40,7 +40,7 @@ func Authentication(
var err error
user, err = repo.GetOrganizationUser(c, code, userID)
if err != nil {
c.AbortWithStatusJSON(http.StatusForbidden, err.Error())
c.JSON(http.StatusUnauthorized, entity.ErrorResponse{Message: err.Error()})
return
}
} else {
Expand Down
25 changes: 11 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,19 @@ func main() {
api := app.Group("/api/v1")
api.GET("/users/me", handleResponse(userController.GetMe))
api.PUT("/reports/:reportId", handleResponse(reportController.ReviewReport, http.StatusNoContent))
orgs := api.Group("/organizations")
orgs.Use(middleware.Authentication(userPersistence, cfg))
{
orgs.GET("/", handleResponse(organizationController.GetOrganizations))
orgs.GET("/:organizationCode", handleResponse(organizationController.GetOrganization))
orgs.PUT("/:organizationCode", handleResponse(organizationController.UpdateOrganization))
api.Use(middleware.Authentication(userPersistence, cfg))
api.GET("/organizations", handleResponse(organizationController.GetOrganizations))
api.GET("/organizations/:organizationCode", handleResponse(organizationController.GetOrganization))
api.PUT("/organizations/:organizationCode", handleResponse(organizationController.UpdateOrganization))

orgs.GET("/:organizationCode/reports", handleResponse(reportController.GetReports))
orgs.POST("/:organizationCode/reports", handleResponse(reportController.CreateReport, http.StatusCreated))
orgs.GET("/:organizationCode/reports/:reportId", handleResponse(reportController.GetReport))
api.GET("/organizations/:organizationCode/reports", handleResponse(reportController.GetReports))
api.POST("/organizations/:organizationCode/reports", handleResponse(reportController.CreateReport, http.StatusCreated))
api.GET("/organizations/:organizationCode/reports/:reportId", handleResponse(reportController.GetReport))

orgs.GET("/:organizationCode/users", handleResponse(userController.GetUsers))
orgs.POST("/:organizationCode/users", handleResponse(userController.InviteUser))
orgs.PUT("/:organizationCode/users/:userId", handleResponse(userController.UpdateUserRole))
orgs.DELETE("/:organizationCode/users/:userId", handleResponse(userController.DeleteUser))
}
api.GET("/organizations/:organizationCode/users", handleResponse(userController.GetUsers))
api.POST("/organizations/:organizationCode/users", handleResponse(userController.InviteUser))
api.PUT("/organizations/:organizationCode/users/:userId", handleResponse(userController.UpdateUserRole))
api.DELETE("/organizations/:organizationCode/users/:userId", handleResponse(userController.DeleteUser))

runApp(app, cfg.App.Port)
}
Expand Down

0 comments on commit 425b851

Please sign in to comment.