Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface GalleryRepository {

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

void searchPublic(@NonNull String query, @Nullable Integer page, @Nullable GallerySortMode sort, @Nullable ResponseCallback<CreatubblesResponse<List<Gallery>>> callback);

/**
* Get current user’s favorite galleries.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ class GalleryRepositoryImpl implements GalleryRepository {
public void getPublic(@Nullable Integer page, @Nullable GallerySortMode sort,
ResponseCallback<CreatubblesResponse<List<Gallery>>> callback) {
String sortParam = sort != null ? sort.toString() : null;
Call<JSONAPIDocument<List<Gallery>>> call = galleryService.getPublic(page, sortParam);
Call<JSONAPIDocument<List<Gallery>>> call = galleryService.getPublic(null, page, sortParam);
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
}

@Override
public void searchPublic(@NonNull String query, @Nullable Integer page, @Nullable GallerySortMode sort, @Nullable ResponseCallback<CreatubblesResponse<List<Gallery>>> callback) {
String sortParam = sort != null ? sort.toString() : null;
Call<JSONAPIDocument<List<Gallery>>> call = galleryService.getPublic(query, page, sortParam);
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ public interface UserRepository {
* When changing manager's password you have to provide both new and current password.
*/
void changePassword(@NonNull String userId, @NonNull PasswordChange passwordChange, @Nullable ResponseCallback<CreatubblesResponse<User>> callback);

/**
* Method used to obtain current user's 'My Connections' filtered by {@code query} param.
*/
void searchConnections(@NonNull String query, @Nullable Integer page, @Nullable UserSortMode sortMode, @Nullable ResponseCallback<CreatubblesResponse<List<User>>> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,57 +50,49 @@ public void getUser(ResponseCallback<CreatubblesResponse<User>> callback) {

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

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

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

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

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

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

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

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

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

@Override
public void searchConnections(@NonNull String query, @Nullable Integer page, @Nullable UserSortMode sortMode, @Nullable ResponseCallback<CreatubblesResponse<List<User>>> callback) {
Call<JSONAPIDocument<List<User>>> call = userService.getConnections(CURRENT_USER, query, page, getSortParam(sortMode));
call.enqueue(new JsonApiResponseMapper<>(objectMapper, callback));
}

private String getSortParam(UserSortMode sortMode) {
return sortMode != null ? sortMode.getParam() : null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public interface GalleryService {
String PARAM_PAGE = "page";
String PARAM_SORT = "sort";
String PARAM_FILTER = "filter";
String PARAM_QUERY = "query";

@GET(EndPoints.GALLERIES)
Call<JSONAPIDocument<List<Gallery>>> getPublic(@Query(PARAM_PAGE) Integer page,
Call<JSONAPIDocument<List<Gallery>>> getPublic(@Query(PARAM_QUERY) String query,
@Query(PARAM_PAGE) Integer page,
@Query(PARAM_SORT) String sort);


@GET(EndPoints.USERS + PATH_ID_GALLERIES)
Call<JSONAPIDocument<List<Gallery>>> getByUser(@Path(PARAM_ID) String userId,
@Query(PARAM_PAGE) Integer page,
Expand Down
10 changes: 6 additions & 4 deletions api/src/main/java/com/creatubbles/api/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@ public interface UserService {

String PARAM_ID = "id";
String PARAM_PAGE = "page";
String PARAM_QUERY = "query";
String PARAM_SORT = "sort";
String PATH_ID = "{" + PARAM_ID + "}";

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

@GET(EndPoints.USERS + "/" + PATH_ID + "/creators")
Call<JSONAPIDocument<List<User>>> getCreators(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
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);

@GET(EndPoints.USERS + "/" + PATH_ID + "/managers")
Call<JSONAPIDocument<List<User>>> getManagers(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
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);

@GET(EndPoints.USERS + "/" + PATH_ID + "/connected_users")
Call<JSONAPIDocument<List<User>>> getConnections(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
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);

@GET(EndPoints.USERS + "/" + PATH_ID + "/followed_users")
Call<JSONAPIDocument<List<User>>> getFollowedUsers(@Path(PARAM_ID) String id, @Query(PARAM_PAGE) Integer page, @Query("sort") String sort);
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);

@POST(EndPoints.CREATORS)
Call<JSONAPIDocument<User>> createUser(@Body NewUser newUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ class GalleryRepositoryTest extends Specification {
when:
repository.getPublic(anyPage(), anySortMode(), anyCallback());
then:
service.getPublic(_, _) >> anyCall()
service.getPublic(_, _, _) >> anyCall()
}

def "should call get public when searching in public galleries"() {
when:
repository.searchPublic(anyQuery(), anyPage(), anySortMode(), anyCallback());
then:
service.getPublic(_, _, _) >> anyCall()
}

def "should cal get favorite when obtaining favorite galleries"() {
Expand Down Expand Up @@ -113,4 +120,8 @@ class GalleryRepositoryTest extends Specification {
private anyCall() {
Mock(Call)
}

private String anyQuery() {
""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,56 +45,56 @@ class UserRepositoryTest extends Specification {
when:
repository.getCreators(anyPage(), anySortMode(), anyCallback())
then:
service.getCreators(currentUserId(), _, _) >> anyCall()
service.getCreators(currentUserId(), _, _, _) >> anyCall()
}

def "should call get creators with an id when obtaining any user's creators"() {
when:
repository.getCreators(anyId(), anyPage(), anySortMode(), anyCallback())
then:
service.getCreators(_, _, _) >> anyCall()
service.getCreators(_, _, _, _) >> anyCall()
}

def "should call get managers with specific user id when obtaining current user's managers"() {
when:
repository.getManagers(anyPage(), anySortMode(), anyCallback())
then:
service.getManagers(currentUserId(), _, _) >> anyCall()
service.getManagers(currentUserId(), _, _, _) >> anyCall()
}

def "should call get managers with an id when obtaining any user's managers"() {
when:
repository.getManagers(anyId(), anyPage(), anySortMode(), anyCallback())
then:
service.getManagers(_, _, _) >> anyCall()
service.getManagers(_, _, _, _) >> anyCall()
}

def "should call get followed users with specific id when obtaining current user's followed users"() {
when:
repository.getFollowedUsers(anyPage(), anySortMode(), anyCallback())
then:
service.getFollowedUsers(currentUserId(), _, _) >> anyCall()
service.getFollowedUsers(currentUserId(), _, _, _) >> anyCall()
}

def "should call get followed users with an id when obtaining any user's followed users"() {
when:
repository.getFollowedUsers(anyPage(), anySortMode(), anyCallback())
then:
service.getFollowedUsers(currentUserId(), _, _) >> anyCall()
service.getFollowedUsers(currentUserId(), _, _, _) >> anyCall()
}

def "should call get connections users with specific id when obtaining current user's connections"() {
when:
repository.getConnections(anyPage(), anySortMode(), anyCallback())
then:
service.getConnections(currentUserId(), _, _) >> anyCall()
service.getConnections(currentUserId(), _, _, _) >> anyCall()
}

def "should call get connections users with an id when obtaining any user's connections"() {
when:
repository.getConnections(anyPage(), anySortMode(), anyCallback())
then:
service.getConnections(currentUserId(), _, _) >> anyCall()
service.getConnections(currentUserId(), _, _, _) >> anyCall()
}

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

def "should call get connections for current user when searching fo users"() {
when:
repository.searchConnections(anyQuery(), anyPage(), anySortMode(), anyCallback())
then:
service.getConnections(currentUserId(), _, _, _) >> anyCall()
}

private UserSortMode anySortMode() {
null
}
Expand All @@ -184,4 +191,8 @@ class UserRepositoryTest extends Specification {
private String anyId() {
""
}

private String anyQuery() {
""
}
}
31 changes: 30 additions & 1 deletion app/src/main/java/com/creatubbles/app/view/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public class MainActivity extends AppCompatActivity {
R.id.get_user_details_btn, R.id.get_avatar_suggestion, R.id.get_notifications_btn,
R.id.update_last_viewed_time_btn, R.id.get_toyboo_details_btn, R.id.find_partner_applications,
R.id.get_partner_app_by_id, R.id.get_content_btn, R.id.get_recent_content_btn, R.id.get_followed_content_btn,
R.id.get_trending_content_btn, R.id.get_connected_content_btn, R.id.get_schools_btn})
R.id.get_trending_content_btn, R.id.get_connected_content_btn, R.id.get_schools_btn, R.id.search_user_connections_btn,
R.id.search_galleries_btn})
List<Button> actionButtons;

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

public void onSearchUserConnectionsClicked(View view) {
UserRepository userRepository = new UserRepositoryBuilder(accessToken)
.build();
getUserList((page, callback) -> userRepository.searchConnections("test", page, null, callback));
}

public void onGetUserFollowedClicked(View view) {
UserRepository userRepository = new UserRepositoryBuilder(accessToken)
.build();
Expand Down Expand Up @@ -684,6 +691,28 @@ public void onError(String message) {
});
}

public void onSearchGalleriesClicked(View view) {
GalleryRepository galleryRepository = new GalleryRepositoryBuilder(accessToken)
.build();

galleryRepository.searchPublic("test", null, null, new ResponseCallback<CreatubblesResponse<List<Gallery>>>() {
@Override
public void onSuccess(CreatubblesResponse<List<Gallery>> response) {
Toast.makeText(MainActivity.this, "Galleries total count: " + response.getMeta().getTotalCount(),
Toast.LENGTH_SHORT).show();
}

@Override
public void onServerError(ErrorResponse errorResponse) {
displayError(errorResponse);
}

@Override
public void onError(String message) {
}
});
}

public void onGetAllLandingUrlsClicked(View view) {
LandingUrlsRepository repository = new LandingUrlsRepositoryBuilder(accessToken)
.build();
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
android:onClick="onGetUserConnectionsClicked"
android:enabled="false"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search_user_connections_btn"
android:text="Search Connections"
android:onClick="onSearchUserConnectionsClicked"
android:enabled="false" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -232,6 +240,13 @@
android:onClick="onGetGalleriesByIdClicked"
android:enabled="false"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search_galleries_btn"
android:text="Search public galleries"
android:onClick="onSearchGalleriesClicked"
android:enabled="false" />

<Button
android:layout_width="wrap_content"
Expand Down