Fix 404 & clean code
This commit is contained in:
parent
1dc135f8f9
commit
1d390cf7ff
9 changed files with 192 additions and 184 deletions
|
|
@ -41,14 +41,14 @@ func SectionShow(c *fiber.Ctx) error {
|
|||
var section models.Section
|
||||
result := db.Preload("ParentSection").Find(§ion, "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 | Sections",
|
||||
section.Name,
|
||||
|
|
@ -131,12 +131,12 @@ func SectionAdd(c *fiber.Ctx) error {
|
|||
result := db.Create(§ion)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/sections/%d",
|
||||
section.ID,
|
||||
))
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/sections/%d",
|
||||
section.ID,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,14 +159,14 @@ func SectionEdit(c *fiber.Ctx) error {
|
|||
var section models.Section
|
||||
result := db.Find(§ion, "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")
|
||||
}
|
||||
|
||||
var childSections []models.Section
|
||||
db.Find(&childSections, "parent_section_id = ?", section.ID)
|
||||
isParent := (len(childSections) > 0)
|
||||
|
|
@ -225,12 +225,12 @@ func SectionEdit(c *fiber.Ctx) error {
|
|||
result := db.Save(§ion)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
} else {
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/sections/%d",
|
||||
section.ID,
|
||||
))
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/admin/sections/%d",
|
||||
section.ID,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue