82 lines
1.7 KiB
Go
82 lines
1.7 KiB
Go
package controllers
|
|
|
|
import (
|
|
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
|
"git.readonly.ch/bouzoure/pop-camarades/models"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func Homepage(c *fiber.Ctx) error {
|
|
userid, err := helpers.GetSessionUserId(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
allowedSectionsMembers, err := helpers.PermissionsGetSections(
|
|
userid, "show_member",
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
allowedSectionsContacts, err := helpers.PermissionsGetSections(
|
|
userid, "show_contact",
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
db, err := helpers.GetDatabase()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var membersCount int64
|
|
var contactsCount int64
|
|
|
|
db.Find(
|
|
&models.Person{},
|
|
"is_member = ? AND section_id IN ?",
|
|
true, allowedSectionsMembers,
|
|
).Count(&membersCount)
|
|
|
|
db.Find(
|
|
&models.Person{},
|
|
"is_contact = ? AND section_id IN ?",
|
|
true, allowedSectionsContacts,
|
|
).Count(&contactsCount)
|
|
|
|
return c.Render("index", fiber.Map{
|
|
"PageTitle": "Accueil",
|
|
"MembersCount": membersCount,
|
|
"ContactsCount": contactsCount,
|
|
})
|
|
}
|
|
|
|
func Admin(c *fiber.Ctx) error {
|
|
db, err := helpers.GetDatabase()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var sectionsCount int64
|
|
var listsCount int64
|
|
var fieldsCount int64
|
|
var usersCount int64
|
|
var rolesCount int64
|
|
|
|
db.Find(&models.Section{}).Count(§ionsCount)
|
|
db.Find(&models.List{}).Count(&listsCount)
|
|
db.Find(&models.Field{}).Count(&fieldsCount)
|
|
db.Find(&models.User{}).Count(&usersCount)
|
|
db.Find(&models.Role{}).Count(&rolesCount)
|
|
|
|
return c.Render("admin", fiber.Map{
|
|
"PageTitle": "Administration",
|
|
"SectionsCount": sectionsCount,
|
|
"ListsCount": listsCount,
|
|
"FieldsCount": fieldsCount,
|
|
"UsersCount": usersCount,
|
|
"RolesCount": rolesCount,
|
|
})
|
|
}
|