Add ChecklistService #14

Manually merged
UmbertoF merged 4 commits from feature_checklist into develop 2019-11-16 14:46:48 +00:00
4 changed files with 238 additions and 0 deletions
Showing only changes of commit 9ce3629bbc - Show all commits

View File

@ -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<ChecklistItem> 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<ChecklistItem> 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<ChecklistItem> 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<ChecklistItem> 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<ChecklistItem> editChecklistItem(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId,
@Path("itemId") String itemId,
@Body TestBody isFinished
);
}

View File

@ -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 +
'}';
}

View File

@ -0,0 +1,9 @@
package wekan.wrapper.entity;
public class TestBody {
private boolean isFinished;
public TestBody(boolean isFinished) {
this.isFinished = isFinished;
}
}

View File

@ -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\"" +
"}";
}