Skip to content

Commit 9360890

Browse files
author
Pawel Szymanski
committed
Implement searching for users
1 parent b86ef2d commit 9360890

6 files changed

Lines changed: 63 additions & 29 deletions

File tree

api/src/main/java/com/creatubbles/api/repository/UserRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ public interface UserRepository {
137137
* When changing manager's password you have to provide both new and current password.
138138
*/
139139
void changePassword(@NonNull String userId, @NonNull PasswordChange passwordChange, @Nullable ResponseCallback<CreatubblesResponse<User>> callback);
140+
141+
/**
142+
* Method used to obtain current user's 'My Connections' filtered by {@code query} param.
143+
*/
144+
void searchConnections(@NonNull String query, @Nullable Integer page, @Nullable UserSortMode sortMode, @Nullable ResponseCallback<CreatubblesResponse<List<User>>> callback);
140145
}

api/src/main/java/com/creatubbles/api/repository/UserRepositoryImpl.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,57 +50,49 @@ public void getUser(ResponseCallback<CreatubblesResponse<User>> callback) {
5050

5151
@Override
5252
public void getCreators(@Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
53-
String sort = sortMode != null ? sortMode.getParam() : null;
54-
Call<JSONAPIDocument<List<User>>> call = userService.getCreators(CURRENT_USER, page, sort);
53+
Call<JSONAPIDocument<List<User>>> call = userService.getCreators(CURRENT_USER, null, page, getSortParam(sortMode));
5554
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
5655
}
5756

5857
@Override
5958
public void getManagers(@Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
60-
String sort = sortMode != null ? sortMode.getParam() : null;
61-
Call<JSONAPIDocument<List<User>>> call = userService.getManagers(CURRENT_USER, page, sort);
59+
Call<JSONAPIDocument<List<User>>> call = userService.getManagers(CURRENT_USER, null, page, getSortParam(sortMode));
6260
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
6361
}
6462

6563
@Override
6664
public void getConnections(@Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
67-
String sort = sortMode != null ? sortMode.getParam() : null;
68-
Call<JSONAPIDocument<List<User>>> call = userService.getConnections(CURRENT_USER, page, sort);
65+
Call<JSONAPIDocument<List<User>>> call = userService.getConnections(CURRENT_USER, null, page, getSortParam(sortMode));
6966
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
7067
}
7168

7269
@Override
7370
public void getFollowedUsers(@Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
74-
String sort = sortMode != null ? sortMode.getParam() : null;
75-
Call<JSONAPIDocument<List<User>>> call = userService.getFollowedUsers(CURRENT_USER, page, sort);
71+
Call<JSONAPIDocument<List<User>>> call = userService.getFollowedUsers(CURRENT_USER, null, page, getSortParam(sortMode));
7672
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
7773
}
7874

7975
@Override
8076
public void getCreators(@NonNull String userId, @Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
81-
String sort = sortMode != null ? sortMode.getParam() : null;
82-
Call<JSONAPIDocument<List<User>>> call = userService.getCreators(userId, page, sort);
77+
Call<JSONAPIDocument<List<User>>> call = userService.getCreators(userId, null, page, getSortParam(sortMode));
8378
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
8479
}
8580

8681
@Override
8782
public void getManagers(@NonNull String userId, @Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
88-
String sort = sortMode != null ? sortMode.getParam() : null;
89-
Call<JSONAPIDocument<List<User>>> call = userService.getManagers(userId, page, sort);
83+
Call<JSONAPIDocument<List<User>>> call = userService.getManagers(userId, null, page, getSortParam(sortMode));
9084
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
9185
}
9286

9387
@Override
9488
public void getFollowedUsers(@NonNull String userId, @Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
95-
String sort = sortMode != null ? sortMode.getParam() : null;
96-
Call<JSONAPIDocument<List<User>>> call = userService.getFollowedUsers(userId, page, sort);
89+
Call<JSONAPIDocument<List<User>>> call = userService.getFollowedUsers(userId, null, page, getSortParam(sortMode));
9790
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
9891
}
9992

10093
@Override
10194
public void getConnections(@NonNull String userId, @Nullable Integer page, UserSortMode sortMode, ResponseCallback<CreatubblesResponse<List<User>>> callback) {
102-
String sort = sortMode != null ? sortMode.getParam() : null;
103-
Call<JSONAPIDocument<List<User>>> call = userService.getConnections(userId, page, sort);
95+
Call<JSONAPIDocument<List<User>>> call = userService.getConnections(userId, null, page, getSortParam(sortMode));
10496
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
10597
}
10698

@@ -159,4 +151,14 @@ public void changePassword(@NonNull String userId, @NonNull PasswordChange passw
159151
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
160152
}
161153

154+
@Override
155+
public void searchConnections(@NonNull String query, @Nullable Integer page, @Nullable UserSortMode sortMode, @Nullable ResponseCallback<CreatubblesResponse<List<User>>> callback) {
156+
Call<JSONAPIDocument<List<User>>> call = userService.getConnections(CURRENT_USER, query, page, getSortParam(sortMode));
157+
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
158+
}
159+
160+
private String getSortParam(UserSortMode sortMode) {
161+
return sortMode != null ? sortMode.getParam() : null;
162+
}
163+
162164
}

