From 9ce3629bbc894a8dc68d031f520b2eed7a67ab80 Mon Sep 17 00:00:00 2001 From: norangebit Date: Thu, 14 Nov 2019 18:53:50 +0100 Subject: [PATCH] add checklist item - add class ChecklistItem - add API for checklist item --- .../wekan/wrapper/api/ChecklistService.java | 85 ++++++++++++++ .../wekan/wrapper/entity/ChecklistItem.java | 38 +++++++ .../java/wekan/wrapper/entity/TestBody.java | 9 ++ .../wrapper/api/ChecklistServiceTest.java | 106 ++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 wrapper/src/main/java/wekan/wrapper/entity/TestBody.java diff --git a/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java b/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java index 9e90d71..009044a 100644 --- a/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java +++ b/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java @@ -3,7 +3,9 @@ package wekan.wrapper.api; import retrofit2.Call; import retrofit2.http.*; import wekan.wrapper.entity.Checklist; +import wekan.wrapper.entity.ChecklistItem; import wekan.wrapper.entity.ChecklistPrototype; +import wekan.wrapper.entity.TestBody; import java.util.List; @@ -83,4 +85,87 @@ public interface ChecklistService { @Path("cardId") String cardId, @Path("checklistId") String checklistId ); + + /** + * Get the checklist item attached on a checklist. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @param checklistId The ID of the checklist + * @param itemId The ID of the item + * @return The checklist item + */ + @GET("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}") + Call getChecklistItem( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Path("checklistId") String checklistId, + @Path("itemId") String itemId + ); + + /** + * Change the title of the checklist item. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @param checklistId The ID of the checklist + * @param itemId The ID of the item + * @param title The new title + * @return The ID of the checklist item + */ + @FormUrlEncoded + @PUT("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}") + Call editChecklistItem( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Path("checklistId") String checklistId, + @Path("itemId") String itemId, + @Field("title") String title + ); + + /** + * Change the state of the checklist item. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @param checklistId The ID of the checklist + * @param itemId The ID of the item + * @param isFinished True if the item is done + * @return The ID of the checklist item + */ + @FormUrlEncoded + @PUT("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}") + Call editChecklistItem( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Path("checklistId") String checklistId, + @Path("itemId") String itemId, + @Field("isFinished") boolean isFinished + ); + + /** + * Delete a checklist item from the checklist. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @param checklistId The ID of the checklist + * @param itemId The ID of the item + * @return The ID of the checklist item + */ + @DELETE("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}") + Call deleteChecklistItem( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Path("checklistId") String checklistId, + @Path("itemId") String itemId + ); + + @PUT("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}") + Call editChecklistItem( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Path("checklistId") String checklistId, + @Path("itemId") String itemId, + @Body TestBody isFinished + ); } diff --git a/wrapper/src/main/java/wekan/wrapper/entity/ChecklistItem.java b/wrapper/src/main/java/wekan/wrapper/entity/ChecklistItem.java index af8ea97..bc43118 100644 --- a/wrapper/src/main/java/wekan/wrapper/entity/ChecklistItem.java +++ b/wrapper/src/main/java/wekan/wrapper/entity/ChecklistItem.java @@ -2,10 +2,18 @@ package wekan.wrapper.entity; import com.google.gson.annotations.SerializedName; +import java.util.Date; + public class ChecklistItem { @SerializedName("_id") private String id; private String title; + private String checklistId; + private String cardId; + private String userId; + private int sort; + private Date createdAt; + private Date modifiedAt; private boolean isFinished; public String getId() { @@ -16,6 +24,30 @@ public class ChecklistItem { return title; } + public String getChecklistId() { + return checklistId; + } + + public String getCardId() { + return cardId; + } + + public String getUserId() { + return userId; + } + + public int getSort() { + return sort; + } + + public Date getCreatedAt() { + return createdAt; + } + + public Date getModifiedAt() { + return modifiedAt; + } + public boolean isFinished() { return isFinished; } @@ -25,6 +57,12 @@ public class ChecklistItem { return "ChecklistItem{" + "id='" + id + '\'' + ", title='" + title + '\'' + + ", checklistId='" + checklistId + '\'' + + ", cardId='" + cardId + '\'' + + ", userId='" + userId + '\'' + + ", sort=" + sort + + ", createdAt=" + createdAt + + ", modifiedAt=" + modifiedAt + ", isFinished=" + isFinished + '}'; } diff --git a/wrapper/src/main/java/wekan/wrapper/entity/TestBody.java b/wrapper/src/main/java/wekan/wrapper/entity/TestBody.java new file mode 100644 index 0000000..c403f1c --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/entity/TestBody.java @@ -0,0 +1,9 @@ +package wekan.wrapper.entity; + +public class TestBody { + private boolean isFinished; + + public TestBody(boolean isFinished) { + this.isFinished = isFinished; + } +} diff --git a/wrapper/src/test/java/wekan/wrapper/api/ChecklistServiceTest.java b/wrapper/src/test/java/wekan/wrapper/api/ChecklistServiceTest.java index 5ec72e4..a6ee073 100644 --- a/wrapper/src/test/java/wekan/wrapper/api/ChecklistServiceTest.java +++ b/wrapper/src/test/java/wekan/wrapper/api/ChecklistServiceTest.java @@ -168,6 +168,100 @@ public class ChecklistServiceTest { } } + @Test + public void getChecklistItem() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody(ITEM); + + mockWebServer.enqueue(response); + + try { + ChecklistItem item = service.getChecklistItem( + "board id", + "card id", + "checklist id", + "item id" + ) + .execute().body(); + + assertNotNull(item); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void editChecklistItemTitle() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody("{ \"_id\": \"id\" }"); + + mockWebServer.enqueue(response); + + try { + ChecklistItem item = service.editChecklistItem( + "board id", + "card id", + "checklist id", + "item id", + "new title" + ) + .execute().body(); + + assertNotNull(item); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void editChecklistItemState() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody("{ \"_id\": \"id\" }"); + + mockWebServer.enqueue(response); + + try { + ChecklistItem item = service.editChecklistItem( + "board id", + "card id", + "checklist id", + "item id", + true + ) + .execute().body(); + + assertNotNull(item); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void deleteChecklistItem() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody("{ \"_id\": \"id\" }"); + + mockWebServer.enqueue(response); + + try { + ChecklistItem item = service.deleteChecklistItem( + "board id", + "card id", + "checklist id", + "item id" + ) + .execute().body(); + + assertNotNull(item); + } catch (IOException e) { + e.printStackTrace(); + } + } + private static final String CHECKLIST_1 = "{" + "\"_id\":\"Tv6FuHLWaDR4Z3ig2\"," + "\"title\":\"clist 1\"," + @@ -185,4 +279,16 @@ public class ChecklistServiceTest { "\"_id\":\"Tv6FuHLWaDR4Z3ig2\"," + "\"title\":\"clist 1\"" + "}"; + + private static final String ITEM = "{" + + "\"_id\":\"3HhzyoYBYGSr4mLdY\"," + + "\"title\":\"cosa da fare 1\"," + + "\"checklistId\":\"LyE7odMhtqZrgrXL9\"," + + "\"cardId\":\"bndtZCrJ9kshcFuw8\"," + + "\"sort\":0," + + "\"isFinished\":true," + + "\"createdAt\":\"2019-11-14T16:12:46.672Z\"," + + "\"modifiedAt\":\"2019-11-14T16:17:16.159Z\"," + + "\"userId\":\"Si69gNgkJfQuk6uiJ\"" + + "}"; }