Create contacts & members pages
This commit is contained in:
parent
71e39dcf62
commit
68ff9ee375
4 changed files with 168 additions and 0 deletions
34
controllers/contacts.go
Normal file
34
controllers/contacts.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Contacts(c *fiber.Ctx) error {
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var people []models.Person
|
||||
result := db.Order(
|
||||
"last_name collate nocase asc, first_name collate nocase asc",
|
||||
).Preload("Section").Find(
|
||||
&people, "is_contact = ?", true,
|
||||
)
|
||||
|
||||
if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Render("people", fiber.Map{
|
||||
"PageTitle": "Contacts",
|
||||
"MembersPage": false,
|
||||
"People": people,
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue