Skip to content

Commit 399f9ce

Browse files
author
Pawel Szymanski
committed
Implement search for galleries
1 parent 9360890 commit 399f9ce

6 files changed

Lines changed: 56 additions & 5 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/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/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
}

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

Lines changed: 24 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, R.id.search_user_connections_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)
@@ -690,6 +691,28 @@ public void onError(String message) {
690691
});
691692
}
692693

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+
693716
public void onGetAllLandingUrlsClicked(View view) {
694717
LandingUrlsRepository repository = new LandingUrlsRepositoryBuilder(accessToken)
695718
.build();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@
240240
android:onClick="onGetGalleriesByIdClicked"
241241
android:enabled="false"/>
242242

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" />
243250

244251
<Button
245252
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)