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

@ -69,7 +69,7 @@ func Contacts(c *fiber.Ctx) error {
params.PersonType = "contacts"
var sections []models.Section
db.Order("name collate nocase asc").Find(&sections, "contains_contacts = ? AND id IN ?", true, allowedSections)
db.Order("name asc").Find(&sections, "contains_contacts = ? AND id IN ?", true, allowedSections)
params.AllowedSections = allowedSections
// Security for active contacts
@ -156,7 +156,7 @@ func ContactsExport(c *fiber.Ctx) error {
params.PersonType = "contacts"
var sections []models.Section
db.Order("name collate nocase asc").Find(&sections, "contains_members = ? AND id IN ?", true, allowedSections)
db.Order("name asc").Find(&sections, "contains_members = ? AND id IN ?", true, allowedSections)
params.AllowedSections = allowedSections
// Security for active contacts
@ -280,7 +280,7 @@ func ContactsExport(c *fiber.Ctx) error {
} else if field.FieldType == "list" {
if field.List.Multi {
if field.List != nil && field.List.Multi {
if countMulti == 0 {
c.Writef("\"")
@ -323,7 +323,7 @@ func ContactShow(c *fiber.Ctx) error {
var person models.Person
result := db.Unscoped().Preload("Section").Find(
&person, "id = ? AND is_contact", id, true,
&person, "id = ? AND is_contact = ?", id, true,
)
if result.Error != nil {
@ -416,7 +416,7 @@ func ContactAdd(c *fiber.Ctx) error {
}
var sections []models.Section
db.Order("name collate nocase asc").Find(
db.Order("name asc").Find(
&sections,
"contains_contacts = ?",
true,
@ -511,7 +511,7 @@ func ContactAdd(c *fiber.Ctx) error {
}
for _, field := range fields {
if field.List.Multi {
if field.List != nil && field.List.Multi {
for _, listItem := range field.List.ListItems {
key := fmt.Sprintf("field-%d-%d", field.ID, listItem.ID)
value := c.FormValue(key)
@ -520,7 +520,7 @@ func ContactAdd(c *fiber.Ctx) error {
var fieldValue models.FieldValue
fieldValue.FieldID = field.ID
fieldValue.PersonID = person.ID
fieldValue.ListItemID = listItem.ID
fieldValue.ListItemID = &listItem.ID
db.Create(&fieldValue)
}
}
@ -594,7 +594,8 @@ func ContactAdd(c *fiber.Ctx) error {
var fieldValue models.FieldValue
fieldValue.FieldID = field.ID
fieldValue.PersonID = person.ID
fieldValue.ListItemID = uint(valueInt)
valueUint := uint(valueInt)
fieldValue.ListItemID = &valueUint
db.Create(&fieldValue)
}
}
@ -659,7 +660,7 @@ func ContactEdit(c *fiber.Ctx) error {
}
var sections []models.Section
db.Order("name collate nocase asc").Find(
db.Order("name asc").Find(
&sections,
"contains_contacts = ?",
true,
@ -760,7 +761,7 @@ func ContactEdit(c *fiber.Ctx) error {
field.ID,
)
if field.List.Multi {
if field.List != nil && field.List.Multi {
for _, listItem := range field.List.ListItems {
key := fmt.Sprintf("field-%d-%d", field.ID, listItem.ID)
value := c.FormValue(key)
@ -769,7 +770,7 @@ func ContactEdit(c *fiber.Ctx) error {
var fieldValue models.FieldValue
fieldValue.FieldID = field.ID
fieldValue.PersonID = person.ID
fieldValue.ListItemID = listItem.ID
fieldValue.ListItemID = &listItem.ID
db.Create(&fieldValue)
}
}
@ -843,7 +844,8 @@ func ContactEdit(c *fiber.Ctx) error {
var fieldValue models.FieldValue
fieldValue.FieldID = field.ID
fieldValue.PersonID = person.ID
fieldValue.ListItemID = uint(valueInt)
valueUint := uint(valueInt)
fieldValue.ListItemID = &valueUint
db.Create(&fieldValue)
}
}