Simplified join with a global code

This commit is contained in:
Manuel Forcén Muñoz 2025-02-12 20:12:30 +01:00
parent bc6b57bc54
commit efd337b6ce
4 changed files with 93 additions and 77 deletions

View file

@ -9,15 +9,13 @@ type User struct {
}
type Member struct {
ID uint `gorm:"primaryKey;autoIncrement:true" json:"-"`
PlanID uint `json:"-"`
Plan Plan `json:"-"`
Type string `gorm:"check:type in ('user','non-user')" json:"type"`
Name string `gorm:"check:type=='member' OR name IS NOT NULL" json:"name"`
Status string `gorm:"check:status in ('pending','ready')" json:"status"`
JoinCode string `gorm:"uniqueIndex;check:type=='non-member' OR join_code IS NOT NULL" json:"join_code,omitempty"`
UserID string `json:"username"`
User User `gorm:"foreignKey:UserID" json:"-"`
ID uint `gorm:"primaryKey;autoIncrement:true" json:"-"`
PlanID uint `json:"-"`
Plan Plan `json:"-"`
Type string `gorm:"check:type in ('user','non-user')" json:"type"`
Name string `gorm:"check:type=='member' OR name IS NOT NULL" json:"name"`
UserID string `json:"username"`
User User `gorm:"foreignKey:UserID" json:"-"`
}
// CREATE TABLE plans(id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING, owner STRING, FOREIGN KEY(owner) REFERENCES users(username))
@ -27,6 +25,7 @@ type Plan struct {
Name string `json:"name"`
Owner string `json:"owner"`
Description string `json:"description"`
JoinCode string `gorm:"not null" json:"join_code,omitempty"`
Members []Member `json:"-"`
Polls []Poll `gorm:"foreignKey:PlanID;references:ID" json:"-"`
}