fix minor bugs in role api
This commit is contained in:
19
api.go
19
api.go
@@ -181,7 +181,7 @@ func (aH *AccessHandlerAPI) AddRole(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Check if a role with this name already exists
|
||||
if err := aH.dbHandler.Exists(&models.Role{}, "role", role, false); err == nil {
|
||||
if err := aH.dbHandler.Exists(&models.Role{}, "role", role.Role, false); err == nil {
|
||||
aH.logger.Error("AddRole", fmt.Sprintf("role with name %s already exists", role.Role))
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonMessageResponse(fmt.Sprintf("role with name %s already exists", role.Role)))
|
||||
}
|
||||
@@ -199,25 +199,30 @@ func (aH *AccessHandlerAPI) AddRole(c *gin.Context) {
|
||||
func (aH *AccessHandlerAPI) GetRole(c *gin.Context) {
|
||||
var i int
|
||||
var err error
|
||||
var roles []models.Role
|
||||
|
||||
role := c.Query("role")
|
||||
id := c.Query("id")
|
||||
if id != "" {
|
||||
|
||||
if role != "" {
|
||||
err = aH.dbHandler.GetByKey(&roles, "role", role, false)
|
||||
} else if id != "" {
|
||||
i, err = strconv.Atoi(id)
|
||||
if err != nil {
|
||||
aH.logger.Error("GetRole", err)
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
err = aH.dbHandler.GetById(&roles, uint(i))
|
||||
}
|
||||
|
||||
var role []models.Role
|
||||
err = aH.dbHandler.GetById(&role, uint(i))
|
||||
if err != nil {
|
||||
aH.logger.Error("GetRole", err)
|
||||
c.JSON(http.StatusInternalServerError, nil)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, role)
|
||||
c.JSON(http.StatusOK, roles)
|
||||
}
|
||||
|
||||
func (aH *AccessHandlerAPI) UpdateRole(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user