add getChecklist and deleteChecklist
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
acd7724353
commit
c22a8d78b4
@ -12,12 +12,12 @@ 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
|
||||
* @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<List<Checklist>> getChecklists(
|
||||
Call<List<Checklist>> getAllChecklists(
|
||||
@Path("boardId") String boardId,
|
||||
@Path("cardId") String cardId
|
||||
);
|
||||
@ -25,10 +25,10 @@ public interface ChecklistService {
|
||||
/**
|
||||
* 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
|
||||
* @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")
|
||||
@ -41,10 +41,10 @@ public interface ChecklistService {
|
||||
/**
|
||||
* 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
|
||||
* @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")
|
||||
@ -53,4 +53,34 @@ public interface ChecklistService {
|
||||
@Path("cardId") String cardId,
|
||||
@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
|
||||
);
|
||||
}
|
||||
|
@ -3,12 +3,14 @@ package wekan.wrapper.entity;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Checklist {
|
||||
@SerializedName("_id")
|
||||
private String id;
|
||||
private String cardId;
|
||||
private String title;
|
||||
private List<ChecklistItem> items;
|
||||
private Date finishedAt;
|
||||
private Date createdAt;
|
||||
private Date modifiedAt;
|
||||
@ -26,6 +28,10 @@ public class Checklist {
|
||||
return title;
|
||||
}
|
||||
|
||||
public List<ChecklistItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public Date getFinishedAt() {
|
||||
return finishedAt;
|
||||
}
|
||||
@ -48,6 +54,7 @@ public class Checklist {
|
||||
"id='" + id + '\'' +
|
||||
", cardId='" + cardId + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", items=" + items +
|
||||
", finishedAt=" + finishedAt +
|
||||
", createdAt=" + createdAt +
|
||||
", modifiedAt=" + modifiedAt +
|
||||
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,11 @@ public class ChecklistPrototype {
|
||||
items = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ChecklistPrototype.
|
||||
*
|
||||
* @return The ChecklistPrototype
|
||||
*/
|
||||
public ChecklistPrototype build() {
|
||||
return new ChecklistPrototype(
|
||||
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) {
|
||||
this.title = title;
|
||||
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) {
|
||||
items.add(item);
|
||||
return this;
|
||||
|
@ -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\"" +
|
||||
"}";
|
||||
}
|
Loading…
Reference in New Issue
Block a user