Добавлен основные классы для сервиса авторизаци
This commit is contained in:
36
internal/handler/users.go
Normal file
36
internal/handler/users.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ChangeUserRoleRequest struct {
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
func (h *Handler) changeUserRole(c *gin.Context) {
|
||||
var input ChangeUserRoleRequest
|
||||
|
||||
if err := c.BindJSON(&input); err != nil {
|
||||
newErrorResponse(c, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
username := c.Param("username")
|
||||
if username == "" {
|
||||
newErrorResponse(c, http.StatusBadRequest, "Ошибка в строке запроса")
|
||||
return
|
||||
}
|
||||
role, err := h.services.ChangeUserRole(username, input.Role)
|
||||
|
||||
if err != nil {
|
||||
newErrorResponse(c, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, map[string]interface{}{
|
||||
"newRole": role,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user