admin: add a new route to update team history coefficient
This commit is contained in:
parent
4125c7b161
commit
c2887a1812
2 changed files with 52 additions and 4 deletions
|
@ -242,6 +242,23 @@ type uploadedHistory struct {
|
||||||
Time time.Time
|
Time time.Time
|
||||||
Primary *int64
|
Primary *int64
|
||||||
Secondary *int64
|
Secondary *int64
|
||||||
|
Coefficient float32
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateHistory(team *fic.Team, body []byte) (interface{}, error) {
|
||||||
|
var uh uploadedHistory
|
||||||
|
if err := json.Unmarshal(body, &uh); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var givenId int64
|
||||||
|
if uh.Secondary != nil {
|
||||||
|
givenId = *uh.Secondary
|
||||||
|
} else if uh.Primary != nil {
|
||||||
|
givenId = *uh.Primary
|
||||||
|
}
|
||||||
|
|
||||||
|
return team.UpdateHistoryCoeff(uh.Kind, uh.Time, givenId, uh.Coefficient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func delHistory(team *fic.Team, body []byte) (interface{}, error) {
|
func delHistory(team *fic.Team, body []byte) (interface{}, error) {
|
||||||
|
|
|
@ -54,6 +54,37 @@ func (t Team) GetHistory() ([]map[string]interface{}, error) {
|
||||||
return hist, nil
|
return hist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateHistoryCoeff updates the coefficient for a given entry.
|
||||||
|
func (t Team) UpdateHistoryCoeff(kind string, h time.Time, givenId int64, newCoeff float32) (interface{}, error) {
|
||||||
|
if kind == "hint" {
|
||||||
|
if res, err := DBExec("UPDATE team_hints SET coefficient = ? WHERE id_team = ? AND time = ? AND id_hint = ?", newCoeff, t.Id, h, givenId); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
return nb, err
|
||||||
|
}
|
||||||
|
} else if kind == "wchoices" {
|
||||||
|
if res, err := DBExec("UPDATE team_wchoices SET coefficient = ? WHERE id_team = ? AND time = ? AND id_flag = ?", newCoeff, t.Id, h, givenId); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
return nb, err
|
||||||
|
}
|
||||||
|
} else if kind == "solved" {
|
||||||
|
if res, err := DBExec("UPDATE exercice_solved SET coefficient = ? WHERE id_team = ? AND time = ? AND id_exercice = ?", newCoeff, t.Id, h, givenId); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
return nb, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DelHistoryItem removes from the database an entry from the history.
|
// DelHistoryItem removes from the database an entry from the history.
|
||||||
func (t Team) DelHistoryItem(kind string, h time.Time, primary *int64, secondary *int64) (interface{}, error) {
|
func (t Team) DelHistoryItem(kind string, h time.Time, primary *int64, secondary *int64) (interface{}, error) {
|
||||||
if kind == "tries" && primary != nil {
|
if kind == "tries" && primary != nil {
|
||||||
|
|
Reference in a new issue