From 68ff9ee3755c5cab6cf80ccf381c600dcc9ed68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Bouzour=C3=A8ne?= Date: Wed, 8 Jan 2025 16:09:19 +0100 Subject: [PATCH] Create contacts & members pages --- controllers/contacts.go | 34 +++++++++++++++ controllers/members.go | 34 +++++++++++++++ main.go | 6 +++ views/people.html | 94 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 controllers/contacts.go create mode 100644 controllers/members.go create mode 100644 views/people.html diff --git a/controllers/contacts.go b/controllers/contacts.go new file mode 100644 index 0000000..f920b8f --- /dev/null +++ b/controllers/contacts.go @@ -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, + }) +} diff --git a/controllers/members.go b/controllers/members.go new file mode 100644 index 0000000..001275d --- /dev/null +++ b/controllers/members.go @@ -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 Members(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_member = ?", true, + ) + + if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) { + return err + } + + return c.Render("people", fiber.Map{ + "PageTitle": "Membres", + "MembersPage": true, + "People": people, + }) +} diff --git a/main.go b/main.go index 5072c6e..2f70245 100644 --- a/main.go +++ b/main.go @@ -116,6 +116,12 @@ func main() { app.Get("/totp/verify", controllers.TotpVerifyPage) app.Post("/totp/verify", controllers.TotpVerifyPage) + // Members + app.Get("/members", controllers.Members) + + // Contacts + app.Get("/contacts", controllers.Contacts) + // Account manage app.Get("/account/manage", controllers.AccountManage) app.Post("/account/manage", controllers.AccountManage) diff --git a/views/people.html b/views/people.html new file mode 100644 index 0000000..6709732 --- /dev/null +++ b/views/people.html @@ -0,0 +1,94 @@ +{% extends "layouts/main.html" %} + +{% block main %} +
+
+ +
+
+ + {% if People %} +
+ + + + + + + + + + + {% for Person in People %} + + + + + + + {% endfor %} + +
NomPrénomLieuSection
+ {% if Person.IsMember %} + + {{ Person.LastName }} + + {% else %} + + {{ Person.LastName }} + + {% endif %} + + {% if Person.IsMember %} + + {{ Person.FirstName }} + + {% else %} + + {{ Person.FirstName }} + + {% endif %} + + {{ Person.PostalCode }} {{ Person.City }} + + {% if Person.SectionID %} + {{ Section.Section.Name }} + {% endif %} +
+
+ {% else %} +
+ {% if MembersPage %} + Pas de membre pour le moment + {% else %} + Pas de contact pour le moment + {% endif %} +
+ {% endif %} + +
+ {% if MembersPage %} + + + Ajouter + + {% else %} + + + Ajouter + + {% endif %} +
+
+{% endblock %}