From 1cac40cf106fd1880392156104e2b535a758c32b Mon Sep 17 00:00:00 2001 From: noemi3 Date: Sat, 9 Nov 2019 19:22:16 +0100 Subject: [PATCH 1/2] added newList and getAllList --- .../java/wekan/wrapper/api/ListService.java | 17 +++++++++++++++++ .../main/java/wekan/wrapper/entity/WList.java | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 wrapper/src/main/java/wekan/wrapper/api/ListService.java create mode 100644 wrapper/src/main/java/wekan/wrapper/entity/WList.java diff --git a/wrapper/src/main/java/wekan/wrapper/api/ListService.java b/wrapper/src/main/java/wekan/wrapper/api/ListService.java new file mode 100644 index 0000000..ec51a67 --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/api/ListService.java @@ -0,0 +1,17 @@ +package wekan.wrapper.api; + +import retrofit2.Call; +import retrofit2.http.*; +import wekan.wrapper.entity.WList; + +import java.util.List; + + +public interface ListService { + @GET("/api/boards/{board}/lists") + Call> getAllList(@Path("board") String boardId); + + @POST("/api/boards/{board}/lists") + Call newList(@Path("board") String board, @Body String title); + +} diff --git a/wrapper/src/main/java/wekan/wrapper/entity/WList.java b/wrapper/src/main/java/wekan/wrapper/entity/WList.java new file mode 100644 index 0000000..7730125 --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/entity/WList.java @@ -0,0 +1,17 @@ +package wekan.wrapper.entity; + +import com.google.gson.annotations.SerializedName; + +public class WList { + @SerializedName("_id") + private String id; + private String title; + + @Override + public String toString() { + return "WList{" + + "id='" + id + '\'' + + ", title='" + title + '\'' + + '}'; + } +} -- 2.45.2 From ab91241aa6b149daab2fd9238333e6887e9cc0a8 Mon Sep 17 00:00:00 2001 From: noemi3 Date: Thu, 14 Nov 2019 11:47:53 +0100 Subject: [PATCH 2/2] added getList and deleteList --- .../java/wekan/wrapper/api/ListService.java | 39 ++++- .../main/java/wekan/wrapper/entity/WList.java | 74 +++++++++ .../java/wekan/wrapper/entity/WipLimit.java | 19 +++ .../wekan/wrapper/api/ListServiceTest.java | 148 ++++++++++++++++++ 4 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 wrapper/src/main/java/wekan/wrapper/entity/WipLimit.java create mode 100644 wrapper/src/test/java/wekan/wrapper/api/ListServiceTest.java diff --git a/wrapper/src/main/java/wekan/wrapper/api/ListService.java b/wrapper/src/main/java/wekan/wrapper/api/ListService.java index ec51a67..c23ea8e 100644 --- a/wrapper/src/main/java/wekan/wrapper/api/ListService.java +++ b/wrapper/src/main/java/wekan/wrapper/api/ListService.java @@ -8,10 +8,47 @@ import java.util.List; public interface ListService { + + /** + * Get the list of Lists attached to a board + * + * @param boardId the ID of the board + * @return the list of all lists + */ @GET("/api/boards/{board}/lists") Call> getAllList(@Path("board") String boardId); + /** + * Add a List to a board + * + * @param boardId the ID of the string + * @param title title of the new list + * @return the new list + */ + @FormUrlEncoded @POST("/api/boards/{board}/lists") - Call newList(@Path("board") String board, @Body String title); + Call newList( + @Path("board") String boardId, + @Field("title") String title + ); + + /** + * Get a List attached to a board + * @param boardId the ID of the board + * @param listId the ID of the list + * @return the list + */ + @GET("/api/boards/{board}/lists/{list}") + Call getList(@Path("board") String boardId, @Path("list") String listId); + + /** + * Delete a List + * @param boardId the ID of the board + * @param listId the ID of the list + * @return ID of the delete list + */ + @DELETE("/api/boards/{board}/lists/{list}") + Call deleteList (@Path("board") String boardId, @Path("list") String listId); + } diff --git a/wrapper/src/main/java/wekan/wrapper/entity/WList.java b/wrapper/src/main/java/wekan/wrapper/entity/WList.java index 7730125..8790216 100644 --- a/wrapper/src/main/java/wekan/wrapper/entity/WList.java +++ b/wrapper/src/main/java/wekan/wrapper/entity/WList.java @@ -6,12 +6,86 @@ public class WList { @SerializedName("_id") private String id; private String title; + private Boolean starred; + private Boolean archived; + private String boardId; + private String swimlanedId; + private String createdAt; + private int sort; + private String updateAt; + private String modifiedAt; + private WipLimit wipLimit; + private Color color; + private String type; + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } + + public Boolean getStarred() { + return starred; + } + + public Boolean getArchived() { + return archived; + } + + public String getBoardId() { + return boardId; + } + + public String getSwimlanedId() { + return swimlanedId; + } + + public String getCreatedAt() { + return createdAt; + } + + public int getSort() { + return sort; + } + + public String getUpdateAt() { + return updateAt; + } + + public String getModifiedAt() { + return modifiedAt; + } + + public WipLimit getWipLimit() { + return wipLimit; + } + + public Color getColor() { + return color; + } + + public String getType() { + return type; + } @Override public String toString() { return "WList{" + "id='" + id + '\'' + ", title='" + title + '\'' + + ", starred=" + starred + + ", archived=" + archived + + ", boardId='" + boardId + '\'' + + ", swimlanedId='" + swimlanedId + '\'' + + ", createdAt='" + createdAt + '\'' + + ", sort=" + sort + + ", updateAt='" + updateAt + '\'' + + ", modifiedAt='" + modifiedAt + '\'' + + ", wipLimit=" + wipLimit + + ", color='" + color + '\'' + + ", type='" + type + '\'' + '}'; } } diff --git a/wrapper/src/main/java/wekan/wrapper/entity/WipLimit.java b/wrapper/src/main/java/wekan/wrapper/entity/WipLimit.java new file mode 100644 index 0000000..d2a21ff --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/entity/WipLimit.java @@ -0,0 +1,19 @@ +package wekan.wrapper.entity; + +class WipLimit { + private int value; + private boolean enable; + private boolean soft; + + public int getValue() { + return value; + } + + public boolean isEnable() { + return enable; + } + + public boolean isSoft() { + return soft; + } +} diff --git a/wrapper/src/test/java/wekan/wrapper/api/ListServiceTest.java b/wrapper/src/test/java/wekan/wrapper/api/ListServiceTest.java new file mode 100644 index 0000000..e75c85f --- /dev/null +++ b/wrapper/src/test/java/wekan/wrapper/api/ListServiceTest.java @@ -0,0 +1,148 @@ +package wekan.wrapper.api; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; +import wekan.wrapper.entity.*; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.List; + +import static org.junit.Assert.*; + +public class ListServiceTest { + private MockWebServer mockWebServer = new MockWebServer(); + private ListService service = null; + + @Before + public void setUp() { + try { + mockWebServer.start(); + service = new Retrofit.Builder() + .baseUrl(mockWebServer.url("/")) + .addConverterFactory(GsonConverterFactory.create()) + .build() + .create(ListService.class); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @After + public void teardown() { + try { + mockWebServer.shutdown(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void getAllList() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody( + "[ " + WLIST_1 + ", " + WLIST_2 + " ]" + ); + + mockWebServer.enqueue(response); + + try { + List lists = service.getAllList("boardId") + .execute().body(); + + assertNotNull(lists); + assertEquals(2, lists.size()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void getList() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody(WLIST_1); + + mockWebServer.enqueue(response); + + try { + WList list = service.getList("boardId", "listId") + .execute().body(); + + assertNotNull(list); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void newList() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody(WLIST_2); + + mockWebServer.enqueue(response); + + try { + WList list = service.newList("boardId", "body") + .execute().body(); + + assertNotNull(list); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void deleteList() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody("{ \"_id\": \"list id\" }"); + + mockWebServer.enqueue(response); + + try { + WList list = service.deleteList("boardId", "listId") + .execute().body(); + + assertNotNull(list); + + + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static final String WLIST_1 = "{\"_id\":\"j3gzdbCJQYGnzuLhu\"," + + "\"title\":\"list 1\"," + + "\"boardId\":\"9QttSbCKjJ8v7zB3g\"," + + "\"sort\":1," + + "\"type\":\"list\"," + + "\"starred\":false," + + "\"archived\":false," + + "\"swimlaneId\":\"\"," + + "\"createdAt\":\"2019-11-14T10:34:14.120Z\"," + + "\"updatedAt\":\"2019-11-14T10:34:14.120Z\"," + + "\"modifiedAt\":\"2019-11-14T10:34:14.666Z\"," + + "\"wipLimit\":{\"value\":1,\"enabled\":false,\"soft\":false}" + + "}"; + private static final String WLIST_2 = "{\"_id\":\"j3gzdbCJQYGnzuLhu\"," + + "\"title\":\"list 2\"," + + "\"boardId\":\"9QttSbCKjJ8v7zB3d\"," + + "\"sort\":1," + + "\"type\":\"list\"," + + "\"starred\":false," + + "\"archived\":false," + + "\"swimlaneId\":\"\"," + + "\"createdAt\":\"2019-11-14T10:34:14.120Z\"," + + "\"updatedAt\":\"2019-11-14T10:34:14.120Z\"," + + "\"modifiedAt\":\"2019-11-14T10:34:14.666Z\"," + + "\"wipLimit\":{\"value\":1,\"enabled\":false,\"soft\":false}" + + "}"; +} \ No newline at end of file -- 2.45.2