Skip to content

Commit f71ad0d

Browse files
authored
Merge pull request #53 from creatubbles/feature/search_connections
Implement querying for users and galleries
2 parents d49dac7 + 399f9ce commit f71ad0d

10 files changed

Lines changed: 118 additions & 33 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public interface GalleryRepository {
1919

2020
void getPublic(@Nullable Integer page, @Nullable GallerySortMode sort, @Nullable ResponseCallback<CreatubblesResponse<List<Gallery>>> callback);
2121

22+
void searchPublic(@NonNull String query, @Nullable Integer page, @Nullable GallerySortMode sort, @Nullable ResponseCallback<CreatubblesResponse<List<Gallery>>> callback);
23+
2224
/**
2325
* Get current user’s favorite galleries.
2426
*/

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ class GalleryRepositoryImpl implements GalleryRepository {
3636
public void getPublic(@Nullable Integer page, @Nullable GallerySortMode sort,
3737
ResponseCallback<CreatubblesResponse<List<Gallery>>> callback) {
3838
String sortParam = sort != null ? sort.toString() : null;
39-
Call<JSONAPIDocument<List<Gallery>>> call = galleryService.getPublic(page, sortParam);
39+
Call<JSONAPIDocument<List<Gallery>>> call = galleryService.getPublic(null, page, sortParam);
40+
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
41+
}
42+
43+
@Override
44+
public void searchPublic(@NonNull String query, @Nullable Integer page, @Nullable GallerySortMode sort, @Nullable ResponseCallback<CreatubblesResponse<List<Gallery>>> callback) {
45+
String sortParam = sort != null ? sort.toString() : null;
46+
Call<JSONAPIDocument<List<Gallery>>> call = galleryService.getPublic(query, page, sortParam);
4047
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
4148
}
4249

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/GalleryService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ public interface GalleryService {
2626
String PARAM_PAGE = "page";
2727
String PARAM_SORT = "sort";
2828
String PARAM_FILTER = "filter";
29+
String PARAM_QUERY = "query";
2930

3031
@GET(EndPoints.GALLERIES)
31-
Call<JSONAPIDocument<List<Gallery>>> getPublic(@Query(PARAM_PAGE) Integer page,
32+
Call<JSONAPIDocument<List<Gallery>>> getPublic(@Query(PARAM_QUERY) String query,
33+
@Query(PARAM_PAGE) Integer page,
3234
@Query(PARAM_SORT) String sort);
3335

34-
3536
@GET(EndPoints.USERS + PATH_ID_GALLERIES)
3637
Call<JSONAPIDocument<List<Gallery>>> getByUser(@Path(PARAM_ID) String userId,
3738
@Query(PARAM_PAGE) Integer page,

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/GalleryRepositoryTest.groovy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ class GalleryRepositoryTest extends Specification {
2020
when:
2121
repository.getPublic(anyPage(), anySortMode(), anyCallback());
2222
then:
23-
service.getPublic(_, _) >> anyCall()
23+
service.getPublic(_, _, _) >> anyCall()
24+
}
25+
26+
def "should call get public when searching in public galleries"() {
27+
when:
28+
repository.searchPublic(anyQuery(), anyPage(), anySortMode(), anyCallback());
29+
then:
30+
service.getPublic(_, _, _) >> anyCall()
2431
}
2532

2633
def "should cal get favorite when obtaining favorite galleries"() {
@@ -113,4 +120,8 @@ class GalleryRepositoryTest extends Specification {
113120
private anyCall() {
114121
Mock(Call)
115122
}
123+
124+
private String anyQuery() {
125+
""
126+
}
116127
}

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: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ 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,
121+
R.id.search_galleries_btn})
121122
List<Button> actionButtons;
122123

123124
@Bind(R.id.send_file_btn)
@@ -294,6 +295,12 @@ public void onGetUserConnectionsClicked(View view) {
294295
getUserList((page, callback) -> userRepository.getConnections(page, null, callback));
295296
}
296297

298+
public void onSearchUserConnectionsClicked(View view) {
299+
UserRepository userRepository = new UserRepositoryBuilder(accessToken)
300+
.build();
301+
getUserList((page, callback) -> userRepository.searchConnections("test", page, null, callback));
302+
}
303+
297304
public void onGetUserFollowedClicked(View view) {
298305
UserRepository userRepository = new UserRepositoryBuilder(accessToken)
299306
.build();
@@ -684,6 +691,28 @@ public void onError(String message) {
684691
});
685692
}
686693

694+
public void onSearchGalleriesClicked(View view) {
695+
GalleryRepository galleryRepository = new GalleryRepositoryBuilder(accessToken)
696+
.build();
697+
698+
galleryRepository.searchPublic("test", null, null, new ResponseCallback<CreatubblesResponse<List<Gallery>>>() {
699+
@Override
700+
public void onSuccess(CreatubblesResponse<List<Gallery>> response) {
701+
Toast.makeText(MainActivity.this, "Galleries total count: " + response.getMeta().getTotalCount(),
702+
Toast.LENGTH_SHORT).show();
703+
}
704+
705+
@Override
706+
public void onServerError(ErrorResponse errorResponse) {
707+
displayError(errorResponse);
708+
}
709+
710+
@Override
711+
public void onError(String message) {
712+
}
713+
});
714+
}
715+
687716
public void onGetAllLandingUrlsClicked(View view) {
688717
LandingUrlsRepository repository = new LandingUrlsRepositoryBuilder(accessToken)
689718
.build();

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

Lines changed: 15 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"
@@ -232,6 +240,13 @@
232240
android:onClick="onGetGalleriesByIdClicked"
233241
android:enabled="false"/>
234242

243+
<Button
244+
android:layout_width="wrap_content"
245+
android:layout_height="wrap_content"
246+
android:id="@+id/search_galleries_btn"
247+
android:text="Search public galleries"
248+
android:onClick="onSearchGalleriesClicked"
249+
android:enabled="false" />
235250

236251
<Button
237252
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)