From acd77243537b5bafdd39566ec461bd36a2fbfed9 Mon Sep 17 00:00:00 2001 From: norangebit Date: Wed, 13 Nov 2019 19:29:04 +0100 Subject: [PATCH] add getChecklists and postChecklist - add class Checklist - add class ChecklistPrototype --- .../wekan/wrapper/api/ChecklistService.java | 56 ++++++++++++++++++ .../java/wekan/wrapper/entity/Checklist.java | 57 +++++++++++++++++++ .../wrapper/entity/ChecklistPrototype.java | 40 +++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java create mode 100644 wrapper/src/main/java/wekan/wrapper/entity/Checklist.java create mode 100644 wrapper/src/main/java/wekan/wrapper/entity/ChecklistPrototype.java diff --git a/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java b/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java new file mode 100644 index 0000000..d04a514 --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/api/ChecklistService.java @@ -0,0 +1,56 @@ +package wekan.wrapper.api; + +import retrofit2.Call; +import retrofit2.http.*; +import wekan.wrapper.entity.Checklist; +import wekan.wrapper.entity.ChecklistPrototype; + +import java.util.List; + +public interface ChecklistService { + + /** + * Get all checklists attached on a card. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @return The list with the checklists + */ + @GET("/api/boards/{boardId}/cards/{cardId}/checklists") + Call> getChecklists( + @Path("boardId") String boardId, + @Path("cardId") String cardId + ); + + /** + * Attach new empty checklist to a card. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @param title The title of the new checklist + * @return The new checklist + */ + @FormUrlEncoded + @POST("/api/boards/{boardId}/cards/{cardId}/checklists") + Call postChecklist( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Field("title") String title + ); + + /** + * Attach new checklist to a card. + * + * @param boardId The ID of the board + * @param cardId The ID of the card + * @param checklistPrototype The prototype of the checklist + * @return The new checklist + * @see ChecklistPrototype + */ + @POST("/api/boards/{boardId}/cards/{cardId}/checklists") + Call postChecklist( + @Path("boardId") String boardId, + @Path("cardId") String cardId, + @Body ChecklistPrototype checklistPrototype + ); +} diff --git a/wrapper/src/main/java/wekan/wrapper/entity/Checklist.java b/wrapper/src/main/java/wekan/wrapper/entity/Checklist.java new file mode 100644 index 0000000..4e01f86 --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/entity/Checklist.java @@ -0,0 +1,57 @@ +package wekan.wrapper.entity; + +import com.google.gson.annotations.SerializedName; + +import java.util.Date; + +public class Checklist { + @SerializedName("_id") + private String id; + private String cardId; + private String title; + private Date finishedAt; + private Date createdAt; + private Date modifiedAt; + private int sort; + + public String getId() { + return id; + } + + public String getCardId() { + return cardId; + } + + public String getTitle() { + return title; + } + + public Date getFinishedAt() { + return finishedAt; + } + + public Date getCreatedAt() { + return createdAt; + } + + public Date getModifiedAt() { + return modifiedAt; + } + + public int getSort() { + return sort; + } + + @Override + public String toString() { + return "Checklist{" + + "id='" + id + '\'' + + ", cardId='" + cardId + '\'' + + ", title='" + title + '\'' + + ", finishedAt=" + finishedAt + + ", createdAt=" + createdAt + + ", modifiedAt=" + modifiedAt + + ", sort=" + sort + + '}'; + } +} diff --git a/wrapper/src/main/java/wekan/wrapper/entity/ChecklistPrototype.java b/wrapper/src/main/java/wekan/wrapper/entity/ChecklistPrototype.java new file mode 100644 index 0000000..07cb673 --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/entity/ChecklistPrototype.java @@ -0,0 +1,40 @@ +package wekan.wrapper.entity; + +import java.util.ArrayList; +import java.util.List; + +public class ChecklistPrototype { + private String title; + private List items; + + private ChecklistPrototype(String title, List items) { + this.title = title; + this.items = items; + } + + public static class Builder { + private String title; + private List items; + + public Builder() { + items = new ArrayList<>(); + } + + public ChecklistPrototype build() { + return new ChecklistPrototype( + title, + items + ); + } + + public Builder setTitle(String title) { + this.title = title; + return this; + } + + public Builder addItems(String item) { + items.add(item); + return this; + } + } +}