Migrate to PostgreSQL and fix related issues

This commit is contained in:
William Bouzourène 2025-05-12 21:10:40 +02:00
parent 0b8fbea6c3
commit a89a9776c3
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww
17 changed files with 176 additions and 174 deletions

View file

@ -18,7 +18,7 @@ func Sections(c *fiber.Ctx) error {
}
var sections []models.Section
result := db.Order("name collate nocase asc").Preload("ParentSection").Find(&sections)
result := db.Order("name asc").Preload("ParentSection").Find(&sections)
if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
return err
@ -70,8 +70,8 @@ func SectionAdd(c *fiber.Ctx) error {
}
var sections []models.Section
db.Order("name collate nocase asc").Find(
&sections, "id <> ? AND parent_section_id = 0", section.ID,
db.Order("name asc").Find(
&sections, "id <> ? AND parent_section_id IS NULL", section.ID,
)
if c.Method() == "POST" {
@ -106,12 +106,12 @@ func SectionAdd(c *fiber.Ctx) error {
section.Name = name
section.ShortName = shortName
section.ParentSectionID = 0
parentSectionID, err := strconv.ParseUint(parentSection, 10, 0)
if err == nil {
for _, parentSection := range sections {
if parentSection.ID == uint(parentSectionID) {
section.ParentSectionID = uint(parentSectionID)
parentSectionID2 := uint(parentSectionID)
if parentSection.ID == parentSectionID2 {
section.ParentSectionID = &parentSectionID2
break
}
}
@ -177,8 +177,8 @@ func SectionEdit(c *fiber.Ctx) error {
)
var sections []models.Section
db.Order("name collate nocase asc").Find(
&sections, "id <> ? AND parent_section_id = 0", section.ID,
db.Order("name asc").Find(
&sections, "id <> ? AND parent_section_id IS NULL", section.ID,
)
var errors []string
@ -200,12 +200,12 @@ func SectionEdit(c *fiber.Ctx) error {
section.Name = name
section.ShortName = shortName
section.ParentSectionID = 0
parentSectionID, err := strconv.ParseUint(parentSection, 10, 0)
if err == nil {
for _, parentSection := range sections {
if parentSection.ID == uint(parentSectionID) {
section.ParentSectionID = uint(parentSectionID)
parentSectionID2 := uint(parentSectionID)
if parentSection.ID == parentSectionID2 {
section.ParentSectionID = &parentSectionID2
break
}
}