adds RenameAsync for tags

This commit is contained in:
Philipp Häfelfinger 2022-10-28 00:14:23 +02:00
parent d61ecf8d76
commit a36ac7442d
3 changed files with 38 additions and 1 deletions

View File

@ -93,4 +93,17 @@ public class TagApiTests : ApiTestsBase
await Verify(response);
}
[Test]
public async Task RenameAsync_should_pass_correct_parameters()
{
SetJsonResult(@"{""stat"":""ok"",""result"":{""id"":1,""name"":""tag1new"",""url_name"":""tag1new""}}");
await _tagApi.RenameAsync(1, "tag1new", ApiToken);
CorrectMethodShouldGetCalled("pwg.tags.rename");
CorrectParamShouldGetSent("tag_id", "1");
CorrectParamShouldGetSent("new_name", "tag1new");
CorrectParamShouldGetSent("pwg_token", ApiToken);
}
}

View File

@ -63,6 +63,18 @@ public interface ITagApi
/// <param name="cancellationToken">
/// <see cref="CancellationToken" />
/// </param>
/// <returns></returns>
/// <returns>Information about the merge result</returns>
Task<MergeResult> MergeAsync(int targetTagId, int sourceTagId, string apiToken, CancellationToken cancellationToken = default);
/// <summary>
/// renames a existing tag
/// </summary>
/// <param name="tagId">the tag id that gets renamed</param>
/// <param name="newName">the new name of the existing tag</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 RenameAsync(int tagId, string newName, string apiToken, CancellationToken cancellationToken = default);
}

View File

@ -76,4 +76,16 @@ public class TagApi : ITagApi
return response.Result;
}
public async Task RenameAsync(int tagId, string newName, string apiToken, CancellationToken cancellationToken = default)
{
var formParams = new Dictionary<string, string>
{
{ "tag_id", tagId.ToString() },
{ "new_name", newName },
{ "pwg_token", apiToken }
};
await _context.PostAsync<PiwigoResponse>(_logger, "pwg.tags.rename", formParams, cancellationToken);
}
}