Ver código fonte

增加权限

xjg 4 meses atrás
pai
commit
c2a6dc319b

+ 1 - 0
READMD.md

@@ -1 +1,2 @@
 [//]: # (- docker run --name authorization-client --restart=always -d -p 8092:8092 sghharbor.com/sghblog-project/authorization-client:v1.0.0)
+lsof -i tcp:8010

+ 7 - 0
api/admin/permission/enter.go

@@ -0,0 +1,7 @@
+package permission
+
+import pb "sghgogs.com/sghblog/authorization-service/proto"
+
+type AdminPermission struct {
+	Service pb.AdminPermissionService
+}

+ 314 - 0
api/admin/permission/permission.go

@@ -0,0 +1,314 @@
+package permission
+
+import (
+	"github.com/gin-gonic/gin"
+	"net/http"
+	"sghgogs.com/sghblog/authorization-client/model/base"
+	"sghgogs.com/sghblog/authorization-client/model/response/admin"
+	"sghgogs.com/sghblog/authorization-client/response"
+	"sghgogs.com/sghblog/authorization-client/utils"
+	pb "sghgogs.com/sghblog/authorization-service/proto"
+	"sghgogs.com/sghblog/common"
+	"strconv"
+)
+
+// binding:"required"
+
+type ListResponse struct {
+	Items      []admin.AdminPermission `json:"items"`
+	TotalCount int64                   `json:"total_count"`
+}
+
+type Request struct {
+	Page     int32       `json:"page"`      // 页码, 默认1
+	PageSize int32       `json:"page_size"` // 页大小, 默认20
+	Keyword  string      `json:"keyword"`   // 关键词
+	Status   base.Status `json:"status"`    // 状态 ENABLED DISABLED DELETED
+}
+
+// GetAdminPermissionList
+// @summary 权限列表
+// @Tags Permissions
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "Bearer 用户令牌"
+// @Param page query int true "页码"
+// @Param page_size query int true "每页数量"
+// @Param keyword query string false "关键字"
+// @Param status query string false "状态" Enums(enabled, disabled)
+// @Success 200 {object} response.ApiResponse{data=ListResponse} "成功"
+// @Failure 400 {object} response.ApiResponse "请求错误"
+// @Failure 500 {object} response.ApiResponse "内部错误"
+// @Router /v1/api/admin/permissions [get]
+func (svc *AdminPermission) GetAdminPermissionList(c *gin.Context) {
+	validationConfig := response.ValidationConfig{
+		Validators: map[string]func(interface{}) error{
+			"page":      response.ValidateInt, // 验证是否为整数
+			"page_size": response.ValidateInt, // 验证是否为整数
+		},
+		Required: []string{"page", "page_size"},
+	}
+	params, err := response.ParseQueryParameters(c, validationConfig)
+	if err != nil {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error()))
+		return
+	}
+	page, _ := strconv.Atoi(params["page"].(string))
+	pageSize, _ := strconv.Atoi(params["page_size"].(string))
+	keyword, status := "", ""
+	if value, ok := params["keyword"]; ok {
+		keyword = value.(string)
+	}
+	if value, ok := params["status"]; ok {
+		status = value.(string)
+		if status != "" && !base.IsValidStatus(status) {
+			c.JSON(http.StatusBadRequest, gin.H{"error": common.ErrorMessage[common.StatusIsNotValid]})
+			return
+		}
+	}
+	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminPermissionService.GetAdminPermissionList")
+	listRequest := pb.GetAdminPermissionListRequest{
+		Page:     int32(page),
+		PageSize: int32(pageSize),
+		Keyword:  keyword,
+	}
+	if status != "" {
+		enum, _ := base.MapStatusToEnum(base.Status(status))
+		listRequest.Status = enum
+
+	}
+	list, err := svc.Service.GetAdminPermissionList(ctx, &listRequest)
+	if err != nil {
+		code, mgs := response.MicroErrorRequest(err)
+		c.JSON(code, response.ErrorResponse(code, mgs))
+		return
+	}
+	permissions := make([]admin.AdminPermission, 0)
+	for _, permission := range list.Items {
+		var item admin.AdminPermission
+		common.SwapTo(permission, &item)
+		toStatus, _ := base.MapEnumToStatus(permission.Status)
+		item.Status = string(toStatus)
+		if permission.UpdatedAt > 0 {
+			item.UpdatedAt = utils.ConvertInt64ToTime(permission.UpdatedAt)
+		}
+		item.CreatedAt = utils.ConvertInt64ToTime(permission.CreatedAt)
+		item.IsReserved = permission.IsReserved
+		item.Roles = base.RolesToResponse(permission.Roles)
+		item.Endpoint = permission.Endpoint
+		permissions = append(permissions, item)
+	}
+	c.JSON(http.StatusOK, response.SuccessResponse(ListResponse{
+		Items:      permissions,
+		TotalCount: list.TotalCount,
+	}))
+}
+
+// GetAdminPermission
+// @summary 获取权限详情
+// @Tags Permissions
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "Bearer 用户令牌"
+// @Param    id   path      int  true  "权限ID"
+// @Success 200 {object} response.ApiResponse{data=admin.AdminPermission} "成功"
+// @Failure 400 {object} response.ApiResponse "请求错误"
+// @Failure 500 {object} response.ApiResponse "内部错误"
+// @Router /v1/api/admin/permission/{permissionID} [get]
+func (svc *AdminPermission) GetAdminPermission(c *gin.Context) {
+	permissionID, err := strconv.ParseInt(c.Param("permissionID"), 10, 64)
+	if err != nil || permissionID <= 0 {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.InvalidRoleID]))
+		return
+	}
+	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminRoleService.GetAdminRole")
+	list, err := svc.Service.GetAdminPermission(ctx, &pb.GetAdminPermissionRequest{
+		Id: permissionID,
+	})
+	if err != nil {
+		code, mgs := response.MicroErrorRequest(err)
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(code, mgs))
+		return
+	}
+	permission := list.Data
+	status, _ := base.MapEnumToStatus(permission.Status)
+	c.JSON(http.StatusOK, response.SuccessResponse(admin.AdminPermission{
+		ID:          permission.Id,
+		Name:        permission.Name,
+		Description: permission.Description,
+		Roles:       base.RolesToResponse(permission.Roles),
+		CreatedAt:   utils.ConvertInt64ToTime(permission.CreatedAt),
+		UpdatedAt:   utils.ConvertInt64ToTime(permission.UpdatedAt),
+		Status:      string(status),
+		IsReserved:  permission.IsReserved,
+	}))
+}
+
+type CreateRequest struct {
+	Name        string  `json:"name" binding:"required,max=50,min=3"` // 权限名称
+	Description string  `json:"description"`                          // 非必填,描述
+	Endpoint    string  `json:"endpoint" binding:"required"`
+	Roles       []int64 `json:"roles"` // 角色
+}
+
+// CreateAdminPermission
+// @summary 新增权限
+// @Tags Permissions
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "Bearer 用户令牌"
+// @Param body body CreateRequest true "请求body"
+// @Success 200 {object} response.ApiResponse "成功"
+// @Failure 400 {object} response.ApiResponse "请求错误"
+// @Failure 500 {object} response.ApiResponse "内部错误"
+// @Router /v1/api/admin/permission [post]
+func (svc *AdminPermission) CreateAdminPermission(c *gin.Context) {
+	var req CreateRequest
+	if err := c.BindJSON(&req); err != nil {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error()))
+		return
+	}
+	if len(req.Roles) > 0 {
+		if isBool, err := common.ValidateNumericInt64(req.Roles); !isBool {
+			c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error()))
+			return
+		}
+	}
+	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminPermissionService.CreateAdminPermission")
+	_, err := svc.Service.CreateAdminPermission(ctx, &pb.CreateAdminPermissionRequest{
+		Name:        req.Name,
+		Description: req.Description,
+		Endpoint:    req.Endpoint,
+		Roles:       req.Roles,
+		Status:      pb.StatusEnum_ENABLED,
+	})
+	if err != nil {
+		code, mgs := response.MicroErrorRequest(err)
+		c.JSON(code, response.ErrorResponse(code, mgs))
+		return
+	}
+	c.JSON(http.StatusOK, response.SuccessResponse(nil))
+}
+
+type UpdateRequest struct {
+	Description string  `json:"description"` // 非必填,描述
+	Roles       []int64 `json:"roles"`       // 角色
+}
+
+// UpdateAdminPermission
+// @summary 更新权限
+// @Tags Permissions
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "Bearer 用户令牌"
+// @Param    id   path      int  true  "权限ID"
+// @Param body body UpdateRequest true "请求body"
+// @Success 200 {object} response.ApiResponse "成功"
+// @Failure 400 {object} response.ApiResponse "请求错误"
+// @Failure 500 {object} response.ApiResponse "内部错误"
+// @Router /v1/api/admin/permission/{permissionID} [put]
+func (svc *AdminPermission) UpdateAdminPermission(c *gin.Context) {
+	var req UpdateRequest
+	if err := c.BindJSON(&req); err != nil {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error()))
+		return
+	}
+	permissionID, err := strconv.ParseInt(c.Param("permissionID"), 10, 64)
+	if err != nil || permissionID <= 0 {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.InvalidRoleID]))
+		return
+	}
+	if len(req.Roles) > 0 {
+		if isBool, err := common.ValidateNumericInt64(req.Roles); !isBool {
+			c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error()))
+			return
+		}
+	}
+
+	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminRoleService.UpdateAdminRole")
+
+	_, err = svc.Service.UpdateAdminPermission(ctx, &pb.UpdateAdminPermissionRequest{
+		PermissionId: permissionID,
+		Description:  req.Description,
+		Roles:        req.Roles,
+	})
+	if err != nil {
+		code, mgs := response.MicroErrorRequest(err)
+		c.JSON(code, response.ErrorResponse(code, mgs))
+		return
+	}
+	c.JSON(http.StatusOK, response.SuccessResponse(nil))
+}
+
+// DeleteAdminPermission
+// @summary 删除权限
+// @Tags Permissions
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "Bearer 用户令牌"
+// @Param    id   path      int  true  "权限ID"
+// @Success 200 {object} response.ApiResponse "成功"
+// @Failure 400 {object} response.ApiResponse "请求错误"
+// @Failure 500 {object} response.ApiResponse "内部错误"
+// @Router /v1/api/admin/permission/{permissionID} [delete]
+func (svc *AdminPermission) DeleteAdminPermission(c *gin.Context) {
+	permissionID, err := strconv.ParseInt(c.Param("permissionID"), 10, 64)
+	if err != nil || permissionID <= 0 {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.InvalidRoleID]))
+		return
+	}
+	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminRoleService.DeleteAdminRole")
+	_, err = svc.Service.DeleteAdminPermission(ctx, &pb.DeleteAdminPermissionRequest{
+		PermissionId: permissionID,
+	})
+	if err != nil {
+		code, mgs := response.MicroErrorRequest(err)
+		c.JSON(code, response.ErrorResponse(code, mgs))
+		return
+	}
+	c.JSON(http.StatusOK, response.SuccessResponse(nil))
+}
+
+type ToggleRequest struct {
+	Status base.Status `json:"status" binding:"required"` // "enabled"|"disabled"
+}
+
+// ToggleAdminPermission
+// @summary 启用/禁用
+// @Tags Permissions
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "Bearer 用户令牌"
+// @Param body body ToggleRequest true "请求body"
+// @Success 200 {object} response.ApiResponse "成功"
+// @Failure 400 {object} response.ApiResponse "请求错误"
+// @Failure 500 {object} response.ApiResponse "内部错误"
+// @Router /v1/api/admin/permission/{permissionID}/toggle [put]
+func (svc *AdminPermission) ToggleAdminPermission(c *gin.Context) {
+	var req ToggleRequest
+	if err := c.ShouldBindJSON(&req); err != nil {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error()))
+		return
+	}
+	permissionID, err := strconv.ParseInt(c.Param("permissionID"), 10, 64)
+	if err != nil || permissionID <= 0 {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.InvalidRoleID]))
+		return
+	}
+	enum, err := base.MapStatusToEnum(req.Status)
+	if err != nil {
+		c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.StatusIsNotValid]))
+		return
+	}
+	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminPermissionService.ToggleAdminPermission")
+	_, err = svc.Service.ToggleAdminPermission(ctx, &pb.ToggleAdminPermissionRequest{
+		PermissionId: permissionID,
+		Status:       enum,
+	})
+	if err != nil {
+		code, mgs := response.MicroErrorRequest(err)
+		c.JSON(code, response.ErrorResponse(code, mgs))
+		return
+	}
+	c.JSON(http.StatusOK, response.SuccessResponse(nil))
+}

