Skip to content

Commit

Permalink
refactor: Use Call<EmptyResponse> in favor of Call<Void> because the …
Browse files Browse the repository at this point in the history
…latter will be removed in the next SSO version

Refs: nextcloud/Android-SingleSignOn#636

Signed-off-by: Stefan Niedermann <[email protected]>
  • Loading branch information
stefan-niedermann committed Jan 23, 2024
1 parent efe798e commit 148b13a
Show file tree
Hide file tree
Showing 38 changed files with 145 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;

import com.nextcloud.android.sso.api.EmptyResponse;
import com.nextcloud.android.sso.model.SingleSignOnAccount;

import java.io.File;
Expand Down Expand Up @@ -132,7 +133,7 @@ public void createBoard(Board board, @NonNull ResponseCallback<FullBoard> respon
this.requestHelper.request(() -> provider.getDeckAPI().createBoard(board), responseCallback);
}

public void deleteBoard(Board board, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteBoard(Board board, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().deleteBoard(board.getId()), responseCallback);
}

Expand All @@ -148,7 +149,7 @@ public void updateAccessControl(long remoteBoardId, AccessControl acl, @NonNull
this.requestHelper.request(() -> provider.getDeckAPI().updateAccessControl(remoteBoardId, acl.getId(), acl), responseCallback);
}

public void deleteAccessControl(long remoteBoardId, AccessControl acl, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteAccessControl(long remoteBoardId, AccessControl acl, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().deleteAccessControl(remoteBoardId, acl.getId(), acl), responseCallback);
}

Expand All @@ -164,7 +165,7 @@ public void createStack(Board board, Stack stack, @NonNull ResponseCallback<Full
this.requestHelper.request(() -> provider.getDeckAPI().createStack(board.getId(), stack), responseCallback);
}

public void deleteStack(Board board, Stack stack, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteStack(Board board, Stack stack, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().deleteStack(board.getId(), stack.getId()), responseCallback);

}
Expand All @@ -188,27 +189,27 @@ public void createCard(long boardId, long stackId, Card card, @NonNull ResponseC
this.requestHelper.request(() -> provider.getDeckAPI().createCard(boardId, stackId, card), responseCallback);
}

public void deleteCard(long boardId, long stackId, Card card, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteCard(long boardId, long stackId, Card card, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().deleteCard(boardId, stackId, card.getId()), responseCallback);
}

public void updateCard(long boardId, long stackId, CardUpdate card, @NonNull ResponseCallback<FullCard> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().updateCard(boardId, stackId, card.getId(), card), responseCallback);
}

public void assignUserToCard(long boardId, long stackId, long cardId, String userUID, @NonNull ResponseCallback<Void> responseCallback) {
public void assignUserToCard(long boardId, long stackId, long cardId, String userUID, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().assignUserToCard(boardId, stackId, cardId, userUID), responseCallback);
}

public void unassignUserFromCard(long boardId, long stackId, long cardId, String userUID, @NonNull ResponseCallback<Void> responseCallback) {
public void unassignUserFromCard(long boardId, long stackId, long cardId, String userUID, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().unassignUserFromCard(boardId, stackId, cardId, userUID), responseCallback);
}

public void assignLabelToCard(long boardId, long stackId, long cardId, long labelId, @NonNull ResponseCallback<Void> responseCallback) {
public void assignLabelToCard(long boardId, long stackId, long cardId, long labelId, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().assignLabelToCard(boardId, stackId, cardId, labelId), responseCallback);
}

public void unassignLabelFromCard(long boardId, long stackId, long cardId, long labelId, @NonNull ResponseCallback<Void> responseCallback) {
public void unassignLabelFromCard(long boardId, long stackId, long cardId, long labelId, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().unassignLabelFromCard(boardId, stackId, cardId, labelId), responseCallback);
}

