//Defense get the defense of a student func (s *Store) Defense(student string) (schema.Defense, error) { d := schema.Defense{} st := s.stmt(selectDefense) var grade sql.NullInt64 err := st.QueryRow(student).Scan( &d.SessionId, &grade, &d.Public, &d.Local, &d.Time, &d.Room, ) if err == sql.ErrNoRows { return d, schema.ErrUnknownDefense } if err != nil { return d, err } d.Grade = nullableInt(grade, -1) ints, err := s.Internship(student) if err != nil { return d, err } d.Student = ints.Convention.Student return d, err }
func (s *Store) defenses() (map[string]schema.Defense, error) { defs := make(map[string]schema.Defense) st := s.stmt(selectDefenses) rows, err := st.Query() if err != nil { return defs, err } defer rows.Close() for rows.Next() { d := schema.Defense{} var s string var grade sql.NullInt64 err = rows.Scan( &s, &d.Time, &d.SessionId, &grade, &d.Public, &d.Local, ) d.Grade = nullableInt(grade, -1) if err != nil { return defs, err } defs[s] = d } return defs, nil }
func (s *Store) DefenseSession(room, id string) (schema.DefenseSession, error) { st := s.stmt(defenseSession) rows, err := st.Query(room, id) if err != nil { return schema.DefenseSession{}, err } defer rows.Close() if !rows.Next() { return schema.DefenseSession{}, schema.ErrUnknownDefense } session, err := scanDefenseSession(rows) if err != nil { return session, err } //jury st = s.stmt(selectJury) rows2, err := st.Query(room, id) if err != nil { return session, err } defer rows2.Close() for rows2.Next() { var last pq.NullTime u := schema.User{Person: schema.Person{}} var role string err := rows2.Scan(&u.Person.Firstname, &u.Person.Lastname, &u.Person.Tel, &u.Person.Email, &role, &last) u.Role = schema.Role(role) u.LastVisit = nullableTime(last) if err != nil { return session, err } session.Juries = append(session.Juries, u) } //students st = s.stmt(selectStudentInDefenseSession) rows3, err := st.Query(room, id) if err != nil { return session, err } defer rows3.Close() for rows3.Next() { var student string var grade sql.NullInt64 def := schema.Defense{} err = rows3.Scan(&student, &grade, &def.Public, &def.Local, &def.Time) if err != nil { return session, err } ints, err := s.Internship(student) if err != nil { return session, err } if grade.Valid { def.Grade = int(grade.Int64) } def.Student = ints.Convention.Student def.Company = ints.Convention.Company session.Defenses = append(session.Defenses, def) } return session, err }