From 93941b778c40915a65670f29752ffb005a1041ce Mon Sep 17 00:00:00 2001 From: Alexis Poyen <apoyen@mail.apoyen.fr> Date: Wed, 6 May 2020 12:16:07 +0200 Subject: [PATCH] Feat : add models for elections --- internal/models/models.go | 139 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/internal/models/models.go b/internal/models/models.go index 0dfb408..146f905 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -3,6 +3,7 @@ package models import ( "net/http" "strings" + "time" "github.com/jinzhu/gorm" @@ -30,6 +31,144 @@ const ErrorRoleOfLoggedUser = "Could not get role of logged user" // ErrorNotAuthorizeMethodOnRessource = "You're not authorize to execute this method on this ressource." const ErrorNotAuthorizeMethodOnRessource = "You're not authorize to execute this method on this ressource." +type election struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + name string + ballotType string + areas []area + Rounds []Round +} + +type area struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + electionID uint + name string + seatNumber uint + mapID string + sections []section +} + +type section struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + areaID uint + name string + seatNumber uint + mapID string + desks []desk +} + +type desk struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + sectionID uint + name string + subscribed uint + witnessDesk bool +} + +type party struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + name string + color string + candidateList []candidateList +} + +type capturer struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + userID int `gorm:"not null;unique"` + name string + deskRounds []deskRound +} + +type parameter struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + roundID round + countBalnkAndNull bool + showOnlyCompleted bool + showMap bool +} + +type round struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + ElectionID uint + parameter parameter + name string + date time.Time + tour uint + deskRounds []deskRound +} + +type deskRound struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + RoundID uint + completed bool + dateCompletion time.Time + validated bool + Votes []Vote +} +type candidateList struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + PartyID uint + name string + candidates []candidate + Votes []Vote +} + +type candidate struct { + ID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + candidateListID uint + fullName string + rank uint + communityCounseller bool + birthdate time.Time + potentialIncompatibility bool + refused bool + removed bool +} + +type vote struct { + deskRoundID uint `gorm:"primary_key"` + candidateListID uint `gorm:"primary_key"` + CreatedAt time.Time `json:"-"` + UpdatedAt time.Time `json:"-"` + DeletedAt *time.Time `json:"-"` + voiceNumber uint + blank bool + null bool +} + // NewDataHandler init a DataHandler and returns a pointer to it func NewDataHandler() *DataHandler { db, err := gorm.Open("sqlite3", "./data/test.db") -- GitLab