Created
May 17, 2017 17:57
-
-
Save Augusent/e15de4707e6afd74810cdaacfee8b19e to your computer and use it in GitHub Desktop.
Repository Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
public final class UsersRepository { | |
private final Api api; | |
private final Prefs prefs; | |
private final Db db; | |
@Inject | |
public UsersRepository(Api api, Prefs prefs, Db db) { | |
this.api = api; | |
this.prefs = prefs; | |
this.db = db; | |
} | |
public Single<List<User>> getJoinedUsers(long gameId, int page) { | |
return api.fetchJoinedUsers(gameId, page).map(Users::get); | |
} | |
public Single<User> getMe() { | |
return api.fetchMe().map(UserResponse::getUser); | |
} | |
public Single<Users> getUsersForRate(long gameId, int page) { | |
return api.fetchUsersForRate(gameId, page); | |
} | |
public Single<User> updateProfile(Profile profile) { | |
return api.updateProfile(new UserBody(profile)).map(UserResponse::getUser); | |
} | |
public Completable updateLocation(Location location) { | |
return api.updateLocation(location.lat(), location.lng()).toCompletable(); | |
} | |
public Single<String> uploadPhoto(File uri) { | |
final MultipartBody.Part formData = MultipartBody.Part.createFormData("upload[source]", | |
uri.getName(), | |
RequestBody.create(MediaType.parse(MimeType.IMAGE_JPG), uri)); | |
return api.uploadPhoto(formData) | |
.map(UploadResponse::getUpload) | |
.map(Upload::getUrl) | |
.doOnSuccess(url -> Timber.v("Uploaded photo url: %s", url)); | |
} | |
public Single<User> getUser(long userId) { | |
return api.fetchUser(userId).map(UserResponse::getUser); | |
} | |
public Completable rateUser(long userId, long gameId, Map<String, Float> ratings) { | |
return api.rateUser(userId, new ReviewRequest(gameId, ratings)).toCompletable(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment