Skip to content

Commit

Permalink
docs: rbac swagger comment
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Aug 31, 2021
1 parent 2946fd2 commit 4464dae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
11 changes: 5 additions & 6 deletions manager/handlers/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import (

// @Summary Get Permissions
// @Description Get Permissions
// @Tags permission
// @Tags Permission
// @Produce json
// @Success 200 {object} RoutesInfo
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Success 200 {object} []rbac.Permission
// @Failure 400
// @Failure 500
// @Router /permissions [get]
func (h *Handlers) GetPermissions(g *gin.Engine) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
permissions := h.Service.GetPermissions(g)
ctx.JSON(http.StatusOK, permissions)
ctx.JSON(http.StatusOK, h.Service.GetPermissions(g))
}
}
40 changes: 21 additions & 19 deletions manager/handlers/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (

// @Summary Create Role
// @Description Create Role by json config
// @Tags role
// @Tags Role
// @Accept json
// @Produce json
// @Param Role body types.CreateRoleRequest true "Role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /roles [post]
func (h *Handlers) CreateRole(ctx *gin.Context) {
var json types.CreateRoleRequest
Expand All @@ -49,14 +50,14 @@ func (h *Handlers) CreateRole(ctx *gin.Context) {

// @Summary Destroy Role
// @Description Destroy role by json config
// @Tags permission
// @Tags Role
// @Accept json
// @Produce json
// @Param role path string true "role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Router /role/:role [delete]
// @Failure 400
// @Failure 500
// @Router /roles/:role [delete]
func (h *Handlers) DestroyRole(ctx *gin.Context) {
var params types.RoleParams
if err := ctx.ShouldBindUri(&params); err != nil {
Expand All @@ -77,12 +78,13 @@ func (h *Handlers) DestroyRole(ctx *gin.Context) {

// @Summary Get Role
// @Description Get Role
// @Tags permission
// @Tags Role
// @Accept json
// @Produce json
// @Param role path string true "role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /roles/:role [get]
func (h *Handlers) GetRole(ctx *gin.Context) {
var params types.RoleParams
Expand All @@ -96,12 +98,12 @@ func (h *Handlers) GetRole(ctx *gin.Context) {

// @Summary Get Roles
// @Description Get roles
// @Tags role
// @Tags Role
// @Accept json
// @Produce json
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /roles [get]
func (h *Handlers) GetRoles(ctx *gin.Context) {
roles := h.Service.GetRoles()
Expand All @@ -110,14 +112,14 @@ func (h *Handlers) GetRoles(ctx *gin.Context) {

// @Summary Add Permission For Role
// @Description Add Permission by json config
// @Tags role
// @Tags Role
// @Accept json
// @Produce json
// @Param Permission body types.AddPermissionForRoleRequest true "Permission"
// @Param role path string true "role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /roles/:role/permissions [post]
func (h *Handlers) AddPermissionForRole(ctx *gin.Context) {
var params types.RoleParams
Expand Down Expand Up @@ -145,14 +147,14 @@ func (h *Handlers) AddPermissionForRole(ctx *gin.Context) {

// @Summary Update Role
// @Description Remove Role Permission by json config
// @Tags role
// @Tags Role
// @Accept json
// @Produce json
// @Param Permission body types.DeletePermissionForRoleRequest true "Permission"
// @Param role path string true "role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /roles/:role/permissions [delete]
func (h *Handlers) DeletePermissionForRole(ctx *gin.Context) {
var params types.RoleParams
Expand Down
20 changes: 10 additions & 10 deletions manager/handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (h *Handlers) ResetPassword(ctx *gin.Context) {
// @Produce json
// @Param id path string true "id"
// @Success 200 {object} []string
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /users/:id/roles [get]
func (h *Handlers) GetRolesForUser(ctx *gin.Context) {
var params types.UserParams
Expand All @@ -107,14 +107,14 @@ func (h *Handlers) GetRolesForUser(ctx *gin.Context) {

// @Summary Add Role For User
// @Description add role to user by uri config
// @Tags users
// @Accept text
// @Tags Users
// @Accept json
// @Produce json
// @Param id path string true "id"
// @Param role path string true "role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /users/:id/roles/:role [put]
func (h *Handlers) AddRoleToUser(ctx *gin.Context) {
var params types.AddRoleForUserParams
Expand All @@ -136,14 +136,14 @@ func (h *Handlers) AddRoleToUser(ctx *gin.Context) {

// @Summary Delete Role For User
// @Description delete role by uri config
// @Tags users
// @Accept text
// @Tags Users
// @Accept json
// @Produce json
// @Param id path string true "id"
// @Param role path string true "role"
// @Success 200
// @Failure 400 {object} HTTPError
// @Failure 500 {object} HTTPError
// @Failure 400
// @Failure 500
// @Router /users/:id/roles/:role [delete]
func (h *Handlers) DeleteRoleForUser(ctx *gin.Context) {
var params types.DeleteRoleForUserParams
Expand Down
4 changes: 2 additions & 2 deletions manager/types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type SignUpRequest struct {

type DeleteRoleForUserParams struct {
ID uint `uri:"id" binding:"required"`
Role string `uri:"role" binding:"required,min=1"`
Role string `uri:"role" binding:"required"`
}

type AddRoleForUserParams struct {
ID uint `uri:"id" binding:"required"`
Role string `uri:"role" binding:"required,min=1"`
Role string `uri:"role" binding:"required"`
}

0 comments on commit 4464dae

Please sign in to comment.