func setUserRole(ex Exchange) error { var p string if err := ex.inJSON(&p); err != nil { return err } r := schema.Role(p) err := ex.s.SetUserRole(ex.V("u"), r) ex.not.PrivilegeUpdated(ex.s.Me(), ex.V("u"), r, err) if err == nil { u, e := ex.s.User(ex.V("u")) return ex.outJSON(u, e) } return err }
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 scanStudent(rows *sql.Rows) (schema.Student, error) { var lastVisit pq.NullTime var nextPos sql.NullString var nextFrance, nextPermanent, nextSameCompany sql.NullBool var nextContact sql.NullString var role string s := schema.Student{ User: schema.User{ Person: schema.Person{}, }, Alumni: &schema.Alumni{}, } err := rows.Scan( &s.Male, &s.User.Person.Firstname, &s.User.Person.Lastname, &s.User.Person.Email, &s.User.Person.Tel, &role, &lastVisit, &s.Promotion, &s.Major, &nextPos, &nextFrance, &nextPermanent, &nextSameCompany, &nextContact, &s.Skip) s.User.Role = schema.Role(role) s.User.LastVisit = nullableTime(lastVisit) if nextPos.Valid { s.Alumni.Contact = nullableString(nextContact) s.Alumni.Position = nullableString(nextPos) s.Alumni.France = nullableBool(nextFrance, false) s.Alumni.Permanent = nullableBool(nextPermanent, false) s.Alumni.SameCompany = nullableBool(nextSameCompany, false) } else { s.Alumni = nil } return s, 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 }
func scanConvention(rows *sql.Rows) (schema.Convention, error) { var nextContact sql.NullString var nextPosition sql.NullString var nextFrance, nextPermanent, nextSameCompany sql.NullBool var role string c := schema.Convention{ Student: schema.Student{ User: schema.User{ Person: schema.Person{}, Role: schema.STUDENT, }, Alumni: &schema.Alumni{}, }, Tutor: schema.User{ Person: schema.Person{}, }, Supervisor: schema.Person{}, Company: schema.Company{}, } err := rows.Scan( &c.Student.User.Person.Firstname, &c.Student.User.Person.Lastname, &c.Student.User.Person.Tel, &c.Student.User.Person.Email, &c.Student.User.LastVisit, &c.Student.Male, &c.Student.Promotion, &c.Student.Major, &nextPosition, &nextFrance, &nextPermanent, &nextSameCompany, &nextContact, &c.Student.Skip, &c.Tutor.Person.Firstname, &c.Tutor.Person.Lastname, &c.Tutor.Person.Tel, &c.Tutor.Person.Email, &c.Tutor.LastVisit, &role, &c.Begin, &c.End, &c.Company.Name, &c.Company.WWW, &c.Company.Title, &c.Creation, &c.ForeignCountry, &c.Lab, &c.Gratification, &c.Supervisor.Firstname, &c.Supervisor.Lastname, &c.Supervisor.Email, &c.Supervisor.Tel, ) c.Begin = c.Begin.UTC() c.End = c.End.UTC() c.Creation = c.Creation.UTC() c.Tutor.Role = schema.Role(role) if !nextPosition.Valid { c.Student.Alumni = nil } else { c.Student.Alumni.Position = nullableString(nextPosition) c.Student.Alumni.France = nullableBool(nextFrance, false) c.Student.Alumni.Permanent = nullableBool(nextPermanent, false) c.Student.Alumni.SameCompany = nullableBool(nextSameCompany, false) c.Student.Alumni.Contact = nullableString(nextContact) } return c, err }