All checks were successful
continuous-integration/drone/push Build is passing
102 lines
2.5 KiB
Go
102 lines
2.5 KiB
Go
package fic
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type ExerciceTryDetail struct {
|
|
Kind string `json:"kind"`
|
|
RelatedId int64 `json:"related"`
|
|
}
|
|
|
|
type ExerciceTry struct {
|
|
Id int64 `json:"id"`
|
|
IdTeam int64 `json:"id_team"`
|
|
Time time.Time `json:"time"`
|
|
Checksum []byte `json:"checksum"`
|
|
NbDiff int64 `json:"nb_diff"`
|
|
OneGood bool `json:"one_good"`
|
|
Details []ExerciceTryDetail `json:"details,omitempty"`
|
|
}
|
|
|
|
// TriesList returns a list of tries related to the exercice.
|
|
func (e *Exercice) TriesList() ([]*ExerciceTry, error) {
|
|
tries_table := "exercice_tries"
|
|
if SubmissionUniqueness {
|
|
tries_table = "exercice_distinct_tries"
|
|
}
|
|
|
|
if rows, err := DBQuery("SELECT id_try, id_team, time, cksum, nbdiff, onegood FROM "+tries_table+" WHERE id_exercice = ?", e.Id); err != nil {
|
|
return nil, err
|
|
} else {
|
|
defer rows.Close()
|
|
|
|
var tries []*ExerciceTry
|
|
for rows.Next() {
|
|
var try ExerciceTry
|
|
if err := rows.Scan(&try.Id, &try.IdTeam, &try.Time, &try.Checksum, &try.NbDiff, &try.OneGood); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
tries = append(tries, &try)
|
|
}
|
|
|
|
return tries, nil
|
|
}
|
|
}
|
|
|
|
func (e *Exercice) GetTry(id int64) (try *ExerciceTry, err error) {
|
|
try = &ExerciceTry{}
|
|
err = DBQueryRow("SELECT id_try, id_team, time, cksum, nbdiff, onegood FROM exercice_tries WHERE id_exercice = ? AND id_try = ?", e.Id, id).Scan(&try.Id, &try.IdTeam, &try.Time, &try.Checksum, &try.NbDiff, &try.OneGood)
|
|
return
|
|
}
|
|
|
|
func (try *ExerciceTry) FillDetails() error {
|
|
if rows, err := DBQuery("SELECT id_flag FROM exercice_tries_flags WHERE id_try = ?", try.Id); err != nil {
|
|
return err
|
|
} else {
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var relatedid int64
|
|
if err := rows.Scan(&relatedid); err != nil {
|
|
return err
|
|
}
|
|
|
|
try.Details = append(try.Details, ExerciceTryDetail{
|
|
Kind: "flag",
|
|
RelatedId: relatedid,
|
|
})
|
|
}
|
|
}
|
|
|
|
if rows, err := DBQuery("SELECT id_mcq FROM exercice_tries_mcq WHERE id_try = ?", try.Id); err != nil {
|
|
return err
|
|
} else {
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var relatedid int64
|
|
if err := rows.Scan(&relatedid); err != nil {
|
|
return err
|
|
}
|
|
|
|
try.Details = append(try.Details, ExerciceTryDetail{
|
|
Kind: "mcq",
|
|
RelatedId: relatedid,
|
|
})
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (try *ExerciceTry) Delete() (int64, error) {
|
|
if res, err := DBExec("DELETE FROM exercice_tries WHERE id_try = ?", try.Id); err != nil {
|
|
return 0, err
|
|
} else if nb, err := res.RowsAffected(); err != nil {
|
|
return 0, err
|
|
} else {
|
|
return nb, err
|
|
}
|
|
}
|