diff --git a/internal/models/models.go b/internal/models/models.go index 0dfb40821fdfda98f2cc500cd70e98f0504e5f86..419de5571257c8ffb5dffdbd9299416910ce881b 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,147 @@ 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 + candidateLists []candidateList +} + +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 + roundID uint + area area `gorm:"foreignkey:AreaRefer"` + 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")