From 7dd727a13d1d7ff3dff395ffecb627f55649b466 Mon Sep 17 00:00:00 2001 From: Yevheniy Oliynyk Date: Sat, 12 Oct 2024 17:09:19 +0200 Subject: [PATCH] feat: screenshots api updates --- .../crowdin/client/core/model/Pagination.java | 4 +- .../client/screenshots/ScreenshotsApi.java | 55 +++++++++++-------- .../model/AutoTagReplaceTagsRequest.java | 3 + .../model/ListScreenshotsParams.java | 16 ++++++ .../model/UpdateScreenshotRequest.java | 1 + 5 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/crowdin/client/screenshots/model/ListScreenshotsParams.java diff --git a/src/main/java/com/crowdin/client/core/model/Pagination.java b/src/main/java/com/crowdin/client/core/model/Pagination.java index 88793e85a..53b847f76 100644 --- a/src/main/java/com/crowdin/client/core/model/Pagination.java +++ b/src/main/java/com/crowdin/client/core/model/Pagination.java @@ -4,6 +4,6 @@ @Data public class Pagination { - private int offset; - private int limit; + private Integer offset; + private Integer limit; } diff --git a/src/main/java/com/crowdin/client/screenshots/ScreenshotsApi.java b/src/main/java/com/crowdin/client/screenshots/ScreenshotsApi.java index edd4c33a6..5fca63963 100644 --- a/src/main/java/com/crowdin/client/screenshots/ScreenshotsApi.java +++ b/src/main/java/com/crowdin/client/screenshots/ScreenshotsApi.java @@ -9,16 +9,7 @@ import com.crowdin.client.core.model.PatchRequest; import com.crowdin.client.core.model.ResponseList; import com.crowdin.client.core.model.ResponseObject; -import com.crowdin.client.screenshots.model.AddScreenshotRequest; -import com.crowdin.client.screenshots.model.AddTagRequest; -import com.crowdin.client.screenshots.model.ReplaceTagsRequest; -import com.crowdin.client.screenshots.model.Screenshot; -import com.crowdin.client.screenshots.model.ScreenshotResponseList; -import com.crowdin.client.screenshots.model.ScreenshotResponseObject; -import com.crowdin.client.screenshots.model.Tag; -import com.crowdin.client.screenshots.model.TagResponseList; -import com.crowdin.client.screenshots.model.TagResponseObject; -import com.crowdin.client.screenshots.model.UpdateScreenshotRequest; +import com.crowdin.client.screenshots.model.*; import java.util.List; import java.util.Map; @@ -46,13 +37,11 @@ public ScreenshotsApi(Credentials credentials, ClientConfig clientConfig) { */ @Deprecated public ResponseList listScreenshots(Long projectId, Long stringId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { - Map> queryParams = HttpRequestConfig.buildUrlParams( - "stringId", Optional.ofNullable(stringId), - "limit", Optional.ofNullable(limit), - "offset", Optional.ofNullable(offset) - ); - ScreenshotResponseList screenshotResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/screenshots", new HttpRequestConfig(queryParams), ScreenshotResponseList.class); - return ScreenshotResponseList.to(screenshotResponseList); + ListScreenshotsParams screenshotsParams = new ListScreenshotsParams(); + screenshotsParams.setStringIds(Optional.ofNullable(stringId).map(Object::toString).orElse(null)); + screenshotsParams.setLimit(limit); + screenshotsParams.setOffset(offset); + return this.listScreenshots(projectId, screenshotsParams); } /** @@ -69,12 +58,34 @@ public ResponseList listScreenshots(Long projectId, Long stringId, I * */ public ResponseList listScreenshots(Long projectId, List stringIds, List labelIds, List excludeLabelIds, Integer limit, Integer offset) throws HttpException, HttpBadRequestException { + ListScreenshotsParams screenshotsParams = new ListScreenshotsParams(); + screenshotsParams.setStringIds(Optional.ofNullable(stringIds).map(l -> String.join(",", l)).orElse(null)); + screenshotsParams.setLabelIds(Optional.ofNullable(labelIds).map(l -> String.join(",", l)).orElse(null)); + screenshotsParams.setExcludeLabelIds(Optional.ofNullable(excludeLabelIds).map(l -> String.join(",", l)).orElse(null)); + screenshotsParams.setLimit(limit); + screenshotsParams.setOffset(offset); + return this.listScreenshots(projectId, screenshotsParams); + } + + /** + * @param projectId project identifier + * @param params query params + * @return list of screenshots + * @see + */ + public ResponseList listScreenshots(Long projectId, ListScreenshotsParams params) throws HttpException, HttpBadRequestException { + ListScreenshotsParams query = Optional.ofNullable(params).orElse(new ListScreenshotsParams()); Map> queryParams = HttpRequestConfig.buildUrlParams( - "stringIds", Optional.ofNullable(stringIds), - "labelIds", Optional.ofNullable(labelIds), - "excludeLabelIds", Optional.ofNullable(excludeLabelIds), - "limit", Optional.ofNullable(limit), - "offset", Optional.ofNullable(offset) + "search", Optional.ofNullable(query.getSearch()), + "orderBy", Optional.ofNullable(query.getOrderBy()), + "stringIds", Optional.ofNullable(query.getStringIds()), + "labelIds", Optional.ofNullable(query.getLabelIds()), + "excludeLabelIds", Optional.ofNullable(query.getExcludeLabelIds()), + "limit", Optional.ofNullable(query.getLimit()), + "offset", Optional.ofNullable(query.getOffset()) ); ScreenshotResponseList screenshotResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/screenshots", new HttpRequestConfig(queryParams), ScreenshotResponseList.class); return ScreenshotResponseList.to(screenshotResponseList); diff --git a/src/main/java/com/crowdin/client/screenshots/model/AutoTagReplaceTagsRequest.java b/src/main/java/com/crowdin/client/screenshots/model/AutoTagReplaceTagsRequest.java index b80050996..54f3240d0 100644 --- a/src/main/java/com/crowdin/client/screenshots/model/AutoTagReplaceTagsRequest.java +++ b/src/main/java/com/crowdin/client/screenshots/model/AutoTagReplaceTagsRequest.java @@ -8,4 +8,7 @@ public class AutoTagReplaceTagsRequest extends ReplaceTagsRequest { private Boolean autoTag; + private Long fileId; + private Long branchId; + private Long directoryId; } diff --git a/src/main/java/com/crowdin/client/screenshots/model/ListScreenshotsParams.java b/src/main/java/com/crowdin/client/screenshots/model/ListScreenshotsParams.java new file mode 100644 index 000000000..a194f3f24 --- /dev/null +++ b/src/main/java/com/crowdin/client/screenshots/model/ListScreenshotsParams.java @@ -0,0 +1,16 @@ +package com.crowdin.client.screenshots.model; + +import com.crowdin.client.core.model.Pagination; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class ListScreenshotsParams extends Pagination { + + private String search; + private String orderBy; + private String stringIds; + private String labelIds; + private String excludeLabelIds; +} diff --git a/src/main/java/com/crowdin/client/screenshots/model/UpdateScreenshotRequest.java b/src/main/java/com/crowdin/client/screenshots/model/UpdateScreenshotRequest.java index 2a55d7005..542c23770 100644 --- a/src/main/java/com/crowdin/client/screenshots/model/UpdateScreenshotRequest.java +++ b/src/main/java/com/crowdin/client/screenshots/model/UpdateScreenshotRequest.java @@ -7,4 +7,5 @@ public class UpdateScreenshotRequest { private Long storageId; private String name; + private Boolean usePreviousTags; }