adds AddComment to images api
This commit is contained in:
parent
33711e20ff
commit
1ff1121bf4
@ -15,6 +15,22 @@ public class ImageApiTests : ApiTestsBase
|
||||
_imageApi = new ImageApi(Context, new NullLogger<ImageApi>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AddComment_should_pass_data_to_piwigo_and_return_new_comment()
|
||||
{
|
||||
SetJsonResult(@"{""stat"":""ok"",""result"":{""comment"":{""id"":2,""validation"":true}}}");
|
||||
|
||||
var commentId = await _imageApi.AddCommentAsync(4, "admin", "test comment", "testKey");
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.images.addComment");
|
||||
CorrectParamShouldGetSent("image_id", "4");
|
||||
CorrectParamShouldGetSent("author", "admin");
|
||||
CorrectParamShouldGetSent("content", "test comment");
|
||||
CorrectParamShouldGetSent("key", "testKey");
|
||||
|
||||
commentId.Should().Be(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetInfo_should_pass_request_and_return_data()
|
||||
{
|
||||
|
9
PiwigoDotnet/Piwigo.Client/Contract/CommentAdded.cs
Normal file
9
PiwigoDotnet/Piwigo.Client/Contract/CommentAdded.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Piwigo.Client.Contract;
|
||||
|
||||
public record CommentAdded
|
||||
{
|
||||
[JsonProperty("comment")]
|
||||
public Comment Comment { get; init; } = null!;
|
||||
}
|
@ -6,6 +6,7 @@ public interface IImageApi
|
||||
{
|
||||
Task<ImageUploaded> AddAsync(ImageUpload imageUpload, CancellationToken cancellationToken = default);
|
||||
Task<ImageUploaded> UpdateAsync(int imageId, ImageUpload imageUpload, CancellationToken cancellationToken = default);
|
||||
Task<int> AddCommentAsync(int imageId, string? author, string content, string key, CancellationToken cancellationToken = default);
|
||||
Task AddChunkAsync(byte[] data, string originalSum, int position, CancellationToken cancellationToken = default);
|
||||
Task<bool> ReadyForUploadAsync(CancellationToken cancellationToken = default);
|
||||
Task<Image> GetInfoAsync(int imageId, int? commentsPage, int? commentsPerPage, CancellationToken cancellationToken = default);
|
||||
@ -14,7 +15,6 @@ public interface IImageApi
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/*
|
||||
addComment
|
||||
checkFiles
|
||||
delete
|
||||
deleteOrphans
|
||||
|
@ -18,6 +18,21 @@ public class ImageApi : IImageApi
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public async Task<int> AddCommentAsync(int imageId, string? author, string content, string key, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var formParams = new Dictionary<string, string>
|
||||
{
|
||||
{ "image_id", imageId.ToString() },
|
||||
{ "content", content },
|
||||
{ "key", key }
|
||||
};
|
||||
formParams.AddIfValueNotNull("author", author);
|
||||
|
||||
var response = await _context.PostAsync<PiwigoResponse<CommentAdded>>(_logger, "pwg.images.addComment", formParams, cancellationToken);
|
||||
|
||||
return response.Result.Comment.Id;
|
||||
}
|
||||
|
||||
public async Task AddChunkAsync(byte[] data, string originalSum, int position, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var base64Data = Convert.ToBase64String(data);
|
||||
|
Loading…
Reference in New Issue
Block a user