func scanUser(row *sql.Rows) (schema.User, error) { u := schema.User{Person: schema.Person{}} var last pq.NullTime var r string err := row.Scan( &u.Person.Firstname, &u.Person.Lastname, &u.Person.Email, &u.Person.Tel, &r, &last, ) u.Role = schema.Role(r) u.LastVisit = nullableTime(last) return u, err }
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 }