// GetUserByID fetches data for the given user ID.
GetUserByID fetches data for the given user ID.
// GetUserByID fetches data for the given user ID .
func GetUserByID(id int) (User, error) {
	rows, err := DB.Query("SELECT id, name, email, password, type, features, emailVerified, level, showMigrateMessage, createdAt, lastLoginAt FROM users WHERE id = ?", id)
	if err != nil {
		return User{}, err
	}
	defer rows.Close()
	if !rows.Next() {
		return User{}, ErrNotFound
	}
	user := User{}
	emailVerified := 0
	err = rows.Scan(&user.ID, &user.Name, &user.Email, &user.PasswordHash, &user.Type, &user.Features, &emailVerified, &user.Level, &user.ShowMigrateMessage, &user.CreatedAt, &user.LastLoginAt)
	if err != nil {
		return User{}, err
	}
	if emailVerified == 1 {
		user.EmailVerified = true
	}
	user.Schools = []SchoolInfo{}
	schoolRows, err := DB.Query("SELECT id, schoolId, enabled, data, userId FROM schools WHERE userId = ?", user.ID)
	if err != nil {
		return User{}, err
	}
	defer schoolRows.Close()
	for schoolRows.Next() {
		info := SchoolInfo{}
		dataString := ""
		err := schoolRows.Scan(&info.EnrollmentID, &info.SchoolID, &info.Enabled, &dataString, &info.UserID)
		if err != nil {
			return User{}, err
		}
		data := map[string]interface{}{}
		err = json.Unmarshal([]byte(dataString), &data)
		if err != nil {
			return User{}, err
		}
		school, err := MainRegistry.GetSchoolByID(info.SchoolID)
		if err != nil {
			return User{}, err
		}
		school.Hydrate(data)
		info.DisplayName = school.Name()
		info.ShortName = school.ShortName()
		info.UserDetails = school.UserDetails()
		info.EmailAddress = school.EmailAddress()
		info.School = school
		user.Schools = append(user.Schools, info)
	}
	return user, nil
}
func GetUserByID ( id int ) ( User , error ) { rows , err := DB . Query ( " " , id ) if err != nil { return User { } , err } defer rows . Close ( ) if ! rows . Next ( ) { return User { } , ErrNotFound } user := User { } emailVerified := 0 err = rows . Scan ( & user . ID , & user . Name , & user . Email , & user . PasswordHash , & user . Type , & user . Features , & emailVerified , & user . Level , & user . ShowMigrateMessage , & user . CreatedAt , & user . LastLoginAt ) if err != nil { return User { } , err } if emailVerified == 1 { user . EmailVerified = true } user . Schools = [ ] SchoolInfo { } schoolRows , err := DB . Query ( " " , user . ID ) if err != nil { return User { } , err } defer schoolRows . Close ( ) for schoolRows . Next ( ) { info := SchoolInfo { } dataString := " " err := schoolRows . Scan ( & info . EnrollmentID , & info . SchoolID , & info . Enabled , & dataString , & info . UserID ) if err != nil { return User { } , err } data := map [ string ] interface { } { } err = json . Unmarshal ( [ ] byte ( dataString ) , & data ) if err != nil { return User { } , err } school , err := MainRegistry . GetSchoolByID ( info . SchoolID ) if err != nil { return User { } , err } school . Hydrate ( data ) info . DisplayName = school . Name ( ) info . ShortName = school . ShortName ( ) info . UserDetails = school . UserDetails ( ) info . EmailAddress = school . EmailAddress ( ) info . School = school user . Schools = append ( user . Schools , info ) } return user , nil }
GetUserByID fetches data for the given user ID.
GetUserByID fetches data for the given user ID .
// parse JSON data // get school and hydrate it // set SchoolInfo