Ejemplo n.º 1
0
func chronologiesGetTree(tx *sqlx.Tx, id int, user model.User) (answer *ChronologiesUpdateStruct, err error) {

	// answer structure that will be printed when everything is done
	answer = &ChronologiesUpdateStruct{}

	// get the chronology_root row
	answer.Chronology_root.Root_chronology_id = id
	err = answer.Chronology_root.Get(tx)
	if err != nil {
		return nil, err
	}

	// get the chronology (root)
	answer.Chronology.Id = id
	err = answer.Chronology.Get(tx)
	if err != nil {
		return nil, err
	}

	// now get the chronology translations and all childrens
	err = getChronoRecursive(tx, &answer.ChronologyTreeStruct)
	if err != nil {
		return nil, err
	}

	// get users of the chrono group
	group := model.Group{
		Id: answer.Chronology_root.Admin_group_id,
	}
	err = group.Get(tx)
	if err != nil {
		return nil, err
	}
	answer.UsersInGroup, err = group.GetUsers(tx)
	if err != nil {
		return nil, err
	}

	for i := range answer.UsersInGroup {
		answer.UsersInGroup[i].Password = ""
	}

	// get the author user
	answer.Author.Id = answer.Chronology_root.Author_user_id
	err = answer.Author.Get(tx)
	answer.Author.Password = ""
	if err != nil {
		return nil, err
	}

	return answer, nil
}
Ejemplo n.º 2
0
func characsGetTree(w http.ResponseWriter, tx *sqlx.Tx, id int, project_id int, user model.User) (answer *CharacsUpdateStruct, err error) {

	// answer structure that will be printed when everything is done
	answer = &CharacsUpdateStruct{}

	// get the charac_root row
	answer.Charac_root.Root_charac_id = id
	err = answer.Charac_root.Get(tx)
	if err != nil {
		userSqlError(w, err)
		_ = tx.Rollback()
		return nil, err
	}

	// get the charac (root)
	answer.Charac.Id = id
	err = answer.Charac.Get(tx)
	if err != nil {
		userSqlError(w, err)
		_ = tx.Rollback()
		return nil, err
	}

	// now get the charac translations and all childrens
	err = getCharacRecursive(tx, &answer.CharacTreeStruct, project_id)
	if err != nil {
		userSqlError(w, err)
		_ = tx.Rollback()
		return nil, err
	}

	// get users of the charac group
	group := model.Group{
		Id: answer.Charac_root.Admin_group_id,
	}
	err = group.Get(tx)
	if err != nil {
		userSqlError(w, err)
		_ = tx.Rollback()
		return nil, err
	}
	answer.UsersInGroup, err = group.GetUsers(tx)
	if err != nil {
		userSqlError(w, err)
		_ = tx.Rollback()
		return nil, err
	}

	for i := range answer.UsersInGroup {
		answer.UsersInGroup[i].Password = ""
	}

	// get the author user
	/*	answer.Author.Id = answer.Charac_root.Author_user_id
		err = answer.Author.Get(tx)
		answer.Author.Password = ""
		if err != nil {
			userSqlError(w, err)
			_ = tx.Rollback()
			return nil, err
		}*/ // no author in characs vs chrono

	return answer, nil
}