|
1 | 1 | package api |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
| 5 | + "strconv" |
| 6 | + "strings" |
| 7 | + |
4 | 8 | "github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels" |
5 | 9 | "github.com/supertokens/supertokens-golang/recipe/emailpassword" |
6 | 10 | "github.com/supertokens/supertokens-golang/recipe/passwordless" |
7 | 11 | "github.com/supertokens/supertokens-golang/recipe/thirdparty" |
8 | 12 | "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" |
9 | 13 | "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless" |
| 14 | + "github.com/supertokens/supertokens-golang/supertokens" |
10 | 15 | ) |
11 | 16 |
|
12 | 17 | func IsValidRecipeId(recipeId string) bool { |
@@ -183,3 +188,48 @@ func IsRecipeInitialised(recipeId string) bool { |
183 | 188 |
|
184 | 189 | return isRecipeInitialised |
185 | 190 | } |
| 191 | + |
| 192 | +// TODO: Add tests |
| 193 | +func getUsersWithSearch(timeJoinedOrder string, paginationToken *string, limit *int, includeRecipeIds *[]string, searchParams map[string]string) (supertokens.UserPaginationResult, error) { |
| 194 | + |
| 195 | + querier, err := supertokens.GetNewQuerierInstanceOrThrowError("") |
| 196 | + if err != nil { |
| 197 | + return supertokens.UserPaginationResult{}, err |
| 198 | + } |
| 199 | + |
| 200 | + requestBody := map[string]string{} |
| 201 | + if searchParams != nil { |
| 202 | + requestBody = searchParams |
| 203 | + } |
| 204 | + requestBody["timeJoinedOrder"] = timeJoinedOrder |
| 205 | + if limit != nil { |
| 206 | + requestBody["limit"] = strconv.Itoa(*limit) |
| 207 | + } |
| 208 | + if paginationToken != nil { |
| 209 | + requestBody["paginationToken"] = *paginationToken |
| 210 | + } |
| 211 | + if includeRecipeIds != nil { |
| 212 | + requestBody["includeRecipeIds"] = strings.Join((*includeRecipeIds)[:], ",") |
| 213 | + } |
| 214 | + |
| 215 | + resp, err := querier.SendGetRequest("/users", requestBody) |
| 216 | + |
| 217 | + if err != nil { |
| 218 | + return supertokens.UserPaginationResult{}, err |
| 219 | + } |
| 220 | + |
| 221 | + temporaryVariable, err := json.Marshal(resp) |
| 222 | + if err != nil { |
| 223 | + return supertokens.UserPaginationResult{}, err |
| 224 | + } |
| 225 | + |
| 226 | + var result = supertokens.UserPaginationResult{} |
| 227 | + |
| 228 | + err = json.Unmarshal(temporaryVariable, &result) |
| 229 | + |
| 230 | + if err != nil { |
| 231 | + return supertokens.UserPaginationResult{}, err |
| 232 | + } |
| 233 | + |
| 234 | + return result, nil |
| 235 | +} |
0 commit comments