+ 3 - 1
api/admin_common/logout.go

@@ -1,6 +1,7 @@
 package admin_common
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"net/http"
 	"sghgogs.com/sghblog/authorization-client/response"
@@ -21,6 +22,7 @@ import (
 // @Router /v1/api/admin/profile [post]
 func (svc *ApiAdminCommon) Logout(c *gin.Context) {
 	ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "CommonService.AdminLogout")
-	svc.Service.AdminLogout(ctx, &pb.AdminLogoutRequest{})
+	logout, err := svc.Service.AdminLogout(ctx, &pb.AdminLogoutRequest{})
+	fmt.Println(logout, err)
 	c.JSON(http.StatusOK, response.SuccessResponse(nil))
 }

+ 487 - 0
docs/docs.go

@@ -82,6 +82,362 @@ const docTemplate = `{
                 }
             }
         },
+        "/v1/api/admin/permission": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "新增权限",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "description": "请求body",
+                        "name": "body",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/permission.CreateRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/api/admin/permission/{permissionID}": {
+            "get": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "获取权限详情",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "权限ID",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/response.ApiResponse"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/admin.AdminPermission"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            },
+            "put": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "更新权限",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "权限ID",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "description": "请求body",
+                        "name": "body",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/permission.UpdateRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            },
+            "delete": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "删除权限",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "权限ID",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/api/admin/permission/{permissionID}/toggle": {
+            "put": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "启用/禁用",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "description": "请求body",
+                        "name": "body",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/permission.ToggleRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/api/admin/permissions": {
+            "get": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "权限列表",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页数量",
+                        "name": "page_size",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "关键字",
+                        "name": "keyword",
+                        "in": "query"
+                    },
+                    {
+                        "enum": [
+                            "enabled",
+                            "disabled"
+                        ],
+                        "type": "string",
+                        "description": "状态",
+                        "name": "status",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/response.ApiResponse"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/permission.ListResponse"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
         "/v1/api/admin/profile": {
             "get": {
                 "description": "查询个人信息",
@@ -1020,6 +1376,48 @@ const docTemplate = `{
         }
     },
     "definitions": {
+        "admin.AdminPermission": {
+            "type": "object",
+            "properties": {
+                "created_at": {
+                    "type": "string"
+                },
+                "created_by": {
+                    "type": "string"
+                },
+                "description": {
+                    "type": "string"
+                },
+                "endpoint": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "is_reserved": {
+                    "type": "boolean"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "roles": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/base.ListMapItem"
+                    }
+                },
+                "status": {
+                    "description": "可以是 \"enabled\", \"disabled\", \"deleted\" 等",
+                    "type": "string"
+                },
+                "updated_at": {
+                    "type": "string"
+                },
+                "updated_by": {
+                    "type": "string"
+                }
+            }
+        },
         "admin.RoleItem": {
             "type": "object",
             "properties": {
@@ -1163,6 +1561,20 @@ const docTemplate = `{
                     "type": "string",
                     "maxLength": 15,
                     "minLength": 3
+                },
+                "permissions": {
+                    "description": "权限",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "users": {
+                    "description": "管理员",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
                 }
             }
         },
@@ -1556,6 +1968,81 @@ const docTemplate = `{
                 }
             }
         },
