adds merge and fixes test for duplicate
This commit is contained in:
parent
e68addbdaa
commit
d61ecf8d76
@ -56,7 +56,13 @@
|
||||
<None Update="TagApiTests.GetListAsync_should_return_all_tags.verified.txt">
|
||||
<DependentUpon>TagApiTests.cs</DependentUpon>
|
||||
</None>
|
||||
<None Update="TagApiTests.Duplicate_should_pass_correct_parameters.verified.txt">
|
||||
<None Update="TagApi.Merge.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="TagApiTests.MergeAsync_should_pass_correct_parameters.verified.txt">
|
||||
<DependentUpon>TagApiTests.cs</DependentUpon>
|
||||
</None>
|
||||
<None Update="TagApiTests.DuplicateAsync_should_pass_correct_parameters.verified.txt">
|
||||
<DependentUpon>TagApiTests.cs</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
13
src/Piwigo.Client.Tests/TagApi.Merge.json
Normal file
13
src/Piwigo.Client.Tests/TagApi.Merge.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"stat": "ok",
|
||||
"result": {
|
||||
"destination_tag": 1,
|
||||
"deleted_tag": [
|
||||
3
|
||||
],
|
||||
"images_in_merged_tag": [
|
||||
"4",
|
||||
"3"
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
destination_tag: 1,
|
||||
deleted_tag: [
|
||||
3
|
||||
],
|
||||
images_in_merged_tag: [
|
||||
4,
|
||||
3
|
||||
]
|
||||
}
|
@ -78,4 +78,19 @@ public class TagApiTests : ApiTestsBase
|
||||
|
||||
await Verify(response);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task MergeAsync_should_pass_correct_parameters()
|
||||
{
|
||||
await SetJsonResultFromFileAsync("TagApi.Merge.json");
|
||||
|
||||
var response = await _tagApi.MergeAsync(1, 4, ApiToken);
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.tags.merge");
|
||||
CorrectParamShouldGetSent("destination_tag_id", "1");
|
||||
CorrectParamShouldGetSent("merge_tag_id", "4");
|
||||
CorrectParamShouldGetSent("pwg_token", ApiToken);
|
||||
|
||||
await Verify(response);
|
||||
}
|
||||
}
|
@ -53,4 +53,16 @@ public interface ITagApi
|
||||
/// </param>
|
||||
/// <returns>all tags with at least one image assigned</returns>
|
||||
Task<IReadOnlyCollection<AssignedTag>> GetListAsync(bool? sortByCounter = null, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Merges two existing tags
|
||||
/// </summary>
|
||||
/// <param name="targetTagId">The tag where the images should get merged into</param>
|
||||
/// <param name="sourceTagId">The tag that will get obsolete</param>
|
||||
/// <param name="apiToken">The API token that can be read from <see cref="Piwigo.Client.Session.SessionStatus" /></param>
|
||||
/// <param name="cancellationToken">
|
||||
/// <see cref="CancellationToken" />
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
Task<MergeResult> MergeAsync(int targetTagId, int sourceTagId, string apiToken, CancellationToken cancellationToken = default);
|
||||
}
|
15
src/Piwigo.Client/Tags/MergeResult.cs
Normal file
15
src/Piwigo.Client/Tags/MergeResult.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Piwigo.Client.Tags;
|
||||
|
||||
public record MergeResult
|
||||
{
|
||||
[JsonProperty("destination_tag")]
|
||||
public int DestinationTagId { get; init; }
|
||||
|
||||
[JsonProperty("deleted_tag")]
|
||||
public IReadOnlyCollection<int>? DeletedTags { get; init; }
|
||||
|
||||
[JsonProperty("images_in_merged_tag")]
|
||||
public IReadOnlyCollection<int>? ImagesInMergedTag { get; init; }
|
||||
}
|
@ -62,4 +62,18 @@ public class TagApi : ITagApi
|
||||
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
public async Task<MergeResult> MergeAsync(int targetTagId, int sourceTagId, string apiToken, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var formParams = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination_tag_id", targetTagId.ToString() },
|
||||
{ "merge_tag_id", sourceTagId.ToString() },
|
||||
{ "pwg_token", apiToken }
|
||||
};
|
||||
|
||||
var response = await _context.PostAsync<PiwigoResponse<MergeResult>>(_logger, "pwg.tags.merge", formParams, cancellationToken);
|
||||
|
||||
return response.Result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user