Expand All @@ -219,7 +220,7 @@ public void createLabel(long boardId, Label label, @NonNull ResponseCallback<Lab
this.requestHelper.request(() -> provider.getDeckAPI().createLabel(boardId, label), responseCallback);
}

public void deleteLabel(long boardId, Label label, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteLabel(long boardId, Label label, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().deleteLabel(boardId, label.getId()), responseCallback);
}

Expand Down Expand Up @@ -272,7 +273,7 @@ public void downloadAttachment(Long remoteBoardId, long remoteStackId, long remo
this.requestHelper.request(() -> provider.getDeckAPI().downloadAttachment(remoteBoardId, remoteStackId, remoteCardId, remoteAttachmentId), responseCallback);
}

public void deleteAttachment(Long remoteBoardId, long remoteStackId, long remoteCardId, @NonNull Attachment attachment, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteAttachment(Long remoteBoardId, long remoteStackId, long remoteCardId, @NonNull Attachment attachment, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().deleteAttachment(attachment.getType().getValue(), remoteBoardId, remoteStackId, remoteCardId, attachment.getId()), responseCallback);
}

Expand All @@ -292,7 +293,7 @@ public void updateCommentForCard(DeckComment comment, @NonNull ResponseCallback<
this.requestHelper.request(() -> provider.getNextcloudAPI().updateCommentForCard(comment.getObjectId(), comment.getId(), comment), responseCallback);
}

public void deleteCommentForCard(DeckComment comment, @NonNull ResponseCallback<Void> responseCallback) {
public void deleteCommentForCard(DeckComment comment, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getNextcloudAPI().deleteCommentForCard(comment.getObjectId(), comment.getId()), responseCallback);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.niedermann.nextcloud.deck.remote.api;


import com.nextcloud.android.sso.api.EmptyResponse;

import java.util.List;

import it.niedermann.nextcloud.deck.model.AccessControl;
Expand Down Expand Up @@ -52,7 +54,7 @@ public interface DeckAPI {
Call<FullBoard> updateBoard(@Path("id") long id, @Body Board board);

@DELETE("v1.0/boards/{id}")
Call<Void> deleteBoard(@Path("id") long id);
Call<EmptyResponse> deleteBoard(@Path("id") long id);

@DELETE("v1.0/boards/{id}/undo_delete")
Call<FullBoard> restoreBoard(@Path("id") long id);
Expand All @@ -73,7 +75,7 @@ public interface DeckAPI {
Call<FullStack> updateStack(@Path("boardId") long boardId, @Path("stackId") long id, @Body Stack stack);

@DELETE("v1.0/boards/{boardId}/stacks/{stackId}")
Call<Void> deleteStack(@Path("boardId") long boardId, @Path("stackId") long id);
Call<EmptyResponse> deleteStack(@Path("boardId") long boardId, @Path("stackId") long id);

@GET("v1.0/boards/{boardId}/stacks/{stackId}")
Call<FullStack> getStack(@Path("boardId") long boardId, @Path("stackId") long id, @Header(MODIFIED_SINCE_HEADER) String lastSync);
Expand All @@ -95,25 +97,25 @@ public interface DeckAPI {

@FormUrlEncoded
@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/assignLabel")
Call<Void> assignLabelToCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("labelId") long labelId);
Call<EmptyResponse> assignLabelToCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("labelId") long labelId);

@FormUrlEncoded
@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/removeLabel")
Call<Void> unassignLabelFromCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("labelId") long labelId);
Call<EmptyResponse> unassignLabelFromCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("labelId") long labelId);

@FormUrlEncoded
@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/assignUser")
Call<Void> assignUserToCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("userId") String userUID);
Call<EmptyResponse> assignUserToCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("userId") String userUID);

@FormUrlEncoded
@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/unassignUser")
Call<Void> unassignUserFromCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("userId") String userUID);
Call<EmptyResponse> unassignUserFromCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("userId") String userUID);

@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/reorder")
Call<List<FullCard>> moveCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body Reorder reorder);

