API package refactor
This commit is contained in:
parent
a7cd86962e
commit
bc6b57bc54
14 changed files with 474 additions and 416 deletions
47
core/models.go
Normal file
47
core/models.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package core
|
||||
|
||||
type User struct {
|
||||
Username string `gorm:"primaryKey" json:"username"`
|
||||
Password string `json:"password"`
|
||||
OwnedPlans []Plan `gorm:"foreignKey:Owner;references:Username" json:"-"`
|
||||
MemberOf []Member `json:"-"`
|
||||
Votes []Vote `gorm:"foreignKey:UsernameID" json:"-"`
|
||||
}
|
||||
|
||||
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:"-"`
|
||||
}
|
||||
|
||||
// CREATE TABLE plans(id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING, owner STRING, FOREIGN KEY(owner) REFERENCES users(username))
|
||||
// CREATE TABLE plan_user_relations(username STRING, plan INTEGER, PRIMARY KEY(username, plan), FOREIGN KEY username REFERENCES user(username), FOREIGN KEY plan REFERENCES plans(id))
|
||||
type Plan struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
Name string `json:"name"`
|
||||
Owner string `json:"owner"`
|
||||
Description string `json:"description"`
|
||||
Members []Member `json:"-"`
|
||||
Polls []Poll `gorm:"foreignKey:PlanID;references:ID" json:"-"`
|
||||
}
|
||||
|
||||
// CREATE TABLE polls(id INTEGER PRIMARY KEY AUTOINCREMENT, plan INTEGER, name STRING, options JSON, FOREIGN KEY plan REFERENCES plans(id))
|
||||
type Poll struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
PlanID uint `json:"-"`
|
||||
Options string `json:"options"`
|
||||
Votes []Vote `gorm:"foreignKey:PollID;references:ID" json:"-"`
|
||||
}
|
||||
|
||||
// CREATE TABLE votes(id INTEGER, poll INTEGER, user STRING, value JSON, FOREIGN KEY poll REFERENCES polls(id), FOREIGN KEY user REFERENCES user(username))
|
||||
type Vote struct {
|
||||
PollID uint `gorm:"primaryKey" json:"-"`
|
||||
UsernameID string `gorm:"primaryKey" json:"username_id"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue