Beispiel #1
0
func fetchUsers(w http.ResponseWriter, r *http.Request, dbl seed.DbLayer) {

	r.ParseForm()
	queryStr := `[{"c": ["all"]}]`
	if len(r.Form["field"]) == 1 && len(r.Form["value"]) == 1 {
		queryStr = fmt.Sprintf(`[{"eq": "%s", "in": ["%s"]}]`, r.Form["value"][0], r.Form["field"][0])
		fmt.Println("Searching with ", queryStr)
	}

	queryResult, err := dbl.Query("Users", queryStr)
	if err != nil {
		fmt.Println("Failed to query ", err)
		return
	}

	// we don't need to do this at all since the dblayer did it for us but
	// useful for debugging right now
	var usersCollection []seed.User
	json.Unmarshal(queryResult, &usersCollection)
	fmt.Println(queryResult)
	for id := range usersCollection {
		fmt.Println("Username is ", usersCollection[id].Username)
	}

	w.Write(queryResult)
}