@DELETE("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}")
Call<Void> deleteCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId);
Call<EmptyResponse> deleteCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId);

/**
* @see <a href="https://github.com/nextcloud/deck/issues/2874">This endpoint does only return {@link Attachment}s of type {@link EAttachmentType.DECK_FILE}</a>
Expand All @@ -138,7 +140,7 @@ public interface DeckAPI {
Call<Label> createLabel(@Path("boardId") long boardId, @Body Label label);

@DELETE("v1.0/boards/{boardId}/labels/{labelId}")
Call<Void> deleteLabel(@Path("boardId") long boardId, @Path("labelId") long labelId);
Call<EmptyResponse> deleteLabel(@Path("boardId") long boardId, @Path("labelId") long labelId);


// Attachments
Expand All @@ -158,7 +160,7 @@ public interface DeckAPI {
Call<Attachment> updateAttachment(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Path("attachmentId") long attachmentId, @Part MultipartBody.Part type, @Part MultipartBody.Part attachment);

@DELETE("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/attachments/{attachmentId}")
Call<Void> deleteAttachment(@Query("type") String type, @Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Path("attachmentId") long attachmentId);
Call<EmptyResponse> deleteAttachment(@Query("type") String type, @Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Path("attachmentId") long attachmentId);

@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/attachments/{attachmentId}/restore")
Call<Attachment> restoreAttachment(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Path("attachmentId") long attachmentId);
Expand All @@ -173,6 +175,6 @@ public interface DeckAPI {
Call<AccessControl> updateAccessControl(@Path("boardId") long boardId, @Path("aclId") long aclId, @Body AccessControl acl);

@DELETE("v1.0/boards/{boardId}/acl/{aclId}")
Call<Void> deleteAccessControl(@Path("boardId") long boardId, @Path("aclId") long aclId, @Body AccessControl acl);
Call<EmptyResponse> deleteAccessControl(@Path("boardId") long boardId, @Path("aclId") long aclId, @Body AccessControl acl);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.niedermann.nextcloud.deck.remote.api;


import com.nextcloud.android.sso.api.EmptyResponse;

import java.util.List;

import it.niedermann.nextcloud.deck.model.ocs.Activity;
Expand Down Expand Up @@ -87,5 +89,5 @@ public interface NextcloudServerAPI {
"Content-Type: application/json;charset=utf-8"
})
@DELETE("apps/deck/api/v1.0/cards/{cardId}/comments/{commentId}")
Call<Void> deleteCommentForCard(@Path("cardId") long cardId, @Path("commentId") long commentId);
Call<EmptyResponse> deleteCommentForCard(@Path("cardId") long cardId, @Path("commentId") long commentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.nextcloud.android.sso.api.EmptyResponse;

import java.util.concurrent.ExecutorService;
import java.util.function.BiConsumer;

Expand Down Expand Up @@ -109,7 +111,7 @@ public void onError(Throwable throwable) {
}
}

public <T extends IRemoteEntity> void deleteEntity(@NonNull final AbstractSyncDataProvider<T> provider, @NonNull T entity, @NonNull ResponseCallback<Void> callback){
public <T extends IRemoteEntity> void deleteEntity(@NonNull final AbstractSyncDataProvider<T> provider, @NonNull T entity, @NonNull ResponseCallback<EmptyResponse> callback){
final long accountId = callback.getAccount().getId();
// known to server?
if (entity.getId() != null) {
Expand All @@ -122,7 +124,7 @@ public <T extends IRemoteEntity> void deleteEntity(@NonNull final AbstractSyncDa
try {
provider.deleteOnServer(serverAdapter, accountId, new ResponseCallback<>(new Account(accountId)) {
@Override
public void onResponse(Void response) {
public void onResponse(EmptyResponse response) {
executor.submit(() -> {
provider.deletePhysicallyInDB(dataBaseAdapter, accountId, entity);
callback.onResponse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.nextcloud.android.sso.api.EmptyResponse;
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;

import java.net.HttpURLConnection;
Expand Down Expand Up @@ -176,10 +177,10 @@ public <T extends IRemoteEntity> void doUpSyncFor(@NonNull AbstractSyncDataProvi
}
}

private <T extends IRemoteEntity> ResponseCallback<Void> getDeleteCallback(@NonNull AbstractSyncDataProvider<T> provider, T entity) {
private <T extends IRemoteEntity> ResponseCallback<EmptyResponse> getDeleteCallback(@NonNull AbstractSyncDataProvider<T> provider, T entity) {
return new ResponseCallback<>(account) {
@Override
public void onResponse(Void response) {
public void onResponse(EmptyResponse response) {
provider.deletePhysicallyInDB(dataBaseAdapter, accountId, entity);
provider.goDeeperForUpSync(SyncHelper.this, serverAdapter, dataBaseAdapter, responseCallback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import androidx.annotation.Nullable;

import com.nextcloud.android.sso.api.EmptyResponse;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -106,7 +108,7 @@ public void goDeeper(SyncHelper syncHelper, T existingEntity, T entityFromServer

public abstract void updateOnServer(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, ResponseCallback<T> callback, T entity);

public abstract void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<Void> callback, T entity, DataBaseAdapter dataBaseAdapter);
public abstract void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<EmptyResponse> callback, T entity, DataBaseAdapter dataBaseAdapter);

public void childDone(AbstractSyncDataProvider<?> child, ResponseCallback<Boolean> responseCallback, boolean syncChangedSomething) {
removeChild(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import androidx.annotation.Nullable;

import com.nextcloud.android.sso.api.EmptyResponse;

import java.time.Instant;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -184,7 +186,7 @@ public void deletePhysicallyInDB(DataBaseAdapter dataBaseAdapter, long accountId
}

@Override
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<Void> callback, AccessControl entity, DataBaseAdapter dataBaseAdapter) {
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<EmptyResponse> callback, AccessControl entity, DataBaseAdapter dataBaseAdapter) {
serverAdapter.deleteAccessControl(board.getBoard().getId(), entity, callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import androidx.annotation.NonNull;

import com.nextcloud.android.sso.api.EmptyResponse;

import java.time.Instant;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -63,7 +65,7 @@ public void updateOnServer(ServerAdapter serverAdapter, DataBaseAdapter dataBase
}

@Override
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<Void> callback, Activity entity, DataBaseAdapter dataBaseAdapter) {
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<EmptyResponse> callback, Activity entity, DataBaseAdapter dataBaseAdapter) {
// nope.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.annotation.SuppressLint;
import android.net.Uri;

import com.nextcloud.android.sso.api.EmptyResponse;

import java.io.File;
import java.io.IOException;
import java.time.Instant;
Expand Down Expand Up @@ -117,7 +119,7 @@ public void updateOnServer(ServerAdapter serverAdapter, DataBaseAdapter dataBase
}

@Override
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<Void> callback, Attachment entity, DataBaseAdapter dataBaseAdapter) {
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<EmptyResponse> callback, Attachment entity, DataBaseAdapter dataBaseAdapter) {
serverAdapter.deleteAttachment(board.getId(), stack.getId(), card.getId(), entity, callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import androidx.lifecycle.MutableLiveData;

import com.nextcloud.android.sso.api.EmptyResponse;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -270,7 +272,7 @@ public void deletePhysicallyInDB(DataBaseAdapter dataBaseAdapter, long accountId
}

@Override
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<Void> callback, FullBoard entity, DataBaseAdapter dataBaseAdapter) {
public void deleteOnServer(ServerAdapter serverAdapter, long accountId, ResponseCallback<EmptyResponse> callback, FullBoard entity, DataBaseAdapter dataBaseAdapter) {
serverAdapter.deleteBoard(entity.getBoard(), callback);
}

Expand Down
Loading

0 comments on commit 148b13a

Please sign in to comment.