api/src/main/java/com/creatubbles/api/service/UserService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,24 @@ public interface UserService {
3232

3333
String PARAM_ID = "id";
3434
String PARAM_PAGE = "page";
35+
String PARAM_QUERY = "query";
36+
String PARAM_SORT = "sort";
3537
String PATH_ID = "{" + PARAM_ID + "}";
3638

3739
@GET(EndPoints.USERS + "/" + PATH_ID)
3840
Call<JSONAPIDocument<User>> getUserById(@Path(PARAM_ID) String id);
3941

4042
@GET(EndPoints.USERS + "/" + PATH_ID + "/creators")
41-
Call<JSONAPIDocument<List<User>>> getCreators(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
43+
Call<JSONAPIDocument<List<User>>> getCreators(@Path(PARAM_ID) String id, @Query(PARAM_QUERY) String query, @Query(PARAM_PAGE) Integer page, @Query(PARAM_SORT) String sort);
4244

4345
@GET(EndPoints.USERS + "/" + PATH_ID + "/managers")
44-
Call<JSONAPIDocument<List<User>>> getManagers(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
46+
Call<JSONAPIDocument<List<User>>> getManagers(@Path(PARAM_ID) String id, @Query(PARAM_QUERY) String query, @Query(PARAM_PAGE) Integer page, @Query(PARAM_SORT) String sort);
4547

4648
@GET(EndPoints.USERS + "/" + PATH_ID + "/connected_users")
47-
Call<JSONAPIDocument<List<User>>> getConnections(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
49+
Call<JSONAPIDocument<List<User>>> getConnections(@Path(PARAM_ID) String id, @Query(PARAM_QUERY) String query, @Query(PARAM_PAGE) Integer page, @Query(PARAM_SORT) String sort);
4850

4951
@GET(EndPoints.USERS + "/" + PATH_ID + "/followed_users")
50-
Call<JSONAPIDocument<List<User>>> getFollowedUsers(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
52+
Call<JSONAPIDocument<List<User>>> getFollowedUsers(@Path(PARAM_ID) String id, @Query(PARAM_QUERY) String query, @Query(PARAM_PAGE) Integer page, @Query(PARAM_SORT) String sort);
5153

5254
@POST(EndPoints.CREATORS)
5355
Call<JSONAPIDocument<User>> createUser(@Body NewUser newUser);

api/src/test/groovy/com/creatubbles/api/repository/UserRepositoryTest.groovy

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,56 +45,56 @@ class UserRepositoryTest extends Specification {
4545
when:
4646
repository.getCreators(anyPage(), anySortMode(), anyCallback())
4747
then:
48-
service.getCreators(currentUserId(), _, _) >> anyCall()
48+
service.getCreators(currentUserId(), _, _, _) >> anyCall()
4949
}
5050

5151
def "should call get creators with an id when obtaining any user's creators"() {
5252
when:
5353
repository.getCreators(anyId(), anyPage(), anySortMode(), anyCallback())
5454
then:
55-
service.getCreators(_, _, _) >> anyCall()
55+
service.getCreators(_, _, _, _) >> anyCall()
5656
}
5757

5858
def "should call get managers with specific user id when obtaining current user's managers"() {
5959
when:
6060
repository.getManagers(anyPage(), anySortMode(), anyCallback())
6161
then:
62-
service.getManagers(currentUserId(), _, _) >> anyCall()
62+
service.getManagers(currentUserId(), _, _, _) >> anyCall()
6363
}
6464

6565
def "should call get managers with an id when obtaining any user's managers"() {
6666
when:
6767
repository.getManagers(anyId(), anyPage(), anySortMode(), anyCallback())
6868
then:
69-
service.getManagers(_, _, _) >> anyCall()
69+
service.getManagers(_, _, _, _) >> anyCall()
7070
}
7171

7272
def "should call get followed users with specific id when obtaining current user's followed users"() {
7373
when:
7474
repository.getFollowedUsers(anyPage(), anySortMode(), anyCallback())
7575
then:
76-
service.getFollowedUsers(currentUserId(), _, _) >> anyCall()
76+
service.getFollowedUsers(currentUserId(), _, _, _) >> anyCall()
7777
}
7878

7979
def "should call get followed users with an id when obtaining any user's followed users"() {
8080
when:
8181
repository.getFollowedUsers(anyPage(), anySortMode(), anyCallback())
8282
then:
83-
service.getFollowedUsers(currentUserId(), _, _) >> anyCall()
83+
service.getFollowedUsers(currentUserId(), _, _, _) >> anyCall()
8484
}
8585

8686
def "should call get connections users with specific id when obtaining current user's connections"() {
8787
when:
8888
repository.getConnections(anyPage(), anySortMode(), anyCallback())
8989
then:
90-
service.getConnections(currentUserId(), _, _) >> anyCall()
90+
service.getConnections(currentUserId(), _, _, _) >> anyCall()
9191
}
9292

9393
def "should call get connections users with an id when obtaining any user's connections"() {
9494
when:
9595
repository.getConnections(anyPage(), anySortMode(), anyCallback())
9696
then:
97-
service.getConnections(currentUserId(), _, _) >> anyCall()
97+
service.getConnections(currentUserId(), _, _, _) >> anyCall()
9898
}
9999

100100
def "should call create user when creating user"() {
@@ -160,6 +160,13 @@ class UserRepositoryTest extends Specification {
160160
service.postPasswordChange(_, _) >> anyCall()
161161
}
162162

163+
def "should call get connections for current user when searching fo users"() {
164+
when:
165+
repository.searchConnections(anyQuery(), anyPage(), anySortMode(), anyCallback())
166+
then:
167+
service.getConnections(currentUserId(), _, _, _) >> anyCall()
168+
}
169+
163170
private UserSortMode anySortMode() {
164171
null
165172
}
@@ -184,4 +191,8 @@ class UserRepositoryTest extends Specification {
184191
private String anyId() {
185192
""
186193
}
194+
195+
private String anyQuery() {
196+
""
197+
}
187198
}

app/src/main/java/com/creatubbles/app/view/MainActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public class MainActivity extends AppCompatActivity {
117117
R.id.get_user_details_btn, R.id.get_avatar_suggestion, R.id.get_notifications_btn,
118118
R.id.update_last_viewed_time_btn, R.id.get_toyboo_details_btn, R.id.find_partner_applications,
119119
R.id.get_partner_app_by_id, R.id.get_content_btn, R.id.get_recent_content_btn, R.id.get_followed_content_btn,
120-
R.id.get_trending_content_btn, R.id.get_connected_content_btn, R.id.get_schools_btn})
120+
R.id.get_trending_content_btn, R.id.get_connected_content_btn, R.id.get_schools_btn, R.id.search_user_connections_btn})
121121
List<Button> actionButtons;
122122

123123
@Bind(R.id.send_file_btn)
@@ -294,6 +294,12 @@ public void onGetUserConnectionsClicked(View view) {
294294
getUserList((page, callback) -> userRepository.getConnections(page, null, callback));
295295
}
296296

297+
public void onSearchUserConnectionsClicked(View view) {
298+
UserRepository userRepository = new UserRepositoryBuilder(accessToken)
299+
.build();
300+
getUserList((page, callback) -> userRepository.searchConnections("test", page, null, callback));
301+
}
302+
297303
public void onGetUserFollowedClicked(View view) {
298304
UserRepository userRepository = new UserRepositoryBuilder(accessToken)
299305
.build();

app/src/main/res/layout/content_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@
137137
android:onClick="onGetUserConnectionsClicked"
138138
android:enabled="false"/>
139139

140+
<Button
141+
android:layout_width="wrap_content"
142+
android:layout_height="wrap_content"
143+
android:id="@+id/search_user_connections_btn"
144+
android:text="Search Connections"
145+
android:onClick="onSearchUserConnectionsClicked"
146+
android:enabled="false" />
147+
140148
<Button
141149
android:layout_width="wrap_content"
142150
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)