Skip to content

Commit 4d8f5bd

Browse files
committed
search apis
1 parent 8dcbec4 commit 4d8f5bd

File tree

12 files changed

+120
-48
lines changed

12 files changed

+120
-48
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
package search
17+
18+
import (
19+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
20+
"github.com/supertokens/supertokens-golang/supertokens"
21+
)
22+
23+
type searchTagsResponse struct {
24+
Status string `json:"status"`
25+
Tags []string `json:"tags"`
26+
}
27+
28+
func SearchTagsGet(apiImplementation dashboardmodels.APIInterface, options dashboardmodels.APIOptions) (searchTagsResponse, error) {
29+
querier, querierErr := supertokens.GetNewQuerierInstanceOrThrowError("dashboard")
30+
31+
if querierErr != nil {
32+
return searchTagsResponse{}, querierErr
33+
}
34+
35+
apiResponse, apiErr := querier.SendGetRequest("/user/search/tags", nil)
36+
if apiErr != nil {
37+
return searchTagsResponse{}, apiErr
38+
}
39+
40+
return searchTagsResponse{
41+
Status: "OK",
42+
Tags: apiResponse["tags"].([]string),
43+
}, nil
44+
}

recipe/dashboard/api/usersGet.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package api
22

33
import (
4+
"net/url"
45
"strconv"
6+
"strings"
57
"sync"
68

79
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
@@ -64,10 +66,25 @@ func UsersGet(apiImplementation dashboardmodels.APIInterface, options dashboardm
6466

6567
var usersResponse supertokens.UserPaginationResult
6668

69+
u, err := url.Parse(req.URL.String())
70+
if err != nil {
71+
return UsersGetResponse{}, err
72+
}
73+
74+
queryParams, err := url.ParseQuery(u.RawQuery)
75+
if err != nil {
76+
return UsersGetResponse{}, err
77+
}
78+
79+
queryParamsObject := map[string]string{}
80+
for i, s := range queryParams {
81+
queryParamsObject[i] = strings.Join(s, ";")
82+
}
83+
6784
if timeJoinedOrder == "ASC" {
68-
usersResponse, err = supertokens.GetUsersOldestFirst(paginationTokenPtr, &limit, nil)
85+
usersResponse, err = supertokens.GetUsersOldestFirst(paginationTokenPtr, &limit, nil, queryParamsObject)
6986
} else {
70-
usersResponse, err = supertokens.GetUsersNewestFirst(paginationTokenPtr, &limit, nil)
87+
usersResponse, err = supertokens.GetUsersNewestFirst(paginationTokenPtr, &limit, nil, queryParamsObject)
7188
}
7289
if err != nil {
7390
return UsersGetResponse{}, err

recipe/dashboard/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ const userEmailVerifyTokenAPI = "/api/user/email/verify/token"
1212
const userPasswordAPI = "/api/user/password"
1313
const signInAPI = "/api/signin"
1414
const signOutAPI = "/api/signout"
15+
const searchTagsAPI = "/api/search/tags"

recipe/dashboard/recipe.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net/http"
2121

2222
"github.com/supertokens/supertokens-golang/recipe/dashboard/api"
23+
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/search"
2324
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails"
2425
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
2526
"github.com/supertokens/supertokens-golang/supertokens"
@@ -163,6 +164,8 @@ func (r *Recipe) handleAPIRequest(id string, req *http.Request, res http.Respons
163164
return userdetails.UserEmailVerifyTokenPost(r.APIImpl, options)
164165
} else if id == userPasswordAPI {
165166
return userdetails.UserPasswordPut(r.APIImpl, options)
167+
} else if id == searchTagsAPI {
168+
return search.SearchTagsGet(r.APIImpl, options)
166169
} else if id == signOutAPI {
167170
return api.SignOutPost(r.APIImpl, options)
168171
}

recipe/dashboard/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,10 @@ func getApiIdIfMatched(path supertokens.NormalisedURLPath, method string) (*stri
139139
return &val, nil
140140
}
141141

142+
if method == http.MethodGet && strings.HasSuffix(path.GetAsStringDangerous(), searchTagsAPI) {
143+
val := searchTagsAPI
144+
return &val, nil
145+
}
146+
142147
return nil, nil
143148
}

recipe/emailpassword/deleteUser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestDeleteUser(t *testing.T) {
6666
if err != nil {
6767
t.Error(err.Error())
6868
}
69-
reponseBeforeDeletingUser, err := supertokens.GetUsersOldestFirst(nil, nil, nil)
69+
reponseBeforeDeletingUser, err := supertokens.GetUsersOldestFirst(nil, nil, nil, nil)
7070
if err != nil {
7171
t.Error(err.Error())
7272
}
@@ -75,7 +75,7 @@ func TestDeleteUser(t *testing.T) {
7575
if err != nil {
7676
t.Error(err.Error())
7777
}
78-
reponseAfterDeletingUser, err := supertokens.GetUsersOldestFirst(nil, nil, nil)
78+
reponseAfterDeletingUser, err := supertokens.GetUsersOldestFirst(nil, nil, nil, nil)
7979
if err != nil {
8080
t.Error(err.Error())
8181
}

recipe/emailpassword/userIdMapping_users_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestCreateUserIdMappingAndGetUsers(t *testing.T) {
7171
assert.NotNil(t, createResp.OK)
7272
}
7373

74-
userResult, err := supertokens.GetUsersOldestFirst(nil, nil, nil)
74+
userResult, err := supertokens.GetUsersOldestFirst(nil, nil, nil, nil)
7575
assert.NoError(t, err)
7676
assert.NotNil(t, userResult.Users)
7777

recipe/emailpassword/user_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestGetUsersOldestFirst(t *testing.T) {
8181
t.Error(err.Error())
8282
}
8383

84-
users, err := supertokens.GetUsersOldestFirst(nil, nil, nil)
84+
users, err := supertokens.GetUsersOldestFirst(nil, nil, nil, nil)
8585
if err != nil {
8686
t.Error(err.Error())
8787
}
@@ -90,7 +90,7 @@ func TestGetUsersOldestFirst(t *testing.T) {
9090
assert.Nil(t, users.NextPaginationToken)
9191

9292
limit := 1
93-
users, err = supertokens.GetUsersOldestFirst(nil, &limit, nil)
93+
users, err = supertokens.GetUsersOldestFirst(nil, &limit, nil, nil)
9494
if err != nil {
9595
t.Error(err.Error())
9696
}
@@ -99,7 +99,7 @@ func TestGetUsersOldestFirst(t *testing.T) {
9999
assert.NotNil(t, users.NextPaginationToken)
100100
assert.Equal(t, "[email protected]", users.Users[0].User["email"])
101101

102-
users, err = supertokens.GetUsersOldestFirst(users.NextPaginationToken, &limit, nil)
102+
users, err = supertokens.GetUsersOldestFirst(users.NextPaginationToken, &limit, nil, nil)
103103
if err != nil {
104104
t.Error(err.Error())
105105
}
@@ -109,7 +109,7 @@ func TestGetUsersOldestFirst(t *testing.T) {
109109
assert.Equal(t, "[email protected]", users.Users[0].User["email"])
110110

111111
limit = 5
112-
users, err = supertokens.GetUsersOldestFirst(users.NextPaginationToken, &limit, nil)
112+
users, err = supertokens.GetUsersOldestFirst(users.NextPaginationToken, &limit, nil, nil)
113113
if err != nil {
114114
t.Error(err.Error())
115115
}
@@ -119,15 +119,15 @@ func TestGetUsersOldestFirst(t *testing.T) {
119119

120120
customPaginationToken := "invalid-pagination-token"
121121
limit = 10
122-
users, err = supertokens.GetUsersOldestFirst(&customPaginationToken, &limit, nil)
122+
users, err = supertokens.GetUsersOldestFirst(&customPaginationToken, &limit, nil, nil)
123123
if err != nil {
124124
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/users' with status code: 400 and message: invalid pagination token\n", err.Error())
125125
} else {
126126
t.Fail()
127127
}
128128

129129
limit = -1
130-
users, err = supertokens.GetUsersOldestFirst(nil, &limit, nil)
130+
users, err = supertokens.GetUsersOldestFirst(nil, &limit, nil, nil)
131131
if err != nil {
132132
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/users' with status code: 400 and message: limit must a positive integer with min value 1\n", err.Error())
133133
} else {
@@ -187,7 +187,7 @@ func TestGetUsersNewestFirst(t *testing.T) {
187187
t.Error(err.Error())
188188
}
189189

190-
users, err := supertokens.GetUsersNewestFirst(nil, nil, nil)
190+
users, err := supertokens.GetUsersNewestFirst(nil, nil, nil, nil)
191191
if err != nil {
192192
t.Error(err.Error())
193193
}
@@ -196,7 +196,7 @@ func TestGetUsersNewestFirst(t *testing.T) {
196196
assert.Nil(t, users.NextPaginationToken)
197197

198198
limit := 1
199-
users, err = supertokens.GetUsersNewestFirst(nil, &limit, nil)
199+
users, err = supertokens.GetUsersNewestFirst(nil, &limit, nil, nil)
200200
if err != nil {
201201
t.Error(err.Error())
202202
}
@@ -205,7 +205,7 @@ func TestGetUsersNewestFirst(t *testing.T) {
205205
assert.NotNil(t, users.NextPaginationToken)
206206
assert.Equal(t, "[email protected]", users.Users[0].User["email"])
207207

208-
users, err = supertokens.GetUsersNewestFirst(users.NextPaginationToken, &limit, nil)
208+
users, err = supertokens.GetUsersNewestFirst(users.NextPaginationToken, &limit, nil, nil)
209209
if err != nil {
210210
t.Error(err.Error())
211211
}
@@ -215,7 +215,7 @@ func TestGetUsersNewestFirst(t *testing.T) {
215215
assert.Equal(t, "[email protected]", users.Users[0].User["email"])
216216

217217
limit = 5
218-
users, err = supertokens.GetUsersNewestFirst(users.NextPaginationToken, &limit, nil)
218+
users, err = supertokens.GetUsersNewestFirst(users.NextPaginationToken, &limit, nil, nil)
219219
if err != nil {
220220
t.Error(err.Error())
221221
}
@@ -225,15 +225,15 @@ func TestGetUsersNewestFirst(t *testing.T) {
225225

226226
customPaginationToken := "invalid-pagination-token"
227227
limit = 10
228-
users, err = supertokens.GetUsersNewestFirst(&customPaginationToken, &limit, nil)
228+
users, err = supertokens.GetUsersNewestFirst(&customPaginationToken, &limit, nil, nil)
229229
if err != nil {
230230
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/users' with status code: 400 and message: invalid pagination token\n", err.Error())
231231
} else {
232232
t.Fail()
233233
}
234234

235235
limit = -1
236-
users, err = supertokens.GetUsersNewestFirst(nil, &limit, nil)
236+
users, err = supertokens.GetUsersNewestFirst(nil, &limit, nil, nil)
237237
if err != nil {
238238
assert.Equal(t, "SuperTokens core threw an error for a request to path: '/users' with status code: 400 and message: limit must a positive integer with min value 1\n", err.Error())
239239
} else {

recipe/thirdparty/users_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ func TestGetUsersOldesFirst(t *testing.T) {
7676
unittesting.SigninupCustomRequest(testServer.URL, "[email protected]", "testPass3")
7777
unittesting.SigninupCustomRequest(testServer.URL, "[email protected]", "testPass4")
7878

79-
userPaginationResult, err := supertokens.GetUsersOldestFirst(nil, nil, nil)
79+
userPaginationResult, err := supertokens.GetUsersOldestFirst(nil, nil, nil, nil)
8080
if err != nil {
8181
t.Error(err.Error())
8282
}
8383
assert.Equal(t, 5, len(userPaginationResult.Users))
8484
assert.Nil(t, userPaginationResult.NextPaginationToken)
8585

8686
customLimit := 1
87-
userPaginationResult, err = supertokens.GetUsersOldestFirst(nil, &customLimit, nil)
87+
userPaginationResult, err = supertokens.GetUsersOldestFirst(nil, &customLimit, nil, nil)
8888
if err != nil {
8989
t.Error(err.Error())
9090
}
9191
assert.Equal(t, 1, len(userPaginationResult.Users))
9292
assert.Equal(t, "[email protected]", userPaginationResult.Users[0].User["email"])
9393
assert.Equal(t, "*string", reflect.TypeOf(userPaginationResult.NextPaginationToken).String())
9494

95-
userPaginationResult, err = supertokens.GetUsersOldestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil)
95+
userPaginationResult, err = supertokens.GetUsersOldestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil, nil)
9696
if err != nil {
9797
t.Error(err.Error())
9898
}
@@ -101,22 +101,22 @@ func TestGetUsersOldesFirst(t *testing.T) {
101101
assert.Equal(t, "*string", reflect.TypeOf(userPaginationResult.NextPaginationToken).String())
102102

103103
customLimit = 5
104-
userPaginationResult, err = supertokens.GetUsersOldestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil)
104+
userPaginationResult, err = supertokens.GetUsersOldestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil, nil)
105105
if err != nil {
106106
t.Error(err.Error())
107107
}
108108
assert.Equal(t, 3, len(userPaginationResult.Users))
109109

110110
customInvalidPaginationToken := "invalid-pagination-token"
111-
userPaginationResult, err = supertokens.GetUsersOldestFirst(&customInvalidPaginationToken, &customLimit, nil)
111+
userPaginationResult, err = supertokens.GetUsersOldestFirst(&customInvalidPaginationToken, &customLimit, nil, nil)
112112
if err != nil {
113113
assert.Contains(t, err.Error(), "invalid pagination token")
114114
} else {
115115
t.Fail()
116116
}
117117

118118
customLimit = -1
119-
userPaginationResult, err = supertokens.GetUsersOldestFirst(nil, &customLimit, nil)
119+
userPaginationResult, err = supertokens.GetUsersOldestFirst(nil, &customLimit, nil, nil)
120120
if err != nil {
121121
assert.Contains(t, err.Error(), "limit must a positive integer with min value 1")
122122
} else {
@@ -171,23 +171,23 @@ func TestGetUsersNewestFirst(t *testing.T) {
171171
unittesting.SigninupCustomRequest(testServer.URL, "[email protected]", "testPass3")
172172
unittesting.SigninupCustomRequest(testServer.URL, "[email protected]", "testPass4")
173173

174-
userPaginationResult, err := supertokens.GetUsersNewestFirst(nil, nil, nil)
174+
userPaginationResult, err := supertokens.GetUsersNewestFirst(nil, nil, nil, nil)
175175
if err != nil {
176176
t.Error(err.Error())
177177
}
178178
assert.Equal(t, 5, len(userPaginationResult.Users))
179179
assert.Nil(t, userPaginationResult.NextPaginationToken)
180180

181181
customLimit := 1
182-
userPaginationResult, err = supertokens.GetUsersNewestFirst(nil, &customLimit, nil)
182+
userPaginationResult, err = supertokens.GetUsersNewestFirst(nil, &customLimit, nil, nil)
183183
if err != nil {
184184
t.Error(err.Error())
185185
}
186186
assert.Equal(t, 1, len(userPaginationResult.Users))
187187
assert.Equal(t, "[email protected]", userPaginationResult.Users[0].User["email"])
188188
assert.Equal(t, "*string", reflect.TypeOf(userPaginationResult.NextPaginationToken).String())
189189

190-
userPaginationResult, err = supertokens.GetUsersNewestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil)
190+
userPaginationResult, err = supertokens.GetUsersNewestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil, nil)
191191
if err != nil {
192192
t.Error(err.Error())
193193
}
@@ -196,23 +196,23 @@ func TestGetUsersNewestFirst(t *testing.T) {
196196
assert.Equal(t, "*string", reflect.TypeOf(userPaginationResult.NextPaginationToken).String())
197197

198198
customLimit = 5
199-
userPaginationResult, err = supertokens.GetUsersNewestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil)
199+
userPaginationResult, err = supertokens.GetUsersNewestFirst(userPaginationResult.NextPaginationToken, &customLimit, nil, nil)
200200
if err != nil {
201201
t.Error(err.Error())
202202
}
203203
assert.Equal(t, 3, len(userPaginationResult.Users))
204204

205205
customInvalidPaginationToken := "invalid-pagination-token"
206206
customLimit = 10
207-
userPaginationResult, err = supertokens.GetUsersNewestFirst(&customInvalidPaginationToken, &customLimit, nil)
207+
userPaginationResult, err = supertokens.GetUsersNewestFirst(&customInvalidPaginationToken, &customLimit, nil, nil)
208208
if err != nil {
209209
assert.Contains(t, err.Error(), "invalid pagination token")
210210
} else {
211211
t.Fail()
212212
}
213213

214214
customLimit = -1
215-
userPaginationResult, err = supertokens.GetUsersNewestFirst(nil, &customLimit, nil)
215+
userPaginationResult, err = supertokens.GetUsersNewestFirst(nil, &customLimit, nil, nil)
216216
if err != nil {
217217
assert.Contains(t, err.Error(), "limit must a positive integer with min value 1")
218218
} else {

0 commit comments

Comments
 (0)