+        "permission.CreateRequest": {
+            "type": "object",
+            "required": [
+                "endpoint",
+                "name"
+            ],
+            "properties": {
+                "description": {
+                    "description": "非必填,描述",
+                    "type": "string"
+                },
+                "endpoint": {
+                    "type": "string"
+                },
+                "name": {
+                    "description": "权限名称",
+                    "type": "string",
+                    "maxLength": 50,
+                    "minLength": 3
+                },
+                "roles": {
+                    "description": "角色",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                }
+            }
+        },
+        "permission.ListResponse": {
+            "type": "object",
+            "properties": {
+                "items": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/admin.AdminPermission"
+                    }
+                },
+                "total_count": {
+                    "type": "integer"
+                }
+            }
+        },
+        "permission.ToggleRequest": {
+            "type": "object",
+            "required": [
+                "status"
+            ],
+            "properties": {
+                "status": {
+                    "description": "\"enabled\"|\"disabled\"",
+                    "allOf": [
+                        {
+                            "$ref": "#/definitions/base.Status"
+                        }
+                    ]
+                }
+            }
+        },
+        "permission.UpdateRequest": {
+            "type": "object",
+            "properties": {
+                "description": {
+                    "description": "非必填,描述",
+                    "type": "string"
+                },
+                "roles": {
+                    "description": "角色",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                }
+            }
+        },
         "response.ApiResponse": {
             "type": "object",
             "properties": {

+ 487 - 0
docs/swagger.json

@@ -76,6 +76,362 @@
                 }
             }
         },
