Backend: extract file generation and team renaming in dedicated files
This commit is contained in:
parent
aefd078ebf
commit
1c62f61bf0
8 changed files with 261 additions and 140 deletions
|
@ -1,6 +1,8 @@
|
|||
package fic
|
||||
|
||||
import ()
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Theme struct {
|
||||
Id int64 `json:"id"`
|
||||
|
@ -68,3 +70,46 @@ func (t Theme) Delete() (int64, error) {
|
|||
return nb, err
|
||||
}
|
||||
}
|
||||
|
||||
type ExportedExercice struct {
|
||||
Title string `json:"title"`
|
||||
Gain int64 `json:"gain"`
|
||||
Solved int64 `json:"solved"`
|
||||
Tried int64 `json:"tried"`
|
||||
}
|
||||
|
||||
type exportedTheme struct {
|
||||
Name string `json:"name"`
|
||||
Authors string `json:"authors"`
|
||||
Exercices map[string]ExportedExercice `json:"exercices"`
|
||||
}
|
||||
|
||||
func ExportThemes() (interface{}, error) {
|
||||
if themes, err := GetThemes(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
ret := map[string]exportedTheme{}
|
||||
for _, theme := range themes {
|
||||
if exercices, err := theme.GetExercices(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
exos := map[string]ExportedExercice{}
|
||||
for _, exercice := range exercices {
|
||||
exos[fmt.Sprintf("%d", exercice.Id)] = ExportedExercice{
|
||||
exercice.Title,
|
||||
exercice.Gain,
|
||||
exercice.SolvedCount(),
|
||||
exercice.TriedTeamCount(),
|
||||
}
|
||||
}
|
||||
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
||||
theme.Name,
|
||||
theme.Authors[:len(theme.Authors)-1],
|
||||
exos,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue