Skip to content

Commit

Permalink
feat: Add labelIds and excludeLabelIds params to StringTranslationsAP…
Browse files Browse the repository at this point in the history
…Is (#207)
  • Loading branch information
Riju-bak authored Oct 30, 2023
1 parent 9b494d7 commit 235aaf8
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ public StringTranslationsApiExecutor(ICrowdinApiClient apiClient, IJsonParser js
[PublicAPI]
public Task<ResponseList<TranslationApproval>> ListTranslationApprovals(
int projectId,
int? fileId = null, int? stringId = null,
int? fileId = null,
string? labelIds = null,
string? excludeLabelIds = null,
int? stringId = null,
string? languageId = null, int? translationId = null,
int limit = 25, int offset = 0)
{
return ListTranslationApprovals(projectId,
new TranslationApprovalsListParams(fileId, stringId, languageId, translationId, limit, offset));
new TranslationApprovalsListParams(fileId, labelIds, excludeLabelIds, stringId, languageId, translationId, limit, offset));
}

/// <summary>
Expand Down Expand Up @@ -294,10 +297,13 @@ private static string FormUrl_TranslationId(int projectId, int translationId)
[PublicAPI]
public Task<ResponseList<TranslationVote>> ListTranslationVotes(
int projectId, int? stringId = null, string? languageId = null,
int? translationId = null, int limit = 25, int offset = 0)
int? translationId = null,
string? labelIds = null,
string? excludeLabelIds = null,
int limit = 25, int offset = 0)
{
return ListTranslationVotes(projectId,
new TranslationVotesListParams(stringId, languageId, translationId, limit, offset));
new TranslationVotesListParams(stringId, languageId, translationId, labelIds, excludeLabelIds , limit, offset));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Crowdin.Api.StringTranslations
public class TranslationApprovalsListParams : IQueryParamsProvider
{
public int? FileId { get; set; }

public string? LabelIds { get; set; }

public string? ExcludeLabelIds { get; set; }

public int? StringId { get; set; }

Expand All @@ -29,13 +33,17 @@ public TranslationApprovalsListParams()

public TranslationApprovalsListParams(
int? fileId,
string? labelIds,
string? excludeLabelIds,
int? stringId,
string? languageId,
int? translationId,
int limit,
int offset)
{
FileId = fileId;
LabelIds = labelIds;
ExcludeLabelIds = excludeLabelIds;
StringId = stringId;
LanguageId = languageId;
TranslationId = translationId;
Expand All @@ -49,6 +57,8 @@ public IDictionary<string, string> ToQueryParams()
Utils.CreateQueryParamsFromPaging(Limit, Offset);

queryParams.AddParamIfPresent("fileId", FileId);
queryParams.AddParamIfPresent("labelIds", LabelIds);
queryParams.AddParamIfPresent("excludeLabelIds", ExcludeLabelIds);
queryParams.AddParamIfPresent("stringId", StringId);
queryParams.AddParamIfPresent("languageId", LanguageId);
queryParams.AddParamIfPresent("translationId", TranslationId);
Expand Down
10 changes: 10 additions & 0 deletions src/Crowdin.Api/StringTranslations/TranslationVotesListParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class TranslationVotesListParams : IQueryParamsProvider

public int? TranslationId { get; set; }

public string? LabelIds { get; set; }

public string? ExcludeLabelIds { get; set; }

public int Limit { get; set; } = 25;

public int Offset { get; set; }
Expand All @@ -29,11 +33,15 @@ public TranslationVotesListParams(
int? stringId,
string? languageId,
int? translationId,
string? labelIds,
string? excludeLabelIds,
int limit, int offset)
{
StringId = stringId;
LanguageId = languageId;
TranslationId = translationId;
LabelIds = labelIds;
ExcludeLabelIds = excludeLabelIds;
Limit = limit;
Offset = offset;
}
Expand All @@ -46,6 +54,8 @@ public IDictionary<string, string> ToQueryParams()
queryParams.AddParamIfPresent("stringId", StringId);
queryParams.AddParamIfPresent("languageId", LanguageId);
queryParams.AddParamIfPresent("translationId", TranslationId);
queryParams.AddParamIfPresent("labelIds", LabelIds);
queryParams.AddParamIfPresent("excludeLabelIds", ExcludeLabelIds);

return queryParams;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions tests/Crowdin.Api.Tests/Core/Resources/StringTranslations.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,72 @@
}
}</value>
</data>
<data name="ListTranslationsApproval_Response" xml:space="preserve">
<value>
{
"data": [
{
"data": {
"id": 190695,
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Doe",
"avatarUrl": ""
},
"translationId": 190695,
"stringId": 2345,
"languageId": "uk",
"createdAt": "2019-09-23T11:26:54+00:00"
}
},
{
"data": {
"id": 200695,
"user": {
"id": 20,
"username": "jane_doe",
"fullName": "Jane Doe",
"avatarUrl": ""
},
"translationId": 200695,
"stringId": 1234,
"languageId": "uk",
"createdAt": "2020-09-23T11:26:54+00:00"
}
}
],
"pagination": {
"offset": 0,
"limit": 25
}
}
</value>
</data>
<data name="ListTranslationVotes_Response" xml:space="preserve">
<value>
{
"data": [
{
"data": {
"id": 6643,
"user": {
"id": 19,
"username": "john_doe",
"fullName": "John Smith",
"avatarUrl": ""
},
"translationId": 19069345,
"votedAt": "2019-09-19T12:42:12+00:00",
"mark": "up"
}
}
],
"pagination": {
"offset": 0,
"limit": 25
}
}
</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,59 @@ public async Task TranslationAlignment()
Assert.Equal(2, alignment.Match);
Assert.Equal(2, alignment.Probability);
}