+        "/v1/api/admin/permission": {
+            "post": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "新增权限",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "description": "请求body",
+                        "name": "body",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/permission.CreateRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/api/admin/permission/{permissionID}": {
+            "get": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "获取权限详情",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "权限ID",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/response.ApiResponse"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/admin.AdminPermission"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            },
+            "put": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "更新权限",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "权限ID",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "description": "请求body",
+                        "name": "body",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/permission.UpdateRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            },
+            "delete": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "删除权限",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "权限ID",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/api/admin/permission/{permissionID}/toggle": {
+            "put": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "启用/禁用",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "description": "请求body",
+                        "name": "body",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/permission.ToggleRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
+        "/v1/api/admin/permissions": {
+            "get": {
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Permissions"
+                ],
+                "summary": "权限列表",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "Bearer 用户令牌",
+                        "name": "Authorization",
+                        "in": "header",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页数量",
+                        "name": "page_size",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "string",
+                        "description": "关键字",
+                        "name": "keyword",
+                        "in": "query"
+                    },
+                    {
+                        "enum": [
+                            "enabled",
+                            "disabled"
+                        ],
+                        "type": "string",
+                        "description": "状态",
+                        "name": "status",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/response.ApiResponse"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/permission.ListResponse"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    },
+                    "400": {
+                        "description": "请求错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    },
+                    "500": {
+                        "description": "内部错误",
+                        "schema": {
+                            "$ref": "#/definitions/response.ApiResponse"
+                        }
+                    }
+                }
+            }
+        },
         "/v1/api/admin/profile": {
             "get": {
                 "description": "查询个人信息",
@@ -1014,6 +1370,48 @@
         }
     },
     "definitions": {
+        "admin.AdminPermission": {
+            "type": "object",
+            "properties": {
+                "created_at": {
+                    "type": "string"
+                },
+                "created_by": {
+                    "type": "string"
+                },
+                "description": {
+                    "type": "string"
+                },
+                "endpoint": {
+                    "type": "string"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "is_reserved": {
+                    "type": "boolean"
+                },
+                "name": {
+                    "type": "string"
+                },
+                "roles": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/base.ListMapItem"
+                    }
+                },
+                "status": {
+                    "description": "可以是 \"enabled\", \"disabled\", \"deleted\" 等",
+                    "type": "string"
+                },
+                "updated_at": {
+                    "type": "string"
+                },
+                "updated_by": {
+                    "type": "string"
+                }
+            }
+        },
         "admin.RoleItem": {
             "type": "object",
             "properties": {
@@ -1157,6 +1555,20 @@
                     "type": "string",
                     "maxLength": 15,
                     "minLength": 3
+                },
+                "permissions": {
+                    "description": "权限",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "users": {
+                    "description": "管理员",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
                 }
             }
         },
