Skip to content

Commit

Permalink
Merge pull request #92 from kptfh/feature/create-tags
Browse files Browse the repository at this point in the history
fixes #87
  • Loading branch information
andrii-bodnar authored Aug 1, 2022
2 parents 1fe2855 + 47b517c commit 3ebc854
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/crowdin/client/screenshots/ScreenshotsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class ScreenshotsApi extends CrowdinApi {
public ScreenshotsApi(Credentials credentials) {
Expand Down Expand Up @@ -127,11 +128,13 @@ public void replaceTags(Long projectId, Long screenshotId, ReplaceTagsRequest re
* @param projectId project identifier
* @param screenshotId screenshot identifier
* @param request request object
* @return newly created tag
* @return newly created tags
*/
public ResponseObject<Tag> addTag(Long projectId, Long screenshotId, List<AddTagRequest> request) throws HttpException, HttpBadRequestException {
TagResponseObject tagResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", request, new HttpRequestConfig(), TagResponseObject.class);
return ResponseObject.of(tagResponseObject.getData());
public ResponseObject<List<Tag>> addTag(Long projectId, Long screenshotId, List<AddTagRequest> request) throws HttpException, HttpBadRequestException {
TagResponseList tagResponseList = this.httpClient.post(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", request, new HttpRequestConfig(), TagResponseList.class);
return ResponseObject.of(tagResponseList.getData().stream()
.map(TagResponseObject::getData)
.collect(Collectors.toList()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<RequestMock> getMocks() {
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId, HttpPatch.METHOD_NAME, "api/screenshots/editScreenshot.json", "api/screenshots/screenshot.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", HttpGet.METHOD_NAME, "api/screenshots/listTags.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", HttpPut.METHOD_NAME, "api/screenshots/replaceTag.json", (String) null),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", HttpPost.METHOD_NAME, "api/screenshots/addTagRequest.json", "api/screenshots/tag.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", HttpPost.METHOD_NAME, "api/screenshots/addTagRequest.json", "api/screenshots/tags.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags", HttpDelete.METHOD_NAME),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags/" + tagId, HttpGet.METHOD_NAME, "api/screenshots/tag.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/screenshots/" + screenshotId + "/tags/" + tagId, HttpDelete.METHOD_NAME),
Expand Down Expand Up @@ -115,7 +115,7 @@ public void replaceTagsTest() {
}

@Test
public void addTagTest() {
public void addTagsTest() {
AddTagRequest request = new AddTagRequest();
request.setStringId(stringId);
Position position = new Position();
Expand All @@ -124,8 +124,8 @@ public void addTagTest() {
position.setWidth(100);
position.setHeight(200);
request.setPosition(position);
ResponseObject<Tag> tagResponseObject = this.getScreenshotsApi().addTag(projectId, screenshotId, singletonList(request));
assertEquals(tagResponseObject.getData().getId(), tagId);
ResponseObject<List<Tag>> tagResponseObject = this.getScreenshotsApi().addTag(projectId, screenshotId, singletonList(request));
assertEquals(tagResponseObject.getData().get(0).getId(), tagId);
}

@Test
Expand Down
22 changes: 22 additions & 0 deletions src/test/resources/api/screenshots/tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": [
{
"data": {
"id": 98,
"screenshotId": 2,
"stringId": 12,
"position": {
"x": 474,
"y": 147,
"width": 490,
"height": 99
},
"createdAt": "2019-09-23T09:35:31+00:00"
}
}
],
"pagination": {
"offset": 0,
"limit": 1
}
}

0 comments on commit 3ebc854

Please sign in to comment.