add getChecklist and deleteChecklist
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Raffaele Mignone 2019-11-13 21:02:06 +01:00
parent acd7724353
commit c22a8d78b4
Signed by: norangebit
GPG Key ID: F5255658CB220573
5 changed files with 286 additions and 12 deletions

View File

@ -17,7 +17,7 @@ public interface ChecklistService {
* @return The list with the checklists * @return The list with the checklists
*/ */
@GET("/api/boards/{boardId}/cards/{cardId}/checklists") @GET("/api/boards/{boardId}/cards/{cardId}/checklists")
Call<List<Checklist>> getChecklists( Call<List<Checklist>> getAllChecklists(
@Path("boardId") String boardId, @Path("boardId") String boardId,
@Path("cardId") String cardId @Path("cardId") String cardId
); );
@ -53,4 +53,34 @@ public interface ChecklistService {
@Path("cardId") String cardId, @Path("cardId") String cardId,
@Body ChecklistPrototype checklistPrototype @Body ChecklistPrototype checklistPrototype
); );
/**
* Get the checklist attached on a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @return The checklist
*/
@GET("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}")
Call<Checklist> getChecklist(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId
);
/**
* Delete the checklist attached on a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @return The id of the checklist
*/
@DELETE("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}")
Call<Checklist> deleteChecklist(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId
);
} }

View File

@ -3,12 +3,14 @@ package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.Date; import java.util.Date;
import java.util.List;
public class Checklist { public class Checklist {
@SerializedName("_id") @SerializedName("_id")
private String id; private String id;
private String cardId; private String cardId;
private String title; private String title;
private List<ChecklistItem> items;
private Date finishedAt; private Date finishedAt;
private Date createdAt; private Date createdAt;
private Date modifiedAt; private Date modifiedAt;
@ -26,6 +28,10 @@ public class Checklist {
return title; return title;
} }
public List<ChecklistItem> getItems() {
return items;
}
public Date getFinishedAt() { public Date getFinishedAt() {
return finishedAt; return finishedAt;
} }
@ -48,6 +54,7 @@ public class Checklist {
"id='" + id + '\'' + "id='" + id + '\'' +
", cardId='" + cardId + '\'' + ", cardId='" + cardId + '\'' +
", title='" + title + '\'' + ", title='" + title + '\'' +
", items=" + items +
", finishedAt=" + finishedAt + ", finishedAt=" + finishedAt +
", createdAt=" + createdAt + ", createdAt=" + createdAt +
", modifiedAt=" + modifiedAt + ", modifiedAt=" + modifiedAt +

View File

@ -0,0 +1,32 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
public class ChecklistItem {
@SerializedName("_id")
private String id;
private String title;
private boolean isFinished;
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public boolean isFinished() {
return isFinished;
}
@Override
public String toString() {
return "ChecklistItem{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
", isFinished=" + isFinished +
'}';
}
}

View File

@ -20,6 +20,11 @@ public class ChecklistPrototype {
items = new ArrayList<>(); items = new ArrayList<>();
} }
/**
* Create a new ChecklistPrototype.
*
* @return The ChecklistPrototype
*/
public ChecklistPrototype build() { public ChecklistPrototype build() {
return new ChecklistPrototype( return new ChecklistPrototype(
title, title,
@ -27,11 +32,23 @@ public class ChecklistPrototype {
); );
} }
/**
* Set the title of the new checklist
*
* @param title The title of the new board
* @return The builder
*/
public Builder setTitle(String title) { public Builder setTitle(String title) {
this.title = title; this.title = title;
return this; return this;
} }
/**
* Add a new checklist item to the checklist
*
* @param item The item to add to the checklist
* @return The builder
*/
public Builder addItems(String item) { public Builder addItems(String item) {
items.add(item); items.add(item);
return this; return this;

View File

@ -0,0 +1,188 @@
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 ChecklistServiceTest {
private MockWebServer mockWebServer = new MockWebServer();
private ChecklistService service = null;
@Before
public void setUp() {
try {
mockWebServer.start();
service = new Retrofit.Builder()
.baseUrl(mockWebServer.url("/"))
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ChecklistService.class);
} catch (IOException e) {
e.printStackTrace();
}
}
@After
public void teardown() {
try {
mockWebServer.shutdown();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getAllChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"[ " + CHECKLIST_1 + ", " + CHECKLIST_2 + " ]"
);
mockWebServer.enqueue(response);
try {
List<Checklist> checklists = service.getAllChecklists(
"board id", "card id"
).
execute().body();
assertNotNull(checklists);
assertEquals(2, checklists.size());
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void postChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
CHECKLIST_2
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.postChecklist(
"board id",
"card id",
"title"
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void postChecklistChecklistPrototype() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
CHECKLIST_2
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.postChecklist(
"board id",
"card id",
new ChecklistPrototype.Builder()
.setTitle("title")
.addItems("item 1")
.addItems("item 2")
.build()
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
CHECKLIST_1
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.getChecklist(
"board id",
"card id",
"checklist id"
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void deleteChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"{ \"_id\": \"jdisfoSIkf0\" }"
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.deleteChecklist(
"board id",
"card id",
"checklist id"
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
private static final String CHECKLIST_1 = "{" +
"\"_id\":\"Tv6FuHLWaDR4Z3ig2\"," +
"\"title\":\"clist 1\"," +
"\"cardId\":\"bndtZCrJ9kshcFuw8\"," +
"\"sort\":0," +
"\"createdAt\":\"2019-11-13T18:22:59.987Z\"," +
"\"modifiedAt\":\"2019-11-13T19:34:48.650Z\"," +
"\"items\":[" +
"{\"_id\":\"9J8n6d6u3TkCAGvhw\",\"title\":\"item 1\",\"isFinished\":false}," +
"{\"_id\":\"iehKbi7qFruCyMRNQ\",\"title\":\"item 2\",\"isFinished\":false}" +
"]" +
"}";
private static final String CHECKLIST_2 = "{" +
"\"_id\":\"Tv6FuHLWaDR4Z3ig2\"," +
"\"title\":\"clist 1\"" +
"}";
}