@@ -1550,6 +1962,81 @@
                 }
             }
         },
+        "permission.CreateRequest": {
+            "type": "object",
+            "required": [
+                "endpoint",
+                "name"
+            ],
+            "properties": {
+                "description": {
+                    "description": "非必填,描述",
+                    "type": "string"
+                },
+                "endpoint": {
+                    "type": "string"
+                },
+                "name": {
+                    "description": "权限名称",
+                    "type": "string",
+                    "maxLength": 50,
+                    "minLength": 3
+                },
+                "roles": {
+                    "description": "角色",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                }
+            }
+        },
+        "permission.ListResponse": {
+            "type": "object",
+            "properties": {
+                "items": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/admin.AdminPermission"
+                    }
+                },
+                "total_count": {
+                    "type": "integer"
+                }
+            }
+        },
+        "permission.ToggleRequest": {
+            "type": "object",
+            "required": [
+                "status"
+            ],
+            "properties": {
+                "status": {
+                    "description": "\"enabled\"|\"disabled\"",
+                    "allOf": [
+                        {
+                            "$ref": "#/definitions/base.Status"
+                        }
+                    ]
+                }
+            }
+        },
+        "permission.UpdateRequest": {
+            "type": "object",
+            "properties": {
+                "description": {
+                    "description": "非必填,描述",
+                    "type": "string"
+                },
+                "roles": {
+                    "description": "角色",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                }
+            }
+        },
         "response.ApiResponse": {
             "type": "object",
             "properties": {

+ 318 - 0
docs/swagger.yaml

@@ -1,5 +1,33 @@
 basePath: /v1/api
 definitions:
+  admin.AdminPermission:
+    properties:
+      created_at:
+        type: string
+      created_by:
+        type: string
+      description:
+        type: string
+      endpoint:
+        type: string
+      id:
+        type: integer
+      is_reserved:
+        type: boolean
+      name:
+        type: string
+      roles:
+        items:
+          $ref: '#/definitions/base.ListMapItem'
+        type: array
+      status:
+        description: 可以是 "enabled", "disabled", "deleted" 等
+        type: string
+      updated_at:
+        type: string
+      updated_by:
+        type: string
+    type: object
   admin.RoleItem:
     properties:
       created_at:
@@ -101,6 +129,16 @@ definitions:
         maxLength: 15
         minLength: 3
         type: string
+      permissions:
+        description: 权限
+        items:
+          type: integer
+        type: array
+      users:
+        description: 管理员
+        items:
+          type: integer
+        type: array
     required:
     - name
     type: object
@@ -364,6 +402,56 @@ definitions:
       username:
         type: string
     type: object
+  permission.CreateRequest:
+    properties:
+      description:
+        description: 非必填,描述
+        type: string
+      endpoint:
+        type: string
+      name:
+        description: 权限名称
+        maxLength: 50
+        minLength: 3
+        type: string
+      roles:
+        description: 角色
+        items:
+          type: integer
+        type: array
+    required:
+    - endpoint
+    - name
+    type: object
+  permission.ListResponse:
+    properties:
+      items:
+        items:
+          $ref: '#/definitions/admin.AdminPermission'
+        type: array
+      total_count:
+        type: integer
+    type: object
+  permission.ToggleRequest:
+    properties:
+      status:
+        allOf:
+        - $ref: '#/definitions/base.Status'
+        description: '"enabled"|"disabled"'
+    required:
+    - status
+    type: object
+  permission.UpdateRequest:
+    properties:
+      description:
+        description: 非必填,描述
+        type: string
+      roles:
+        description: 角色
+        items:
+          type: integer
+        type: array
+    type: object
   response.ApiResponse:
     properties:
       code:
@@ -424,6 +512,236 @@ paths:
       summary: 登录
       tags:
       - Common
+  /v1/api/admin/permission:
+    post:
+      consumes:
+      - application/json
+      parameters:
+      - description: Bearer 用户令牌
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      - description: 请求body
+        in: body
+        name: body
+        required: true
+        schema:
+          $ref: '#/definitions/permission.CreateRequest'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "400":
+          description: 请求错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "500":
+          description: 内部错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+      summary: 新增权限
+      tags:
+      - Permissions
+  /v1/api/admin/permission/{permissionID}:
+    delete:
+      consumes:
+      - application/json
+      parameters:
+      - description: Bearer 用户令牌
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      - description: 权限ID
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "400":
+          description: 请求错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "500":
+          description: 内部错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+      summary: 删除权限
+      tags:
+      - Permissions
+    get:
+      consumes:
+      - application/json
+      parameters:
+      - description: Bearer 用户令牌
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      - description: 权限ID
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            allOf:
+            - $ref: '#/definitions/response.ApiResponse'
+            - properties:
+                data:
+                  $ref: '#/definitions/admin.AdminPermission'
+              type: object
+        "400":
+          description: 请求错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "500":
+          description: 内部错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+      summary: 获取权限详情
+      tags:
+      - Permissions
+    put:
+      consumes:
+      - application/json
+      parameters:
+      - description: Bearer 用户令牌
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      - description: 权限ID
+        in: path
+        name: id
+        required: true
+        type: integer
+      - description: 请求body
+        in: body
+        name: body
+        required: true
+        schema:
+          $ref: '#/definitions/permission.UpdateRequest'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "400":
+          description: 请求错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "500":
+          description: 内部错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+      summary: 更新权限
+      tags:
+      - Permissions
+  /v1/api/admin/permission/{permissionID}/toggle:
+    put:
+      consumes:
+      - application/json
+      parameters:
+      - description: Bearer 用户令牌
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      - description: 请求body
+        in: body
+        name: body
+        required: true
+        schema:
+          $ref: '#/definitions/permission.ToggleRequest'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "400":
+          description: 请求错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "500":
+          description: 内部错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+      summary: 启用/禁用
+      tags:
+      - Permissions
+  /v1/api/admin/permissions:
+    get:
+      consumes:
+      - application/json
+      parameters:
+      - description: Bearer 用户令牌
+        in: header
+        name: Authorization
+        required: true
+        type: string
+      - description: 页码
+        in: query
+        name: page
+        required: true
+        type: integer
+      - description: 每页数量
+        in: query
+        name: page_size
+        required: true
+        type: integer
+      - description: 关键字
+        in: query
+        name: keyword
+        type: string
+      - description: 状态
+        enum:
+        - enabled
+        - disabled
+        in: query
+        name: status
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            allOf:
+            - $ref: '#/definitions/response.ApiResponse'
+            - properties:
+                data:
+                  $ref: '#/definitions/permission.ListResponse'
+              type: object
+        "400":
+          description: 请求错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+        "500":
+          description: 内部错误
+          schema:
+            $ref: '#/definitions/response.ApiResponse'
+      summary: 权限列表
+      tags:
+      - Permissions
   /v1/api/admin/profile:
     get:
       consumes:

+ 4 - 2
go.mod

@@ -23,10 +23,12 @@ require (
 	go.opentelemetry.io/otel/trace v1.21.0
 	golang.org/x/net v0.17.0
 	google.golang.org/protobuf v1.31.0
-	sghgogs.com/sghblog/authorization-service v0.0.0-20231219071555-2d739b878799
-	sghgogs.com/sghblog/common v0.0.0-20231219070006-58d7e2000e0a
+	sghgogs.com/sghblog/authorization-service v0.0.0-00010101000000-000000000000
+	sghgogs.com/sghblog/common v1.0.1
 )
 
+replace sghgogs.com/sghblog/authorization-service => ../AuthorizationService
+
 require (
 	github.com/KyleBanks/depth v1.2.1 // indirect
 	github.com/Microsoft/go-winio v0.6.0 // indirect

+ 2 - 2
go.sum

@@ -972,7 +972,7 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
 rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
 rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
 rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-sghgogs.com/sghblog/authorization-service v0.0.0-20231219071555-2d739b878799 h1:DeOXD6shZA+LIhZZ2pFw0LyBUyAIpVPisvbkHVZhukg=
-sghgogs.com/sghblog/authorization-service v0.0.0-20231219071555-2d739b878799/go.mod h1:7iGPIlilHSF0tQdxNWSlax/R6gQEnycXjVsWnOI3Vgs=
 sghgogs.com/sghblog/common v0.0.0-20231219070006-58d7e2000e0a h1:QfEb62RyInH+XxxJBmGTYx4c0gFlrsrX3ybjihrIcR8=
 sghgogs.com/sghblog/common v0.0.0-20231219070006-58d7e2000e0a/go.mod h1:DcFGf3a/9IznsK3wIp2M2WbzwKWu9aBqQ96jD8NOTmY=
+sghgogs.com/sghblog/common v1.0.1 h1:i2V3NBL7zh7bbKHlUhqmXZeHAD94ErnzNaDRCqJ3JL0=
+sghgogs.com/sghblog/common v1.0.1/go.mod h1:DcFGf3a/9IznsK3wIp2M2WbzwKWu9aBqQ96jD8NOTmY=

+ 3 - 2
install.sh

@@ -1,5 +1,5 @@
 # 测试环境
-# export ADDRESS=":8888"
+ export ADDRESS=":8010"
 export TRACING_ENABLE=true
 export TRACING_JAEGER_URL=http://localhost:14268/api/traces
 
@@ -12,4 +12,5 @@ export REDIS_URL=localhost:6379
 
 go run main.go
 
-# lsof -i:8080
+# lsof -i:8080
+

+ 20 - 0
model/response/admin/permission.go

@@ -0,0 +1,20 @@
+package admin
+
+import (
+	"sghgogs.com/sghblog/authorization-client/model/base"
+	"time"
+)
+
+type AdminPermission struct {
+	ID          int64              `json:"id"`
+	Name        string             `json:"name"`
+	Endpoint    string             `json:"endpoint"`
+	Description string             `json:"description"`
+	Roles       []base.ListMapItem `json:"roles"`
+	CreatedAt   time.Time          `json:"created_at"`
+	CreatedBy   string             `json:"created_by"`
+	UpdatedAt   time.Time          `json:"updated_at"`
+	UpdatedBy   string             `json:"updated_by"`
+	Status      string             `json:"status"` // 可以是 "enabled", "disabled", "deleted" 等
+	IsReserved  bool               `json:"is_reserved"`
+}

+ 2 - 2
response/response.go

@@ -70,7 +70,7 @@ func ParseQueryParameters(c *gin.Context, config ValidationConfig) (map[string]i
 	for key, validator := range config.Validators {
 		if paramValue, ok := params[key]; ok {
 			if err := validator(paramValue); err != nil {
-				return nil, errors.New(common.ErrorMessage[common.ParametersAreMissingErrorCode] + "[" + key + "]: " + err.Error())
+				return nil, errors.New(common.ErrorMessage[common.MissingParameter] + "[" + key + "]: " + err.Error())
 			}
 		}
 	}
@@ -79,7 +79,7 @@ func ParseQueryParameters(c *gin.Context, config ValidationConfig) (map[string]i
 	for _, key := range config.Required {
 		if _, ok := params[key]; !ok {
 			fmt.Println(key)
-			return nil, errors.New(common.ErrorMessage[common.ParametersAreMissingErrorCode] + "[" + key + "]")
+			return nil, errors.New(common.ErrorMessage[common.MissingParameter] + "[" + key + "]")
 		}
 	}
 

+ 3 - 1
router/router.go

@@ -3,6 +3,7 @@ package router
 import (
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
+	"sghgogs.com/sghblog/authorization-client/router/v1/admin/permission"
 	"sghgogs.com/sghblog/authorization-client/router/v1/admin_role"
 	"sghgogs.com/sghblog/authorization-client/router/v1/admin_user"
 
@@ -53,7 +54,8 @@ func NewRouter(namespace string, client client.Client) *gin.Engine {
 	adminCommonRouter := admin_common.NewAdminCommonRouter(namespace, client)
 	adminRoleRouter := admin_role.NewAdminRoleRouter(namespace, client)
 	adminUserRouter := admin_user.NewAdminUserRouter(namespace, client)
-	baseservice.RegisterRouters(r, adminCommonRouter, adminRoleRouter, adminUserRouter)
+	permissionRouter := permission.NewAdminPermissionRouter(namespace, client)
+	baseservice.RegisterRouters(r, adminCommonRouter, adminRoleRouter, adminUserRouter, permissionRouter)
 	r.GET("/_healthz", func(c *gin.Context) {
 		c.String(http.StatusOK, "ok")
 	})

+ 42 - 0
router/v1/admin/permission/permission.go

@@ -0,0 +1,42 @@
+package permission
+
+import (
+	"github.com/gin-gonic/gin"
+	"go-micro.dev/v4/client"
+	"sghgogs.com/sghblog/authorization-client/api/admin/permission"
+	"sghgogs.com/sghblog/authorization-client/utils"
+	"sghgogs.com/sghblog/authorization-client/utils/baseservice"
+	pb "sghgogs.com/sghblog/authorization-service/proto"
+)
+
+type AdminPermission struct {
+	*baseservice.BaseService
+}
+
+func NewAdminPermissionRouter(namespace string, client client.Client) *AdminPermission {
+	return &AdminPermission{
+		BaseService: &baseservice.BaseService{
+			Namespace: namespace,
+			Client:    client,
+		},
+	}
+}
+
+func (svc *AdminPermission) RegisterRoutes(r *gin.Engine) {
+	api := permission.AdminPermission{}
+	commonService := pb.NewAdminPermissionService(svc.Namespace, svc.Client)
+	api.Service = commonService
+	svc.registerAdminPermissionRoutes(r, "/v1/api", &api)
+}
+
+func (svc *AdminPermission) registerAdminPermissionRoutes(r *gin.Engine, path string, api *permission.AdminPermission) {
+	v1 := r.Group(path)
+	{
+		v1.GET("/admin/permissions", utils.TokenAuthMiddleware(), api.GetAdminPermissionList)
+		v1.GET("/admin/permission/:permissionID", utils.TokenAuthMiddleware(), api.GetAdminPermission)
+		v1.POST("/admin/permission", utils.TokenAuthMiddleware(), api.CreateAdminPermission)
+		v1.PUT("/admin/permission/:permissionID", utils.TokenAuthMiddleware(), api.UpdateAdminPermission)
+		v1.DELETE("/admin/permission/:permissionID", utils.TokenAuthMiddleware(), api.DeleteAdminPermission)
+		v1.PUT("/admin/permission/:permissionID/toggle", utils.TokenAuthMiddleware(), api.ToggleAdminPermission)
+	}
+}