Delete model used with Nextcloud folder api calls (create, rename, delete). Use the local model instead or a map

This commit is contained in:
Shinokuni 2020-01-15 22:11:17 +01:00
parent aafec850bb
commit b0963bb9ec
4 changed files with 18 additions and 57 deletions

View File

@ -19,7 +19,6 @@ import com.readrops.readropslibrary.services.SyncType;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsAPI;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsSyncData;
import com.readrops.readropslibrary.services.nextcloudnews.NextNewsSyncResult;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import com.readrops.readropslibrary.utils.UnknownFormatException;
@ -209,14 +208,12 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
public Single<Long> addFolder(Folder folder) {
return Single.<Folder>create(emitter -> {
try {
int folderRemoteId = folder.getRemoteId() == null ? 0 : Integer.parseInt(folder.getRemoteId());
List<Folder> folders = api.createFolder(new NextNewsFolder(folderRemoteId, folder.getName()));
List<Folder> folders = api.createFolder(folder);
if (folders != null) {
Folder nextNewsFolder = folders.get(0); // always only one item returned by the server, see doc
folder.setRemoteId(nextNewsFolder.getRemoteId());
folder.setName(nextNewsFolder.getName());
folder.setRemoteId(String.valueOf(nextNewsFolder.getId()));
emitter.onSuccess(folder);
} else
emitter.onError(new Exception("Unknown error"));
@ -230,7 +227,7 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
public Completable updateFolder(Folder folder) {
return Completable.create(emitter -> {
try {
if (api.renameFolder(new NextNewsFolder(Integer.parseInt(folder.getRemoteId()), folder.getName()))) {
if (api.renameFolder(folder)) {
emitter.onComplete();
} else
emitter.onError(new Exception("Unknown error"));
@ -247,7 +244,7 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
public Completable deleteFolder(Folder folder) {
return Completable.create(emitter -> {
try {
if (api.deleteFolder(new NextNewsFolder(Integer.parseInt(folder.getRemoteId()), folder.getName()))) {
if (api.deleteFolder(folder)) {
emitter.onComplete();
} else
emitter.onError(new Exception("Unknown error"));

View File

@ -14,7 +14,6 @@ import com.readrops.readropslibrary.services.SyncType;
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFeedsAdapter;
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsFoldersAdapter;
import com.readrops.readropslibrary.services.nextcloudnews.adapters.NextNewsItemsAdapter;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import com.readrops.readropslibrary.utils.ConflictException;
import com.readrops.readropslibrary.utils.LibUtils;
@ -160,8 +159,11 @@ public class NextNewsAPI extends API<NextNewsService> {
}
}
public List<Folder> createFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException {
Response<List<Folder>> foldersResponse = api.createFolder(folder).execute();
public List<Folder> createFolder(Folder folder) throws IOException, UnknownFormatException, ConflictException {
Map<String, String> folderNameMap = new HashMap<>();
folderNameMap.put("name", folder.getName());
Response<List<Folder>> foldersResponse = api.createFolder(folderNameMap).execute();
if (foldersResponse.isSuccessful())
return foldersResponse.body();
@ -173,8 +175,8 @@ public class NextNewsAPI extends API<NextNewsService> {
return new ArrayList<>();
}
public boolean deleteFolder(NextNewsFolder folder) throws IOException {
Response response = api.deleteFolder(folder.getId()).execute();
public boolean deleteFolder(Folder folder) throws IOException {
Response response = api.deleteFolder(Integer.parseInt(folder.getRemoteId())).execute();
if (response.isSuccessful())
return true;
@ -184,8 +186,11 @@ public class NextNewsAPI extends API<NextNewsService> {
return false;
}
public boolean renameFolder(NextNewsFolder folder) throws IOException, UnknownFormatException, ConflictException {
Response response = api.renameFolder(folder.getId(), folder).execute();
public boolean renameFolder(Folder folder) throws IOException, UnknownFormatException, ConflictException {
Map<String, String> folderNameMap = new HashMap<>();
folderNameMap.put("name", folder.getName());
Response response = api.renameFolder(Integer.parseInt(folder.getRemoteId()), folderNameMap).execute();
if (response.isSuccessful())
return true;

View File

@ -3,7 +3,6 @@ package com.readrops.readropslibrary.services.nextcloudnews;
import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsFolder;
import com.readrops.readropslibrary.services.nextcloudnews.json.NextNewsUser;
import java.util.List;
@ -54,11 +53,11 @@ public interface NextNewsService {
Call<ResponseBody> renameFeed(@Path("feedId") int feedId, @Body Map<String, String> feedTitleMap);
@POST("folders")
Call<List<Folder>> createFolder(@Body NextNewsFolder folder);
Call<List<Folder>> createFolder(@Body Map<String, String> folderName);
@DELETE("folders/{folderId}")
Call<ResponseBody> deleteFolder(@Path("folderId") int folderId);
@PUT("folders/{folderId}")
Call<ResponseBody> renameFolder(@Path("folderId") int folderId, @Body NextNewsFolder folder);
Call<ResponseBody> renameFolder(@Path("folderId") int folderId, @Body Map<String, String> folderName);
}

View File

@ -1,40 +0,0 @@
package com.readrops.readropslibrary.services.nextcloudnews.json;
import com.google.gson.annotations.SerializedName;
public class NextNewsFolder {
@SerializedName("id")
private int id;
@SerializedName("name")
private String name;
public NextNewsFolder() {
}
public NextNewsFolder(int id, String name) {
this.id = id;
this.name = name;
}
public NextNewsFolder(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}