From 4be15c2f1244012353585135ed44367459d9df2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Bouzour=C3=A8ne?= Date: Tue, 24 Dec 2024 12:14:53 +0100 Subject: [PATCH] Extend model with sections & model --- helpers/database.go | 17 ++++++++++++++++- models/people.go | 18 ++++++++++++++++++ models/sections.go | 15 +++++++++++++++ models/users.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 models/people.go create mode 100644 models/sections.go diff --git a/helpers/database.go b/helpers/database.go index 61ad291..3e423a6 100644 --- a/helpers/database.go +++ b/helpers/database.go @@ -30,8 +30,23 @@ func connectDatabase() (*gorm.DB, error) { sqlite.Open(config.Database.Location), &gorm.Config{}, ) + if err != nil { + // TODO: Handle exception + log.Fatal(err) + } - database.AutoMigrate(&models.User{}) + err = database.AutoMigrate( + &models.User{}, + &models.ParentSection{}, + &models.Section{}, + &models.Person{}, + &models.ManageSection{}, + &models.ManageParentSection{}, + ) + if err != nil { + // TODO: Handle exception + log.Fatal(err) + } connected = true diff --git a/models/people.go b/models/people.go new file mode 100644 index 0000000..c095ba9 --- /dev/null +++ b/models/people.go @@ -0,0 +1,18 @@ +package models + +import "gorm.io/gorm" + +type Person struct { + gorm.Model + FirstName string + LastName string + Email string + Phone string + Mobile string + Address1 string + Address2 string + PostalCode string + City string + SectionID uint + Section Section +} diff --git a/models/sections.go b/models/sections.go new file mode 100644 index 0000000..9ff7be3 --- /dev/null +++ b/models/sections.go @@ -0,0 +1,15 @@ +package models + +import "gorm.io/gorm" + +type ParentSection struct { + gorm.Model + Name string +} + +type Section struct { + gorm.Model + Name string + ParentSectionID uint + ParentSection ParentSection +} diff --git a/models/users.go b/models/users.go index d233e0b..deff81b 100644 --- a/models/users.go +++ b/models/users.go @@ -16,3 +16,31 @@ type User struct { IsAdmin bool SkipWelcome bool } + +type ManageSection struct { + gorm.Model + UserID uint + User User + SectionID uint + Section Section + ShowPerson bool + CreatePerson bool + EditPerson bool + ShowArchivedPerson bool + ArchivePerson bool + UnarchivePerson bool +} + +type ManageParentSection struct { + gorm.Model + UserID uint + User User + ParentSectionID uint + ParentSection ParentSection + ShowPerson bool + CreatePerson bool + EditPerson bool + ShowArchivedPerson bool + ArchivePerson bool + UnarchivePerson bool +}