Fix 404 & clean code
This commit is contained in:
parent
1dc135f8f9
commit
1d390cf7ff
9 changed files with 192 additions and 184 deletions
|
|
@ -40,14 +40,14 @@ func RoleShow(c *fiber.Ctx) error {
|
|||
var role models.Role
|
||||
result := db.Find(&role, "id = ?", id)
|
||||
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Not found")
|
||||
}
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if result.RowsAffected < 1 {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Not found")
|
||||
}
|
||||
|
||||
title := fmt.Sprintf(
|
||||
"%s | Rôles",
|
||||
role.Name,
|
||||
|
|
@ -100,12 +100,12 @@ func RoleAdd(c *fiber.Ctx) error {
|
|||
result := db.Create(&role)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/roles/%d",
|
||||
role.ID,
|
||||
))
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/roles/%d",
|
||||
role.ID,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,14 +127,14 @@ func RoleEdit(c *fiber.Ctx) error {
|
|||
var role models.Role
|
||||
result := db.Find(&role, "id = ?", id)
|
||||
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Not found")
|
||||
}
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if result.RowsAffected < 1 {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Not found")
|
||||
}
|
||||
|
||||
title := fmt.Sprintf(
|
||||
"%s | Modifier rôle",
|
||||
role.Name,
|
||||
|
|
@ -173,12 +173,12 @@ func RoleEdit(c *fiber.Ctx) error {
|
|||
result := db.Save(&role)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/roles/%d",
|
||||
role.ID,
|
||||
))
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/roles/%d",
|
||||
role.ID,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue