implemented team create method
This commit is contained in:
@ -2,16 +2,19 @@ package models
|
||||
|
||||
// Team holds a team object
|
||||
type Team struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
Name string `xorm:"varchar(250) not null" json:"name"`
|
||||
Description string `xorm:"varchar(250)" json:"description"`
|
||||
Rights []int64 `xorm:"varchar(250)" json:"rights"`
|
||||
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
Name string `xorm:"varchar(250) not null" json:"name"`
|
||||
Description string `xorm:"varchar(250)" json:"description"`
|
||||
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
|
||||
|
||||
CreatedBy *User `xorm:"-" json:"created_by"`
|
||||
Members []*User `xorm:"-" json:"members"`
|
||||
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
Updated int64 `xorm:"updated" json:"updated"`
|
||||
|
||||
CreatedBy User `json:"created_by"`
|
||||
CRUDable `xorm:"-" json:"-"`
|
||||
Rights `xorm:"-" json:"-"`
|
||||
}
|
||||
|
||||
// TableName makes beautiful table names
|
||||
@ -19,14 +22,19 @@ func (Team) TableName() string {
|
||||
return "teams"
|
||||
}
|
||||
|
||||
func (t *Team) AfterLoad() {
|
||||
// Get the owner
|
||||
*t.CreatedBy, _, _ = GetUserByID(t.CreatedByID)
|
||||
}
|
||||
|
||||
// TeamMember defines the relationship between a user and a team
|
||||
type TeamMember struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
||||
TeamID int64 `xorm:"int(11) autoincr not null"`
|
||||
UserID int64 `xorm:"int(11) autoincr not null"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
TeamID int64 `xorm:"int(11) not null" json:"team_id"`
|
||||
UserID int64 `xorm:"int(11) not null" json:"user_id"`
|
||||
|
||||
Created int64 `xorm:"created"`
|
||||
Updated int64 `xorm:"updated"`
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
Updated int64 `xorm:"updated" json:"updated"`
|
||||
}
|
||||
|
||||
// TableName makes beautiful table names
|
||||
@ -36,12 +44,13 @@ func (TeamMember) TableName() string {
|
||||
|
||||
// TeamNamespace defines the relationship between a Team and a Namespace
|
||||
type TeamNamespace struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
||||
TeamID int64 `xorm:"int(11) autoincr not null"`
|
||||
NamespaceID int64 `xorm:"int(11) autoincr not null"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
TeamID int64 `xorm:"int(11) not null" json:"team_id"`
|
||||
NamespaceID int64 `xorm:"int(11) not null" json:"namespace_id"`
|
||||
Rights []int64 `xorm:"varchar(250)" json:"rights"`
|
||||
|
||||
Created int64 `xorm:"created"`
|
||||
Updated int64 `xorm:"updated"`
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
Updated int64 `xorm:"updated" json:"updated"`
|
||||
}
|
||||
|
||||
// TableName makes beautiful table names
|
||||
@ -51,12 +60,13 @@ func (TeamNamespace) TableName() string {
|
||||
|
||||
// TeamList defines the relation between a team and a list
|
||||
type TeamList struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
||||
TeamID int64 `xorm:"int(11) autoincr not null"`
|
||||
ListID int64 `xorm:"int(11) autoincr not null"`
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
|
||||
TeamID int64 `xorm:"int(11) not null" json:"team_id"`
|
||||
ListID int64 `xorm:"int(11) not null" json:"list_id"`
|
||||
Rights []int64 `xorm:"varchar(250)" json:"rights"`
|
||||
|
||||
Created int64 `xorm:"created"`
|
||||
Updated int64 `xorm:"updated"`
|
||||
Created int64 `xorm:"created" json:"created"`
|
||||
Updated int64 `xorm:"updated" json:"updated"`
|
||||
}
|
||||
|
||||
// TableName makes beautiful table names
|
||||
@ -73,3 +83,15 @@ func GetAllTeamsByNamespaceID(id int64) (teams []*Team, err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Empty empties a struct. Because we heavily use pointers, the old values remain in the struct.
|
||||
// If you then update by not providing evrything, you have i.e. the old description still in the
|
||||
// newly created team, but you didn't provided one.
|
||||
func (t *Team) Empty() {
|
||||
t.ID = 0
|
||||
t.CreatedByID = 0
|
||||
t.CreatedBy = &User{}
|
||||
t.Name = ""
|
||||
t.Description = ""
|
||||
t.Members = []*User{}
|
||||
}
|
Reference in New Issue
Block a user