package fic import ( "time" ) func (t Team) GetHistory() ([]map[string]interface{}, error) { hist := make([]map[string]interface{}, 0) if rows, err := DBQuery(`SELECT id_team, "tries" AS kind, time, E.id_exercice, E.title, NULL, NULL FROM exercice_tries T INNER JOIN exercices E ON E.id_exercice = T.id_exercice WHERE id_team = ? UNION SELECT id_team, "solved" AS kind, time, E.id_exercice, E.title, coefficient, NULL FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice WHERE id_team = ? UNION SELECT id_team, "hint" AS kind, time, E.id_exercice, E.title, H.id_hint, H.title FROM team_hints T INNER JOIN exercice_hints H ON H.id_hint = T.id_hint INNER JOIN exercices E ON E.id_exercice = H.id_exercice WHERE id_team = ? UNION SELECT id_team, "key_found" AS kind, time, E.id_exercice, E.title, K.id_key, K.type FROM key_found F INNER JOIN exercice_keys K ON K.id_key = F.id_key INNER JOIN exercices E ON K.id_exercice = E.id_exercice WHERE id_team = ? ORDER BY time DESC`, t.Id, t.Id, t.Id, t.Id); err != nil { return nil, err } else { defer rows.Close() for rows.Next() { var id_team int64 var kind string var time time.Time var primary *int64 var primary_title *string var secondary *int64 var secondary_title *string if err := rows.Scan(&id_team, &kind, &time, &primary, &primary_title, &secondary, &secondary_title); err != nil { return nil, err } h := map[string]interface{}{} h["kind"] = kind h["time"] = time if primary != nil { h["primary"] = primary h["primary_title"] = primary_title } if secondary != nil { h["secondary"] = secondary h["secondary_title"] = secondary_title } hist = append(hist, h) } } return hist, nil }