mirror of
https://github.com/sismics/docs.git
synced 2024-12-22 11:23:48 +01:00
Return tags on GET /document/list
This commit is contained in:
parent
0d7045bf24
commit
28fe7c8b02
@ -1,3 +1,3 @@
|
||||
- Users administration (client)
|
||||
- Tag color (client/server)
|
||||
- Display tags on documents list (client/server)
|
||||
- Display tags on documents list (client)
|
@ -122,6 +122,7 @@ public class DocumentResource extends BaseResource {
|
||||
List<JSONObject> documents = new ArrayList<JSONObject>();
|
||||
|
||||
DocumentDao documentDao = new DocumentDao();
|
||||
TagDao tagDao = new TagDao();
|
||||
PaginatedList<DocumentDto> paginatedList = PaginatedLists.create(limit, offset);
|
||||
SortCriteria sortCriteria = new SortCriteria(sortColumn, asc);
|
||||
DocumentCriteria documentCriteria = new DocumentCriteria();
|
||||
@ -140,6 +141,18 @@ public class DocumentResource extends BaseResource {
|
||||
document.put("title", documentDto.getTitle());
|
||||
document.put("description", documentDto.getDescription());
|
||||
document.put("create_date", documentDto.getCreateTimestamp());
|
||||
|
||||
// Get tags
|
||||
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId());
|
||||
List<JSONObject> tags = new ArrayList<JSONObject>();
|
||||
for (TagDto tagDto : tagDtoList) {
|
||||
JSONObject tag = new JSONObject();
|
||||
tag.put("id", tagDto.getId());
|
||||
tag.put("name", tagDto.getName());
|
||||
tags.add(tag);
|
||||
}
|
||||
document.put("tags", tags);
|
||||
|
||||
documents.add(document);
|
||||
}
|
||||
response.put("total", paginatedList.getResultCount());
|
||||
|
@ -69,8 +69,12 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
JSONArray documents = json.getJSONArray("documents");
|
||||
JSONArray tags = documents.getJSONObject(0).getJSONArray("tags");
|
||||
Assert.assertTrue(documents.length() == 1);
|
||||
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
|
||||
Assert.assertEquals(1, tags.length());
|
||||
Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id"));
|
||||
Assert.assertEquals("Super tag", tags.getJSONObject(0).getString("name"));
|
||||
|
||||
// Search documents by query
|
||||
documentResource = resource().path("/document/list");
|
||||
@ -128,7 +132,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
json = response.getEntity(JSONObject.class);
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
Assert.assertEquals(document1Id, json.getString("id"));
|
||||
JSONArray tags = json.getJSONArray("tags");
|
||||
tags = json.getJSONArray("tags");
|
||||
Assert.assertEquals(1, tags.length());
|
||||
Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id"));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user