Fix 404 & clean code
This commit is contained in:
parent
1dc135f8f9
commit
1d390cf7ff
9 changed files with 192 additions and 184 deletions
|
|
@ -43,14 +43,14 @@ func FieldShow(c *fiber.Ctx) error {
|
|||
var field models.Field
|
||||
result := db.Preload("List").Find(&field, "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 | Champs supplémentaires",
|
||||
field.Name,
|
||||
|
|
@ -115,12 +115,12 @@ func FieldAdd(c *fiber.Ctx) error {
|
|||
result := db.Create(&field)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/fields/%d",
|
||||
field.ID,
|
||||
))
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/fields/%d",
|
||||
field.ID,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,14 +145,14 @@ func FieldEdit(c *fiber.Ctx) error {
|
|||
var field models.Field
|
||||
result := db.Find(&field, "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 un champ",
|
||||
field.Name,
|
||||
|
|
@ -169,12 +169,12 @@ func FieldEdit(c *fiber.Ctx) error {
|
|||
result := db.Save(&field)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/fields/%d",
|
||||
field.ID,
|
||||
))
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/fields/%d",
|
||||
field.ID,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue