Add initial_name field in DB
This commit is contained in:
parent
d30b4946b3
commit
467641f4f2
|
@ -22,7 +22,7 @@ func nginxGenTeam() (string, error) {
|
|||
} else {
|
||||
ret := ""
|
||||
for _, team := range teams {
|
||||
ret += fmt.Sprintf(" if ($ssl_client_s_dn ~ \"/C=FR/ST=France/O=Epita/OU=SRS/CN=%s\") { set $team %d; }\n", team.Name, team.Id)
|
||||
ret += fmt.Sprintf(" if ($ssl_client_s_dn ~ \"/C=FR/ST=France/O=Epita/OU=SRS/CN=%s\") { set $team %d; }\n", team.InitialName, team.Id)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
@ -63,10 +63,14 @@ type uploadedMember struct {
|
|||
|
||||
func listTeam(args []string, body []byte) (interface{}, error) {
|
||||
if len(args) >= 2 {
|
||||
if tid, err := strconv.Atoi(string(args[0])); err != nil {
|
||||
return nil, err
|
||||
var team *fic.Team
|
||||
if tid, err := strconv.Atoi(args[0]); err != nil {
|
||||
if t, err := fic.GetTeamByInitialName(args[0]); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
team = &t
|
||||
}
|
||||
} else {
|
||||
var team *fic.Team
|
||||
if tid == 0 {
|
||||
team = nil
|
||||
} else if t, err := fic.GetTeam(tid); err != nil {
|
||||
|
@ -75,15 +79,16 @@ func listTeam(args []string, body []byte) (interface{}, error) {
|
|||
team = &t
|
||||
}
|
||||
|
||||
if args[1] == "my.json" {
|
||||
return fic.MyJSONTeam(team, true)
|
||||
} else if args[1] == "wait.json" {
|
||||
return fic.MyJSONTeam(team, false)
|
||||
} else if args[1] == "certificate" && team != nil {
|
||||
return CertificateAPI(*team, args[2:])
|
||||
} else if args[1] == "name" {
|
||||
return team.Name, nil
|
||||
}
|
||||
}
|
||||
|
||||
if args[1] == "my.json" {
|
||||
return fic.MyJSONTeam(team, true)
|
||||
} else if args[1] == "wait.json" {
|
||||
return fic.MyJSONTeam(team, false)
|
||||
} else if args[1] == "certificate" && team != nil {
|
||||
return CertificateAPI(*team, args[2:])
|
||||
} else if team != nil && args[1] == "name" {
|
||||
return team.Name, nil
|
||||
}
|
||||
} else if len(args) == 1 {
|
||||
if args[0] == "teams.json" {
|
||||
|
|
|
@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS themes(
|
|||
if _, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS teams(
|
||||
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
initial_name VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
color INTEGER NOT NULL
|
||||
);
|
||||
|
|
|
@ -6,13 +6,14 @@ import (
|
|||
)
|
||||
|
||||
type Team struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color uint32 `json:"color"`
|
||||
Id int64 `json:"id"`
|
||||
InitialName string `json:"initialName"`
|
||||
Name string `json:"name"`
|
||||
Color uint32 `json:"color"`
|
||||
}
|
||||
|
||||
func GetTeams() ([]Team, error) {
|
||||
if rows, err := DBQuery("SELECT id_team, name, color FROM teams"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_team, initial_name, name, color FROM teams"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -20,7 +21,7 @@ func GetTeams() ([]Team, error) {
|
|||
var teams = make([]Team, 0)
|
||||
for rows.Next() {
|
||||
var t Team
|
||||
if err := rows.Scan(&t.Id, &t.Name, &t.Color); err != nil {
|
||||
if err := rows.Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teams = append(teams, t)
|
||||
|
@ -35,7 +36,16 @@ func GetTeams() ([]Team, error) {
|
|||
|
||||
func GetTeam(id int) (Team, error) {
|
||||
var t Team
|
||||
if err := DBQueryRow("SELECT id_team, name, color FROM teams WHERE id_team = ?", id).Scan(&t.Id, &t.Name, &t.Color); err != nil {
|
||||
if err := DBQueryRow("SELECT id_team, initial_name, name, color FROM teams WHERE id_team = ?", id).Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func GetTeamByInitialName(initialName string) (Team, error) {
|
||||
var t Team
|
||||
if err := DBQueryRow("SELECT id_team, initial_name, name, color FROM teams WHERE initial_name = ?", initialName).Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
|
@ -43,12 +53,12 @@ func GetTeam(id int) (Team, error) {
|
|||
}
|
||||
|
||||
func CreateTeam(name string, color uint32) (Team, error) {
|
||||
if res, err := DBExec("INSERT INTO teams (name, color) VALUES (?, ?)", name, color); err != nil {
|
||||
if res, err := DBExec("INSERT INTO teams (initial_name, name, color) VALUES (?, ?, ?)", name, name, color); err != nil {
|
||||
return Team{}, err
|
||||
} else if tid, err := res.LastInsertId(); err != nil {
|
||||
return Team{}, err
|
||||
} else {
|
||||
return Team{tid, name, color}, nil
|
||||
return Team{tid, name, name, color}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue