60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package permissionrole
|
|
|
|
import (
|
|
"online-back/internal/appresult"
|
|
"online-back/internal/handlers"
|
|
"online-back/internal/shared"
|
|
"online-back/pkg/logging"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const baseURL = "/permission-roles"
|
|
|
|
type handler struct {
|
|
logger *logging.Logger
|
|
repository Repository
|
|
}
|
|
|
|
func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler {
|
|
return &handler{logger: logger, repository: repository}
|
|
}
|
|
|
|
func (h *handler) Register(router *gin.RouterGroup) {
|
|
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
|
group.POST("", h.create)
|
|
group.DELETE("/:id", h.delete)
|
|
}
|
|
|
|
// create godoc
|
|
// @Summary Assign permission to role
|
|
// @Description Creates a permission-role assignment, or updates the existing pair if already assigned
|
|
// @Tags permission-roles
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param body body CreatePermissionRoleDTO true "Permission-role payload"
|
|
// @Success 201 {object} appresult.AppSuccess
|
|
// @Failure 400 {object} appresult.AppError
|
|
// @Failure 500 {object} appresult.AppError
|
|
// @Router /permission-roles [post]
|
|
func (h *handler) create(c *gin.Context) {
|
|
shared.CreateAssoc[CreatePermissionRoleDTO, PermissionRoleDTO](c, h.logger, h.repository, "permission role")
|
|
}
|
|
|
|
// delete godoc
|
|
// @Summary Remove permission from role
|
|
// @Description Deletes a permission-role assignment
|
|
// @Tags permission-roles
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Param id path int true "Permission-role ID"
|
|
// @Success 200 {object} appresult.AppSuccess
|
|
// @Failure 400 {object} appresult.AppError
|
|
// @Failure 404 {object} appresult.AppError
|
|
// @Failure 500 {object} appresult.AppError
|
|
// @Router /permission-roles/{id} [delete]
|
|
func (h *handler) delete(c *gin.Context) {
|
|
shared.DeleteAssoc[CreatePermissionRoleDTO, PermissionRoleDTO](c, h.logger, h.repository, "permission role")
|
|
}
|