Use pointer receiver more offen
This commit is contained in:
parent
6999b4e728
commit
c7569b5e54
59 changed files with 688 additions and 672 deletions
|
@ -67,7 +67,7 @@ func init() {
|
|||
}))
|
||||
|
||||
router.GET("/api/teams/:tid/certificates", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
if serials, err := pki.GetTeamSerials(TeamsDir, team.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
@ -84,18 +84,18 @@ func init() {
|
|||
})))
|
||||
|
||||
router.GET("/api/teams/:tid/associations", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return pki.GetTeamAssociations(TeamsDir, team.Id)
|
||||
})))
|
||||
router.POST("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||
func(team fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
if err := os.Symlink(fmt.Sprintf("%d", team.Id), path.Join(TeamsDir, assoc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return "\"" + assoc + "\"", nil
|
||||
})))
|
||||
router.DELETE("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||
func(team fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
if err := os.Remove(path.Join(TeamsDir, assoc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -110,11 +110,11 @@ func init() {
|
|||
router.GET("/api/certs/:certid", apiHandler(certificateHandler(getTeamP12File)))
|
||||
router.PUT("/api/certs/:certid", apiHandler(certificateHandler(updateCertificateAssociation)))
|
||||
router.DELETE("/api/certs/:certid", apiHandler(certificateHandler(
|
||||
func(cert fic.Certificate, _ []byte) (interface{}, error) { return cert.Revoke() })))
|
||||
func(cert *fic.Certificate, _ []byte) (interface{}, error) { return cert.Revoke() })))
|
||||
}
|
||||
|
||||
func genHtpasswd(ssha bool) (ret string, err error) {
|
||||
var teams []fic.Team
|
||||
var teams []*fic.Team
|
||||
teams, err = fic.GetTeams()
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -133,7 +133,7 @@ func genHtpasswd(ssha bool) (ret string, err error) {
|
|||
}
|
||||
|
||||
for _, serial := range serials {
|
||||
var cert fic.Certificate
|
||||
var cert *fic.Certificate
|
||||
cert, err = fic.GetCertificate(serial)
|
||||
if err != nil {
|
||||
// Ignore invalid/incorrect/non-existant certificates
|
||||
|
@ -219,7 +219,7 @@ func getCAPEM(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func getTeamP12File(cert fic.Certificate, _ []byte) (interface{}, error) {
|
||||
func getTeamP12File(cert *fic.Certificate, _ []byte) (interface{}, error) {
|
||||
// Create p12 if necessary
|
||||
if _, err := os.Stat(pki.ClientP12Path(cert.Id)); os.IsNotExist(err) {
|
||||
if err := pki.WriteP12(cert.Id, cert.Password); err != nil {
|
||||
|
@ -308,7 +308,7 @@ type CertUploaded struct {
|
|||
Team *int64 `json:"id_team"`
|
||||
}
|
||||
|
||||
func updateCertificateAssociation(cert fic.Certificate, body []byte) (interface{}, error) {
|
||||
func updateCertificateAssociation(cert *fic.Certificate, body []byte) (interface{}, error) {
|
||||
var uc CertUploaded
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
func init() {
|
||||
router.GET("/api/teams/:tid/issue.json", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.MyIssueFile()
|
||||
})))
|
||||
|
||||
|
@ -48,35 +48,35 @@ func getClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.GetClaims()
|
||||
}
|
||||
|
||||
func getTeamClaims(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func getTeamClaims(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.GetClaims()
|
||||
}
|
||||
|
||||
func getExerciceClaims(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func getExerciceClaims(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return exercice.GetClaims()
|
||||
}
|
||||
|
||||
func getClaimLastUpdate(claim fic.Claim, _ []byte) (interface{}, error) {
|
||||
func getClaimLastUpdate(claim *fic.Claim, _ []byte) (interface{}, error) {
|
||||
return claim.GetLastUpdate()
|
||||
}
|
||||
|
||||
type ClaimExported struct {
|
||||
Id int64 `json:"id"`
|
||||
Subject string `json:"subject"`
|
||||
IdTeam *int64 `json:"id_team"`
|
||||
Team *fic.Team `json:"team"`
|
||||
IdExercice *int64 `json:"id_exercice"`
|
||||
Exercice *fic.Exercice `json:"exercice"`
|
||||
IdAssignee *int64 `json:"id_assignee"`
|
||||
Assignee *fic.ClaimAssignee `json:"assignee"`
|
||||
Creation time.Time `json:"creation"`
|
||||
LastUpdate time.Time `json:"last_update"`
|
||||
State string `json:"state"`
|
||||
Priority string `json:"priority"`
|
||||
Descriptions []fic.ClaimDescription `json:"descriptions"`
|
||||
Id int64 `json:"id"`
|
||||
Subject string `json:"subject"`
|
||||
IdTeam *int64 `json:"id_team"`
|
||||
Team *fic.Team `json:"team"`
|
||||
IdExercice *int64 `json:"id_exercice"`
|
||||
Exercice *fic.Exercice `json:"exercice"`
|
||||
IdAssignee *int64 `json:"id_assignee"`
|
||||
Assignee *fic.ClaimAssignee `json:"assignee"`
|
||||
Creation time.Time `json:"creation"`
|
||||
LastUpdate time.Time `json:"last_update"`
|
||||
State string `json:"state"`
|
||||
Priority string `json:"priority"`
|
||||
Descriptions []*fic.ClaimDescription `json:"descriptions"`
|
||||
}
|
||||
|
||||
func showClaim(claim fic.Claim, _ []byte) (interface{}, error) {
|
||||
func showClaim(claim *fic.Claim, _ []byte) (interface{}, error) {
|
||||
var e ClaimExported
|
||||
var err error
|
||||
if e.Team, err = claim.GetTeam(); err != nil {
|
||||
|
@ -130,7 +130,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
if team, err := fic.GetTeam(*uc.IdTeam); err != nil {
|
||||
return nil, fmt.Errorf("Unable to get associated team: %w", err)
|
||||
} else {
|
||||
t = &team
|
||||
t = team
|
||||
}
|
||||
} else {
|
||||
t = nil
|
||||
|
@ -141,7 +141,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
if exercice, err := fic.GetExercice(*uc.IdExercice); err != nil {
|
||||
return nil, fmt.Errorf("Unable to get associated exercice: %w", err)
|
||||
} else {
|
||||
e = &exercice
|
||||
e = exercice
|
||||
}
|
||||
} else {
|
||||
e = nil
|
||||
|
@ -152,7 +152,7 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
if assignee, err := fic.GetAssignee(*uc.IdAssignee); err != nil {
|
||||
return nil, fmt.Errorf("Unable to get associated assignee: %w", err)
|
||||
} else {
|
||||
a = &assignee
|
||||
a = assignee
|
||||
}
|
||||
} else {
|
||||
a = nil
|
||||
|
@ -180,7 +180,7 @@ func generateTeamIssuesFile(team fic.Team) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
||||
func addClaimDescription(claim *fic.Claim, body []byte) (interface{}, error) {
|
||||
var ud fic.ClaimDescription
|
||||
if err := json.Unmarshal(body, &ud); err != nil {
|
||||
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
|
||||
|
@ -199,7 +199,7 @@ func addClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
||||
func updateClaimDescription(claim *fic.Claim, body []byte) (interface{}, error) {
|
||||
var ud fic.ClaimDescription
|
||||
if err := json.Unmarshal(body, &ud); err != nil {
|
||||
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
|
||||
|
@ -216,7 +216,7 @@ func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
|
||||
func updateClaim(claim *fic.Claim, body []byte) (interface{}, error) {
|
||||
var uc ClaimUploaded
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
|
||||
|
@ -261,7 +261,7 @@ func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func deleteClaim(claim fic.Claim, _ []byte) (interface{}, error) {
|
||||
func deleteClaim(claim *fic.Claim, _ []byte) (interface{}, error) {
|
||||
return claim.Delete()
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ func getAssignees(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.GetAssignees()
|
||||
}
|
||||
|
||||
func showClaimAssignee(assignee fic.ClaimAssignee, _ []byte) (interface{}, error) {
|
||||
func showClaimAssignee(assignee *fic.ClaimAssignee, _ []byte) (interface{}, error) {
|
||||
return assignee, nil
|
||||
}
|
||||
func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
|
@ -281,7 +281,7 @@ func newAssignee(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return fic.NewClaimAssignee(ua.Name)
|
||||
}
|
||||
|
||||
func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{}, error) {
|
||||
func updateClaimAssignee(assignee *fic.ClaimAssignee, body []byte) (interface{}, error) {
|
||||
var ua fic.ClaimAssignee
|
||||
if err := json.Unmarshal(body, &ua); err != nil {
|
||||
return nil, fmt.Errorf("Unable to decode JSON: %w", err)
|
||||
|
@ -296,6 +296,6 @@ func updateClaimAssignee(assignee fic.ClaimAssignee, body []byte) (interface{},
|
|||
}
|
||||
}
|
||||
|
||||
func deleteClaimAssignee(assignee fic.ClaimAssignee, _ []byte) (interface{}, error) {
|
||||
func deleteClaimAssignee(assignee *fic.ClaimAssignee, _ []byte) (interface{}, error) {
|
||||
return assignee.Delete()
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func getLastEvents(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func showEvent(event fic.Event, _ []byte) (interface{}, error) {
|
||||
func showEvent(event *fic.Event, _ []byte) (interface{}, error) {
|
||||
return event, nil
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ func clearEvents(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.ClearEvents()
|
||||
}
|
||||
|
||||
func updateEvent(event fic.Event, body []byte) (interface{}, error) {
|
||||
func updateEvent(event *fic.Event, body []byte) (interface{}, error) {
|
||||
var ue fic.Event
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
|
@ -87,7 +87,7 @@ func updateEvent(event fic.Event, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func deleteEvent(event fic.Event, _ []byte) (interface{}, error) {
|
||||
func deleteEvent(event *fic.Event, _ []byte) (interface{}, error) {
|
||||
if i, err := event.Delete(); err != nil {
|
||||
return i, err
|
||||
} else {
|
||||
|
|
|
@ -66,24 +66,24 @@ func init() {
|
|||
|
||||
// Synchronize
|
||||
router.POST("/api/sync/themes/:thid/exercices/:eid", apiHandler(themedExerciceHandler(
|
||||
func(theme fic.Theme, exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(theme *fic.Theme, exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
_, _, errs := sync.SyncExercice(sync.GlobalImporter, theme, exercice.Path, nil)
|
||||
return errs, nil
|
||||
})))
|
||||
router.POST("/api/sync/exercices/:eid/hints", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice))
|
||||
return errs, nil
|
||||
})))
|
||||
router.POST("/api/sync/exercices/:eid/flags", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice)
|
||||
_, herrs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice))
|
||||
return append(errs, herrs...), nil
|
||||
})))
|
||||
|
||||
router.POST("/api/sync/exercices/:eid/fixurlid", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
if exercice.FixURLId() {
|
||||
return exercice.Update()
|
||||
}
|
||||
|
@ -125,13 +125,13 @@ func loadFlags(n func() ([]fic.Flag, error)) (interface{}, error) {
|
|||
var ret []fic.Flag
|
||||
|
||||
for _, flag := range flags {
|
||||
if f, ok := flag.(fic.FlagKey); ok {
|
||||
if f, ok := flag.(*fic.FlagKey); ok {
|
||||
if k, err := fic.GetFlagKey(f.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
ret = append(ret, k)
|
||||
}
|
||||
} else if f, ok := flag.(fic.MCQ); ok {
|
||||
} else if f, ok := flag.(*fic.MCQ); ok {
|
||||
if m, err := fic.GetMCQ(f.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
@ -146,27 +146,27 @@ func loadFlags(n func() ([]fic.Flag, error)) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func listExerciceHints(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func listExerciceHints(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice.GetHints()
|
||||
}
|
||||
|
||||
func listExerciceFlags(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func listExerciceFlags(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice.GetFlagKeys()
|
||||
}
|
||||
|
||||
func listFlagChoices(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func listFlagChoices(flag *fic.FlagKey, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return flag.GetChoices()
|
||||
}
|
||||
|
||||
func listExerciceQuiz(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func listExerciceQuiz(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice.GetMCQ()
|
||||
}
|
||||
|
||||
func showExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showExercice(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice, nil
|
||||
}
|
||||
|
||||
func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func getExerciceHistory(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice.GetHistory()
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ type exerciceStats struct {
|
|||
MCQSolved []int64 `json:"mcq_solved"`
|
||||
}
|
||||
|
||||
func getExerciceStats(e fic.Exercice, body []byte) (interface{}, error) {
|
||||
func getExerciceStats(e *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exerciceStats{
|
||||
TeamTries: e.TriedTeamCount(),
|
||||
TotalTries: e.TriedCount(),
|
||||
|
@ -216,7 +216,7 @@ type uploadedExerciceHistory struct {
|
|||
Coeff float32
|
||||
}
|
||||
|
||||
func updateExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func updateExerciceHistory(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uh uploadedExerciceHistory
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
|
@ -225,7 +225,7 @@ func updateExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, err
|
|||
return exercice.UpdateHistoryItem(uh.Coeff, uh.IdTeam, uh.Kind, uh.Time, uh.Secondary)
|
||||
}
|
||||
|
||||
func delExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func delExerciceHistory(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uh uploadedExerciceHistory
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
|
@ -234,11 +234,11 @@ func delExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
return exercice.DelHistoryItem(uh.IdTeam, uh.Kind, uh.Time, uh.Secondary)
|
||||
}
|
||||
|
||||
func deleteExercice(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func deleteExercice(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return exercice.DeleteCascade()
|
||||
}
|
||||
|
||||
func updateExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func updateExercice(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var ue fic.Exercice
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
|
@ -257,7 +257,7 @@ func updateExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
|||
return ue, nil
|
||||
}
|
||||
|
||||
func partUpdateExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func partUpdateExercice(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var ue fic.Exercice
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
return nil, err
|
||||
|
@ -318,7 +318,7 @@ func partUpdateExercice(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
return exercice, nil
|
||||
}
|
||||
|
||||
func createExercice(theme fic.Theme, body []byte) (interface{}, error) {
|
||||
func createExercice(theme *fic.Theme, body []byte) (interface{}, error) {
|
||||
// Create a new exercice
|
||||
var ue fic.Exercice
|
||||
if err := json.Unmarshal(body, &ue); err != nil {
|
||||
|
@ -334,7 +334,7 @@ func createExercice(theme fic.Theme, body []byte) (interface{}, error) {
|
|||
if d, err := fic.GetExercice(*ue.Depend); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
depend = &d
|
||||
depend = d
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ type uploadedHint struct {
|
|||
URI string
|
||||
}
|
||||
|
||||
func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func createExerciceHint(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uh uploadedHint
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
|
@ -367,15 +367,15 @@ func createExerciceHint(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
}
|
||||
}
|
||||
|
||||
func showExerciceHint(hint fic.EHint, body []byte) (interface{}, error) {
|
||||
func showExerciceHint(hint *fic.EHint, body []byte) (interface{}, error) {
|
||||
return hint, nil
|
||||
}
|
||||
|
||||
func showExerciceHintDeps(hint fic.EHint, body []byte) (interface{}, error) {
|
||||
func showExerciceHintDeps(hint *fic.EHint, body []byte) (interface{}, error) {
|
||||
return loadFlags(hint.GetDepends)
|
||||
}
|
||||
|
||||
func updateExerciceHint(hint fic.EHint, body []byte) (interface{}, error) {
|
||||
func updateExerciceHint(hint *fic.EHint, body []byte) (interface{}, error) {
|
||||
var uh fic.EHint
|
||||
if err := json.Unmarshal(body, &uh); err != nil {
|
||||
return nil, err
|
||||
|
@ -394,7 +394,7 @@ func updateExerciceHint(hint fic.EHint, body []byte) (interface{}, error) {
|
|||
return uh, nil
|
||||
}
|
||||
|
||||
func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) {
|
||||
func deleteExerciceHint(hint *fic.EHint, _ []byte) (interface{}, error) {
|
||||
return hint.Delete()
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ type uploadedFlag struct {
|
|||
ChoicesCost int64 `json:"choices_cost"`
|
||||
}
|
||||
|
||||
func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func createExerciceFlag(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uk uploadedFlag
|
||||
if err := json.Unmarshal(body, &uk); err != nil {
|
||||
return nil, err
|
||||
|
@ -428,15 +428,15 @@ func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
return exercice.AddRawFlagKey(uk.Label, uk.Type, uk.Placeholder, uk.IgnoreCase, uk.Multiline, vre, []byte(uk.Flag), uk.ChoicesCost)
|
||||
}
|
||||
|
||||
func showExerciceFlag(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showExerciceFlag(flag *fic.FlagKey, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return flag, nil
|
||||
}
|
||||
|
||||
func showExerciceFlagDeps(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showExerciceFlagDeps(flag *fic.FlagKey, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return loadFlags(flag.GetDepends)
|
||||
}
|
||||
|
||||
func tryExerciceFlag(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func tryExerciceFlag(flag *fic.FlagKey, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uk uploadedFlag
|
||||
if err := json.Unmarshal(body, &uk); err != nil {
|
||||
return nil, err
|
||||
|
@ -453,7 +453,7 @@ func tryExerciceFlag(flag fic.FlagKey, _ fic.Exercice, body []byte) (interface{}
|
|||
}
|
||||
}
|
||||
|
||||
func updateExerciceFlag(flag fic.FlagKey, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func updateExerciceFlag(flag *fic.FlagKey, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uk uploadedFlag
|
||||
if err := json.Unmarshal(body, &uk); err != nil {
|
||||
return nil, err
|
||||
|
@ -492,11 +492,11 @@ func updateExerciceFlag(flag fic.FlagKey, exercice fic.Exercice, body []byte) (i
|
|||
return flag, nil
|
||||
}
|
||||
|
||||
func deleteExerciceFlag(flag fic.FlagKey, _ fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func deleteExerciceFlag(flag *fic.FlagKey, _ *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return flag.Delete()
|
||||
}
|
||||
|
||||
func createFlagChoice(flag fic.FlagKey, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func createFlagChoice(flag *fic.FlagKey, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uc fic.FlagChoice
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
return nil, err
|
||||
|
@ -506,14 +506,14 @@ func createFlagChoice(flag fic.FlagKey, exercice fic.Exercice, body []byte) (int
|
|||
uc.Label = uc.Value
|
||||
}
|
||||
|
||||
return flag.AddChoice(uc)
|
||||
return flag.AddChoice(&uc)
|
||||
}
|
||||
|
||||
func showFlagChoice(choice fic.FlagChoice, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showFlagChoice(choice *fic.FlagChoice, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return choice, nil
|
||||
}
|
||||
|
||||
func updateFlagChoice(choice fic.FlagChoice, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func updateFlagChoice(choice *fic.FlagChoice, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uc fic.FlagChoice
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
return nil, err
|
||||
|
@ -534,19 +534,19 @@ func updateFlagChoice(choice fic.FlagChoice, _ fic.Exercice, body []byte) (inter
|
|||
return choice, nil
|
||||
}
|
||||
|
||||
func deleteFlagChoice(choice fic.FlagChoice, _ fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func deleteFlagChoice(choice *fic.FlagChoice, _ *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return choice.Delete()
|
||||
}
|
||||
|
||||
func showExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showExerciceQuiz(quiz *fic.MCQ, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return quiz, nil
|
||||
}
|
||||
|
||||
func showExerciceQuizDeps(quiz fic.MCQ, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showExerciceQuizDeps(quiz *fic.MCQ, _ *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return loadFlags(quiz.GetDepends)
|
||||
}
|
||||
|
||||
func updateExerciceQuiz(quiz fic.MCQ, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func updateExerciceQuiz(quiz *fic.MCQ, exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uq fic.MCQ
|
||||
if err := json.Unmarshal(body, &uq); err != nil {
|
||||
return nil, err
|
||||
|
@ -604,7 +604,7 @@ func updateExerciceQuiz(quiz fic.MCQ, exercice fic.Exercice, body []byte) (inter
|
|||
return quiz, nil
|
||||
}
|
||||
|
||||
func deleteExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func deleteExerciceQuiz(quiz *fic.MCQ, _ *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
for _, choice := range quiz.Entries {
|
||||
if _, err := choice.Delete(); err != nil {
|
||||
return nil, err
|
||||
|
@ -614,11 +614,11 @@ func deleteExerciceQuiz(quiz fic.MCQ, _ fic.Exercice, _ []byte) (interface{}, er
|
|||
return quiz.Delete()
|
||||
}
|
||||
|
||||
func listExerciceTags(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func listExerciceTags(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return exercice.GetTags()
|
||||
}
|
||||
|
||||
func addExerciceTag(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func addExerciceTag(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var ut []string
|
||||
if err := json.Unmarshal(body, &ut); err != nil {
|
||||
return nil, err
|
||||
|
@ -634,7 +634,7 @@ func addExerciceTag(exercice fic.Exercice, body []byte) (interface{}, error) {
|
|||
return ut, nil
|
||||
}
|
||||
|
||||
func updateExerciceTags(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func updateExerciceTags(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
exercice.WipeTags()
|
||||
return addExerciceTag(exercice, body)
|
||||
}
|
||||
|
|
|
@ -36,17 +36,17 @@ func init() {
|
|||
|
||||
// Synchronize
|
||||
router.POST("/api/sync/exercices/:eid/files", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return sync.SyncExerciceFiles(sync.GlobalImporter, exercice), nil
|
||||
})))
|
||||
}
|
||||
|
||||
type APIFile struct {
|
||||
fic.EFile
|
||||
*fic.EFile
|
||||
Depends []fic.Flag `json:"depends,omitempty"`
|
||||
}
|
||||
|
||||
func genFileList(in []fic.EFile, e error) (out []APIFile, err error) {
|
||||
func genFileList(in []*fic.EFile, e error) (out []APIFile, err error) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
@ -61,14 +61,14 @@ func genFileList(in []fic.EFile, e error) (out []APIFile, err error) {
|
|||
}
|
||||
|
||||
for _, d := range deps {
|
||||
if k, ok := d.(fic.FlagKey); ok {
|
||||
if k, ok := d.(*fic.FlagKey); ok {
|
||||
k, err = fic.GetFlagKey(k.Id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
g.Depends = append(g.Depends, k)
|
||||
} else if m, ok := d.(fic.MCQ); ok {
|
||||
} else if m, ok := d.(*fic.MCQ); ok {
|
||||
m, err = fic.GetMCQ(m.Id)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -91,7 +91,7 @@ func listFiles(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return genFileList(fic.GetFiles())
|
||||
}
|
||||
|
||||
func listExerciceFiles(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func listExerciceFiles(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
return genFileList(exercice.GetFiles())
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ func clearFiles(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.ClearFiles()
|
||||
}
|
||||
|
||||
func showFile(file fic.EFile, _ []byte) (interface{}, error) {
|
||||
func showFile(file *fic.EFile, _ []byte) (interface{}, error) {
|
||||
return file, nil
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ type uploadedFile struct {
|
|||
Digest string
|
||||
}
|
||||
|
||||
func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func createExerciceFile(exercice *fic.Exercice, body []byte) (interface{}, error) {
|
||||
var uf uploadedFile
|
||||
if err := json.Unmarshal(body, &uf); err != nil {
|
||||
return nil, err
|
||||
|
@ -124,7 +124,7 @@ func createExerciceFile(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
})
|
||||
}
|
||||
|
||||
func updateFile(file fic.EFile, body []byte) (interface{}, error) {
|
||||
func updateFile(file *fic.EFile, body []byte) (interface{}, error) {
|
||||
var uf fic.EFile
|
||||
if err := json.Unmarshal(body, &uf); err != nil {
|
||||
return nil, err
|
||||
|
@ -139,14 +139,14 @@ func updateFile(file fic.EFile, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func deleteFile(file fic.EFile, _ []byte) (interface{}, error) {
|
||||
func deleteFile(file *fic.EFile, _ []byte) (interface{}, error) {
|
||||
return file.Delete()
|
||||
}
|
||||
|
||||
func deleteFileDep(file fic.EFile, depid int, _ []byte) (interface{}, error) {
|
||||
return true, file.DeleteDepend(fic.FlagKey{Id: depid})
|
||||
func deleteFileDep(file *fic.EFile, depid int, _ []byte) (interface{}, error) {
|
||||
return true, file.DeleteDepend(&fic.FlagKey{Id: depid})
|
||||
}
|
||||
|
||||
func checkFile(file fic.EFile, _ []byte) (interface{}, error) {
|
||||
func checkFile(file *fic.EFile, _ []byte) (interface{}, error) {
|
||||
return true, file.CheckFileOnDisk()
|
||||
}
|
||||
|
|
|
@ -94,12 +94,12 @@ func teamPublicHandler(f func(*fic.Team, []byte) (interface{}, error)) func(http
|
|||
} else if team, err := fic.GetTeam(tid); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return f(&team, body)
|
||||
return f(team, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func teamHandler(f func(*fic.Team, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if tid, err := strconv.ParseInt(string(ps.ByName("tid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -111,11 +111,11 @@ func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.
|
|||
}
|
||||
}
|
||||
|
||||
func teamAssocHandler(f func(fic.Team, string, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func teamAssocHandler(f func(*fic.Team, string, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var team fic.Team
|
||||
var team *fic.Team
|
||||
|
||||
teamHandler(func(tm fic.Team, _ []byte) (interface{}, error) {
|
||||
teamHandler(func(tm *fic.Team, _ []byte) (interface{}, error) {
|
||||
team = tm
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
@ -124,7 +124,7 @@ func teamAssocHandler(f func(fic.Team, string, []byte) (interface{}, error)) fun
|
|||
}
|
||||
}
|
||||
|
||||
func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func themeHandler(f func(*fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if thid, err := strconv.ParseInt(string(ps.ByName("thid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -136,7 +136,7 @@ func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httproute
|
|||
}
|
||||
}
|
||||
|
||||
func exerciceHandler(f func(fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func exerciceHandler(f func(*fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if eid, err := strconv.ParseInt(string(ps.ByName("eid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -148,17 +148,17 @@ func exerciceHandler(f func(fic.Exercice, []byte) (interface{}, error)) func(htt
|
|||
}
|
||||
}
|
||||
|
||||
func themedExerciceHandler(f func(fic.Theme, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func themedExerciceHandler(f func(*fic.Theme, *fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var theme fic.Theme
|
||||
var exercice fic.Exercice
|
||||
var theme *fic.Theme
|
||||
var exercice *fic.Exercice
|
||||
|
||||
themeHandler(func(th fic.Theme, _ []byte) (interface{}, error) {
|
||||
themeHandler(func(th *fic.Theme, _ []byte) (interface{}, error) {
|
||||
theme = th
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
|
||||
exerciceHandler(func(ex *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
exercice = ex
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
@ -167,7 +167,7 @@ func themedExerciceHandler(f func(fic.Theme, fic.Exercice, []byte) (interface{},
|
|||
}
|
||||
}
|
||||
|
||||
func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func hintHandler(f func(*fic.EHint, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if hid, err := strconv.ParseInt(string(ps.ByName("hid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -179,10 +179,10 @@ func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter
|
|||
}
|
||||
}
|
||||
|
||||
func flagKeyHandler(f func(fic.FlagKey, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func flagKeyHandler(f func(*fic.FlagKey, *fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var exercice fic.Exercice
|
||||
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
|
||||
var exercice *fic.Exercice
|
||||
exerciceHandler(func(ex *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
exercice = ex
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
@ -202,11 +202,11 @@ func flagKeyHandler(f func(fic.FlagKey, fic.Exercice, []byte) (interface{}, erro
|
|||
}
|
||||
}
|
||||
|
||||
func choiceHandler(f func(fic.FlagChoice, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func choiceHandler(f func(*fic.FlagChoice, *fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var exercice fic.Exercice
|
||||
var flag fic.FlagKey
|
||||
flagKeyHandler(func(fl fic.FlagKey, ex fic.Exercice, _ []byte) (interface{}, error) {
|
||||
var exercice *fic.Exercice
|
||||
var flag *fic.FlagKey
|
||||
flagKeyHandler(func(fl *fic.FlagKey, ex *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
exercice = ex
|
||||
flag = fl
|
||||
return nil, nil
|
||||
|
@ -222,10 +222,10 @@ func choiceHandler(f func(fic.FlagChoice, fic.Exercice, []byte) (interface{}, er
|
|||
}
|
||||
}
|
||||
|
||||
func quizHandler(f func(fic.MCQ, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func quizHandler(f func(*fic.MCQ, *fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var exercice fic.Exercice
|
||||
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
|
||||
var exercice *fic.Exercice
|
||||
exerciceHandler(func(ex *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
exercice = ex
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
@ -245,10 +245,10 @@ func quizHandler(f func(fic.MCQ, fic.Exercice, []byte) (interface{}, error)) fun
|
|||
}
|
||||
}
|
||||
|
||||
func exerciceFileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func exerciceFileHandler(f func(*fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var exercice fic.Exercice
|
||||
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
|
||||
var exercice *fic.Exercice
|
||||
exerciceHandler(func(ex *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
exercice = ex
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
@ -268,7 +268,7 @@ func exerciceFileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(ht
|
|||
}
|
||||
}
|
||||
|
||||
func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func eventHandler(f func(*fic.Event, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if evid, err := strconv.ParseInt(string(ps.ByName("evid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -280,7 +280,7 @@ func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httproute
|
|||
}
|
||||
}
|
||||
|
||||
func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func claimHandler(f func(*fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil {
|
||||
return nil, fmt.Errorf("Invalid claim id: %w", err)
|
||||
|
@ -292,7 +292,7 @@ func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httproute
|
|||
}
|
||||
}
|
||||
|
||||
func claimAssigneeHandler(f func(fic.ClaimAssignee, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func claimAssigneeHandler(f func(*fic.ClaimAssignee, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if aid, err := strconv.ParseInt(string(ps.ByName("aid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -304,7 +304,7 @@ func claimAssigneeHandler(f func(fic.ClaimAssignee, []byte) (interface{}, error)
|
|||
}
|
||||
}
|
||||
|
||||
func fileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func fileHandler(f func(*fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if fileid, err := strconv.ParseInt(string(ps.ByName("fileid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -316,19 +316,19 @@ func fileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter
|
|||
}
|
||||
}
|
||||
|
||||
func fileDependancyHandler(f func(fic.EFile, int, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func fileDependancyHandler(f func(*fic.EFile, int, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if depid, err := strconv.ParseInt(string(ps.ByName("depid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return fileHandler(func(file fic.EFile, b []byte) (interface{}, error) {
|
||||
return fileHandler(func(file *fic.EFile, b []byte) (interface{}, error) {
|
||||
return f(file, int(depid), b)
|
||||
})(ps, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func certificateHandler(f func(fic.Certificate, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func certificateHandler(f func(*fic.Certificate, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var cid uint64
|
||||
var err error
|
||||
|
|
|
@ -25,11 +25,11 @@ func init() {
|
|||
}
|
||||
}))
|
||||
router.GET("/api/teams/:tid/password", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.Password, nil
|
||||
})))
|
||||
router.POST("/api/teams/:tid/password", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
if passwd, err := fic.GeneratePassword(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
@ -145,7 +145,7 @@ type dexConfigClient struct {
|
|||
|
||||
type dexConfig struct {
|
||||
Clients []dexConfigClient
|
||||
Teams []fic.Team
|
||||
Teams []*fic.Team
|
||||
}
|
||||
|
||||
func genDexConfig() ([]byte, error) {
|
||||
|
|
|
@ -15,7 +15,7 @@ func init() {
|
|||
router.POST("/api/qa/:qid/comments", apiHandler(qaHandler(importQAComment)))
|
||||
}
|
||||
|
||||
func qaHandler(f func(fic.QAQuery, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
func qaHandler(f func(*fic.QAQuery, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if qid, err := strconv.ParseInt(string(ps.ByName("qid")), 10, 64); err != nil {
|
||||
return nil, err
|
||||
|
@ -34,7 +34,7 @@ func importExerciceQA(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var exercice fic.Exercice
|
||||
var exercice *fic.Exercice
|
||||
var err error
|
||||
if uq.IdExercice == 0 {
|
||||
return nil, errors.New("id_exercice not filled")
|
||||
|
@ -62,7 +62,7 @@ func importExerciceQA(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func importQAComment(query fic.QAQuery, body []byte) (interface{}, error) {
|
||||
func importQAComment(query *fic.QAQuery, body []byte) (interface{}, error) {
|
||||
// Create a new query
|
||||
var uc fic.QAComment
|
||||
if err := json.Unmarshal(body, &uc); err != nil {
|
||||
|
|
|
@ -48,17 +48,17 @@ func init() {
|
|||
router.POST("/api/teams/", apiHandler(createTeam))
|
||||
|
||||
router.GET("/api/teams/:tid/", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team, nil
|
||||
})))
|
||||
router.PUT("/api/teams/:tid/", apiHandler(teamHandler(updateTeam)))
|
||||
router.POST("/api/teams/:tid/", apiHandler(teamHandler(addTeamMember)))
|
||||
router.DELETE("/api/teams/:tid/", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.Delete()
|
||||
})))
|
||||
router.GET("/api/teams/:tid/score-grid.json", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.ScoreGrid()
|
||||
})))
|
||||
router.GET("/api/teams/:tid/my.json", apiHandler(teamPublicHandler(
|
||||
|
@ -91,7 +91,7 @@ func init() {
|
|||
return fic.GetTries(team, nil)
|
||||
})))
|
||||
router.GET("/api/teams/:tid/members", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||
return team.GetMembers()
|
||||
})))
|
||||
router.POST("/api/teams/:tid/members", apiHandler(teamHandler(addTeamMember)))
|
||||
|
@ -163,7 +163,7 @@ func createTeam(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return fic.CreateTeam(strings.TrimSpace(ut.Name), ut.Color, ut.ExternalId)
|
||||
}
|
||||
|
||||
func updateTeam(team fic.Team, body []byte) (interface{}, error) {
|
||||
func updateTeam(team *fic.Team, body []byte) (interface{}, error) {
|
||||
var ut fic.Team
|
||||
if err := json.Unmarshal(body, &ut); err != nil {
|
||||
return nil, err
|
||||
|
@ -229,7 +229,7 @@ func enableAllTeams(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func addTeamMember(team fic.Team, body []byte) (interface{}, error) {
|
||||
func addTeamMember(team *fic.Team, body []byte) (interface{}, error) {
|
||||
var members []fic.Member
|
||||
if err := json.Unmarshal(body, &members); err != nil {
|
||||
return nil, err
|
||||
|
@ -242,7 +242,7 @@ func addTeamMember(team fic.Team, body []byte) (interface{}, error) {
|
|||
return team.GetMembers()
|
||||
}
|
||||
|
||||
func setTeamMember(team fic.Team, body []byte) (interface{}, error) {
|
||||
func setTeamMember(team *fic.Team, body []byte) (interface{}, error) {
|
||||
var members []fic.Member
|
||||
if err := json.Unmarshal(body, &members); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -72,7 +72,7 @@ func init() {
|
|||
return sync.SyncDeep(sync.GlobalImporter), nil
|
||||
}))
|
||||
router.POST("/api/sync/deep/:thid", apiHandler(themeHandler(
|
||||
func(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func(theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
st := sync.SyncThemeDeep(sync.GlobalImporter, theme, 0, 250)
|
||||
sync.EditDeepReport(map[string][]string{theme.Name: st}, false)
|
||||
sync.DeepSyncProgress = 255
|
||||
|
@ -126,27 +126,27 @@ func init() {
|
|||
return sync.SyncThemes(sync.GlobalImporter), nil
|
||||
}))
|
||||
router.POST("/api/sync/themes/:thid/exercices", apiHandler(themeHandler(
|
||||
func(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func(theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
return sync.SyncExercices(sync.GlobalImporter, theme), nil
|
||||
})))
|
||||
router.POST("/api/sync/themes/:thid/exercices/:eid/files", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
return sync.SyncExerciceFiles(sync.GlobalImporter, exercice), nil
|
||||
})))
|
||||
router.POST("/api/sync/themes/:thid/exercices/:eid/hints", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice))
|
||||
return errs, nil
|
||||
})))
|
||||
router.POST("/api/sync/themes/:thid/exercices/:eid/keys", apiHandler(exerciceHandler(
|
||||
func(exercice fic.Exercice, _ []byte) (interface{}, error) {
|
||||
func(exercice *fic.Exercice, _ []byte) (interface{}, error) {
|
||||
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice)
|
||||
_, herrs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice))
|
||||
return append(errs, herrs...), nil
|
||||
})))
|
||||
|
||||
router.POST("/api/sync/themes/:thid/fixurlid", apiHandler(themeHandler(
|
||||
func(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func(theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
if theme.FixURLId() {
|
||||
return theme.Update()
|
||||
}
|
||||
|
@ -190,13 +190,13 @@ func bindingFiles(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func getExercice(args []string) (fic.Exercice, error) {
|
||||
func getExercice(args []string) (*fic.Exercice, error) {
|
||||
if tid, err := strconv.ParseInt(string(args[0]), 10, 64); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
return nil, err
|
||||
} else if theme, err := fic.GetTheme(tid); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
return nil, err
|
||||
} else if eid, err := strconv.Atoi(string(args[1])); err != nil {
|
||||
return fic.Exercice{}, err
|
||||
return nil, err
|
||||
} else {
|
||||
return theme.GetExercice(eid)
|
||||
}
|
||||
|
@ -210,15 +210,15 @@ func exportThemes(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return fic.ExportThemes()
|
||||
}
|
||||
|
||||
func showTheme(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func showTheme(theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
return theme, nil
|
||||
}
|
||||
|
||||
func listThemedExercices(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func listThemedExercices(theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
return theme.GetExercices()
|
||||
}
|
||||
|
||||
func showThemedExercice(theme fic.Theme, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
func showThemedExercice(theme *fic.Theme, exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
return exercice, nil
|
||||
}
|
||||
|
||||
|
@ -232,10 +232,10 @@ func createTheme(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return nil, errors.New("Theme's name not filled")
|
||||
}
|
||||
|
||||
return fic.CreateTheme(ut)
|
||||
return fic.CreateTheme(&ut)
|
||||
}
|
||||
|
||||
func updateTheme(theme fic.Theme, body []byte) (interface{}, error) {
|
||||
func updateTheme(theme *fic.Theme, body []byte) (interface{}, error) {
|
||||
var ut fic.Theme
|
||||
if err := json.Unmarshal(body, &ut); err != nil {
|
||||
return nil, err
|
||||
|
@ -254,11 +254,11 @@ func updateTheme(theme fic.Theme, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func deleteTheme(theme fic.Theme, _ []byte) (interface{}, error) {
|
||||
func deleteTheme(theme *fic.Theme, _ []byte) (interface{}, error) {
|
||||
return theme.Delete()
|
||||
}
|
||||
|
||||
func getThemedExercicesStats(theme fic.Theme, body []byte) (interface{}, error) {
|
||||
func getThemedExercicesStats(theme *fic.Theme, body []byte) (interface{}, error) {
|
||||
if exercices, err := theme.GetExercices(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
|
Reference in a new issue