[Fact]
public async Task ListTranslationApprovals()
{
const int projectId = 1;
var url = $"/projects/{projectId}/approvals";

Mock<ICrowdinApiClient> mockClient = TestUtils.CreateMockClientWithDefaultParser();

var queryParams = TestUtils.CreateQueryParamsFromPaging();

mockClient
.Setup(client => client.SendGetRequest(url, queryParams))
.ReturnsAsync(new CrowdinApiResult
{
StatusCode = HttpStatusCode.OK,
JsonObject = JObject.Parse(Core.Resources.StringTranslations.ListTranslationsApproval_Response)
});

var executor = new StringTranslationsApiExecutor(mockClient.Object);
ResponseList<TranslationApproval> response = await executor.ListTranslationApprovals(projectId);
Assert.NotNull(response);
var data = response.Data[1];
Assert.Equal(200695, data.TranslationId);
Assert.Equal(1234, data.StringId);
Assert.IsType<User>(data.User);
}

[Fact]
public async Task ListTranslationVotes()
{
const int projectId = 1;
var url = $"/projects/{projectId}/votes";

Mock<ICrowdinApiClient> mockClient = TestUtils.CreateMockClientWithDefaultParser();

var queryParams = TestUtils.CreateQueryParamsFromPaging();

mockClient
.Setup(client => client.SendGetRequest(url, queryParams))
.ReturnsAsync(new CrowdinApiResult
{
StatusCode = HttpStatusCode.OK,
JsonObject = JObject.Parse(Core.Resources.StringTranslations.ListTranslationVotes_Response)
});

var executor = new StringTranslationsApiExecutor(mockClient.Object);
ResponseList<TranslationVote> response = await executor.ListTranslationVotes(projectId);
Assert.NotNull(response);
var data = response.Data[0];
Assert.Equal(19069345, data.TranslationId);
Assert.Equal(TranslationVoteMark.Up, data.Mark);
Assert.IsType<User>(data.User);
}
}
}

0 comments on commit 235aaf8

Please sign in to comment.