Add API for keys and files
This commit is contained in:
parent
381aefa597
commit
8655997246
3 changed files with 153 additions and 53 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
|
@ -15,41 +16,55 @@ var ApiTeamsRouting = map[string]DispatchFunction{
|
|||
"DELETE": deletionTeam,
|
||||
}
|
||||
|
||||
type uploadedTeam struct {
|
||||
Name string
|
||||
type myTeamFile struct {
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Checksum []byte `json:"checksum"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
type uploadedMember struct {
|
||||
Firstname string
|
||||
Lastname string
|
||||
Nickname string
|
||||
Company string
|
||||
type myTeamExercice struct {
|
||||
Statement string `json:"statement"`
|
||||
Hint string `json:"hint"`
|
||||
Gain int64 `json:"gain"`
|
||||
Files []myTeamFile `json:"files"`
|
||||
Solved bool `json:"solved"`
|
||||
SolvedTime time.Time `json:"solved_time"`
|
||||
SolvedNumber int64 `json:"solved_number"`
|
||||
}
|
||||
type myTeam struct {
|
||||
Id int64 `json:"team_id"`
|
||||
Exercices map[string]myTeamExercice `json:"exercices"`
|
||||
}
|
||||
|
||||
func myJSONTeam(t fic.Team) (interface{}, error) {
|
||||
ret := map[string]interface{}{}
|
||||
|
||||
ret["team_id"] = t.Id
|
||||
|
||||
exercices := map[string]interface{}{}
|
||||
ret := myTeam{}
|
||||
ret.Id = t.Id
|
||||
ret.Exercices = map[string]myTeamExercice{}
|
||||
|
||||
if exos, err := fic.GetExercices(); err != nil {
|
||||
return ret, err
|
||||
} else {
|
||||
for _, e := range exos {
|
||||
if t.HasAccess(e) {
|
||||
exercice := map[string]interface{}{}
|
||||
exercice["statement"] = e.Statement
|
||||
exercice["hint"] = e.Hint
|
||||
exercice["solved"] = t.HasSolved(e)
|
||||
exercice := myTeamExercice{}
|
||||
exercice.Statement = e.Statement
|
||||
exercice.Hint = e.Hint
|
||||
exercice.Solved, exercice.SolvedTime, exercice.SolvedNumber = t.HasSolved(e)
|
||||
exercice.Files = []myTeamFile{}
|
||||
|
||||
exercices[fmt.Sprintf("%d", e.Id)] = exercice
|
||||
if files, err := e.GetFiles(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, f := range files {
|
||||
exercice.Files = append(exercice.Files, myTeamFile{f.Path, f.Name, f.Checksum, f.Size})
|
||||
}
|
||||
}
|
||||
|
||||
ret.Exercices[fmt.Sprintf("%d", e.Id)] = exercice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret["exercices"] = exercices
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +81,17 @@ func nginxGenTeam() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
type uploadedTeam struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type uploadedMember struct {
|
||||
Firstname string
|
||||
Lastname string
|
||||
Nickname string
|
||||
Company string
|
||||
}
|
||||
|
||||
func listTeam(args []string, body []byte) (interface{}, error) {
|
||||
if len(args) == 2 {
|
||||
if tid, err := strconv.Atoi(string(args[0])); err != nil {
|
||||
|
|
|
|||
Reference in a new issue