diff --git a/PiwigoDotnet/Piwigo.Client.Tests/ImageApi.getInfo.json b/PiwigoDotnet/Piwigo.Client.Tests/ImageApi.getInfo.json new file mode 100644 index 0000000..e5bb6bd --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Tests/ImageApi.getInfo.json @@ -0,0 +1,111 @@ +{ + stat: "ok", + result: { + id: 3, + file: "2017-05-24-20-35-c7d_6283.jpg", + date_available: "2022-10-20 22:01:31", + date_creation: "2017-05-24 20:35:44", + name: "2017-05-24-20-35-c7d 6283", + comment: null, + author: null, + hit: 5, + filesize: 4647, + width: 3961, + height: 2641, + coi: null, + representative_ext: null, + date_metadata_update: "2022-10-21", + rating_score: null, + level: "0", + md5sum: "9a567bdb978802f619c3610c206f0cdb", + added_by: "1", + rotation: "0", + latitude: null, + longitude: null, + lastmodified: "2022-10-20 22:01:31", + page_url: "http://localhost:8080/picture.php?/3", + element_url: "http://localhost:8080/upload/2022/10/20/20221020220131-9a567bdb.jpg", + derivatives: { + square: { + url: "http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-sq.jpg", + width: 120, + height: 120 + }, + thumb: { + url: "http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-th.jpg", + width: 144, + height: 96 + }, + 2small: { + url: "http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-2s.jpg", + width: 240, + height: 160 + }, + xsmall: { + url: "http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-xs.jpg", + width: 432, + height: 288 + }, + small: { + url: "http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-sm.jpg", + width: 576, + height: 384 + }, + medium: { + url: "http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-me.jpg", + width: 792, + height: 528 + }, + large: { + url: "http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-la.jpg", + width: 1008, + height: 672 + }, + xlarge: { + url: "http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-xl.jpg", + width: 1224, + height: 816 + }, + xxlarge: { + url: "http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-xx.jpg", + width: 1656, + height: 1104 + } + }, + rates: { + score: null, + count: 0, + average: null + }, + categories: [ + { + id: 7, + name: "LocalTestAlbum", + permalink: null, + uppercats: "7", + global_rank: "1", + url: "http://localhost:8080/index.php?/category/7", + page_url: "http://localhost:8080/picture.php?/3/category/7" + } + ], + tags: [], + comment_post: { + author: "admin", + key: "1666472481:2:c928621171e6b7b3ba199c59c778df09" + }, + comments_paging: { + page: 0, + per_page: "10", + count: 1, + total_count: 1 + }, + comments: [ + { + id: 1, + date: "2022-10-22 21:00:48", + author: "admin", + content: "testkommentar" + } + ] + } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.GetInfo_should_pass_request_and_return_data.verified.txt b/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.GetInfo_should_pass_request_and_return_data.verified.txt new file mode 100644 index 0000000..f839280 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.GetInfo_should_pass_request_and_return_data.verified.txt @@ -0,0 +1,84 @@ +{ + id: 3, + width: 3961, + height: 2641, + hit: 5, + file: 2017-05-24-20-35-c7d_6283.jpg, + name: 2017-05-24-20-35-c7d 6283, + date_creation: DateTime_1, + date_available: DateTime_2, + page_url: http://localhost:8080/picture.php?/3, + element_url: http://localhost:8080/upload/2022/10/20/20221020220131-9a567bdb.jpg, + derivatives: { + 2small: { + url: http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-2s.jpg, + width: 240, + height: 160 + }, + large: { + url: http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-la.jpg, + width: 1008, + height: 672 + }, + medium: { + url: http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-me.jpg, + width: 792, + height: 528 + }, + small: { + url: http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-sm.jpg, + width: 576, + height: 384 + }, + square: { + url: http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-sq.jpg, + width: 120, + height: 120 + }, + thumb: { + url: http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-th.jpg, + width: 144, + height: 96 + }, + xlarge: { + url: http://localhost:8080/i.php?/upload/2022/10/20/20221020220131-9a567bdb-xl.jpg, + width: 1224, + height: 816 + }, + xsmall: { + url: http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-xs.jpg, + width: 432, + height: 288 + }, + xxlarge: { + url: http://localhost:8080/_data/i/upload/2022/10/20/20221020220131-9a567bdb-xx.jpg, + width: 1656, + height: 1104 + } + }, + categories: [ + { + id: 7, + name: LocalTestAlbum, + url: http://localhost:8080/index.php?/category/7, + page_url: http://localhost:8080/picture.php?/3/category/7 + } + ], + comment_post: { + author: admin, + key: 1666472481:2:c928621171e6b7b3ba199c59c778df09 + }, + comments_paging: { + per_page: 10, + count: 1, + total_count: 1 + }, + comments: [ + { + id: 1, + date: DateTime_3, + author: admin, + content: testkommentar + } + ] +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs b/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs index f27896b..8641ca3 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs +++ b/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs @@ -15,6 +15,21 @@ public class ImageApiTests : ApiTestsBase _imageApi = new ImageApi(Context, new NullLogger()); } + [Test] + public async Task GetInfo_should_pass_request_and_return_data() + { + await SetJsonResultFromFileAsync("ImageApi.getInfo.json"); + + var response = await _imageApi.GetInfoAsync(3, 2, 100); + + CorrectMethodShouldGetCalled("pwg.images.getInfo"); + CorrectParamShouldGetSent("image_id", "3"); + CorrectParamShouldGetSent("comments_page", "2"); + CorrectParamShouldGetSent("comments_per_page", "100"); + + await Verify(response); + } + [Test] public async Task Update_should_pass_data_to_piwigo() { diff --git a/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj b/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj index daca17a..50e7262 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj +++ b/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj @@ -35,6 +35,12 @@ AlbumApiTests.cs + + Always + + + ImageApiTests.cs + diff --git a/PiwigoDotnet/Piwigo.Client/Contract/Album.cs b/PiwigoDotnet/Piwigo.Client/Contract/Album.cs index 574b0a2..23c33d6 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/Album.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/Album.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; [SuppressMessage("ReSharper", "StringLiteralTypo")] -public class Album +public record Album { [JsonProperty("id")] public int Id { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/AlbumAdded.cs b/PiwigoDotnet/Piwigo.Client/Contract/AlbumAdded.cs index c3328e0..75e95c5 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/AlbumAdded.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/AlbumAdded.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -internal class AlbumAdded +internal record AlbumAdded { [JsonProperty("info")] public string? Info { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs b/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs index 7d12ac1..e79653d 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class AlbumList +public record AlbumList { [JsonProperty("Categories")] public IList Albums { get; init; } = null!; diff --git a/PiwigoDotnet/Piwigo.Client/Contract/AlbumOrphans.cs b/PiwigoDotnet/Piwigo.Client/Contract/AlbumOrphans.cs index 192ddc4..047e266 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/AlbumOrphans.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/AlbumOrphans.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class AlbumOrphans +public record AlbumOrphans { [JsonProperty("nb_images_associated_outside")] public int? AssociatedOutsideCount { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs b/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs index f3f7ed7..11f3bcd 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class CheckUpload +public record CheckUpload { [JsonProperty("message")] public string? Message { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/Comment.cs b/PiwigoDotnet/Piwigo.Client/Contract/Comment.cs new file mode 100644 index 0000000..0578c20 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client/Contract/Comment.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Piwigo.Client.Contract; + +public record Comment +{ + [JsonProperty("id")] + public int Id { get; init; } + + [JsonProperty("date")] + public DateTime? Date { get; init; } + + [JsonProperty("author")] + public string? Author { get; init; } + + [JsonProperty("content")] + public string? Content { get; init; } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/Contract/CommentPagingInfo.cs b/PiwigoDotnet/Piwigo.Client/Contract/CommentPagingInfo.cs new file mode 100644 index 0000000..074b050 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client/Contract/CommentPagingInfo.cs @@ -0,0 +1,7 @@ +using Newtonsoft.Json; + +namespace Piwigo.Client.Contract; + +public record CommentPagingInfo([property: JsonProperty("page")] int Page, [property: JsonProperty("per_page")] int PageSize, [property: JsonProperty("count")] int Count, + [property: JsonProperty("total_count")] + int TotalItems); \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/Contract/CommentPost.cs b/PiwigoDotnet/Piwigo.Client/Contract/CommentPost.cs new file mode 100644 index 0000000..114a50e --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client/Contract/CommentPost.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Piwigo.Client.Contract; + +public record CommentPost +{ + [JsonProperty("author")] + public string? Author { get; init; } + + [JsonProperty("key")] + public string? Key { get; init; } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/Contract/Image.cs b/PiwigoDotnet/Piwigo.Client/Contract/Image.cs index 916c84c..a5302ab 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/Image.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/Image.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class Image +public record Image { [JsonProperty("id")] public int Id { get; init; } @@ -42,4 +42,13 @@ public class Image [JsonProperty("categories")] public IReadOnlyCollection? Albums { get; init; } + + [JsonProperty("comment_post")] + public CommentPost? CommentPost { get; init; } + + [JsonProperty("comments_paging")] + public CommentPagingInfo? CommentPaging { get; init; } + + [JsonProperty("comments")] + public IReadOnlyCollection? Comments { get; init; } } \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/Contract/ImageAlbum.cs b/PiwigoDotnet/Piwigo.Client/Contract/ImageAlbum.cs index 725b8c4..f2a914b 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/ImageAlbum.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/ImageAlbum.cs @@ -2,11 +2,17 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class ImageAlbum +public record ImageAlbum { [JsonProperty("id")] public int Id { get; init; } + [JsonProperty("name")] + public string? Name { get; init; } + + [JsonProperty("permalink")] + public string? Permalink { get; init; } + [JsonProperty("url")] public string? Url { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/ImageDerivative.cs b/PiwigoDotnet/Piwigo.Client/Contract/ImageDerivative.cs index 344985c..cd13cb2 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/ImageDerivative.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/ImageDerivative.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class ImageDerivative +public record ImageDerivative { [JsonProperty("url")] public string? Url { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/ImageUploaded.cs b/PiwigoDotnet/Piwigo.Client/Contract/ImageUploaded.cs index a948ef9..55065b7 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/ImageUploaded.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/ImageUploaded.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class ImageUploaded +public record ImageUploaded { [JsonProperty("image_id")] public int? ImageId { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/IImageApi.cs b/PiwigoDotnet/Piwigo.Client/IImageApi.cs index c221963..86f73e1 100644 --- a/PiwigoDotnet/Piwigo.Client/IImageApi.cs +++ b/PiwigoDotnet/Piwigo.Client/IImageApi.cs @@ -7,15 +7,14 @@ public interface IImageApi Task AddAsync(ImageUpload imageUpload, CancellationToken cancellationToken = default); Task UpdateAsync(int imageId, ImageUpload imageUpload, CancellationToken cancellationToken = default); Task AddChunkAsync(byte[] data, string originalSum, int position, CancellationToken cancellationToken = default); - Task ReadyForUploadAsync(CancellationToken cancellationToken = default); + Task GetInfoAsync(int imageId, int? commentsPage, int? commentsPerPage, CancellationToken cancellationToken = default); Task GetImages(int albumId, bool recursive, PagingInfo page, ImageFilter filter, ImageOrder order = ImageOrder.Name, CancellationToken cancellationToken = default); /* addComment -addFile checkFiles delete deleteOrphans @@ -24,7 +23,6 @@ exist -> formats delete searchImage -getInfo rate search setInfo diff --git a/PiwigoDotnet/Piwigo.Client/ImageApi.cs b/PiwigoDotnet/Piwigo.Client/ImageApi.cs index b5b09b9..0131e46 100644 --- a/PiwigoDotnet/Piwigo.Client/ImageApi.cs +++ b/PiwigoDotnet/Piwigo.Client/ImageApi.cs @@ -44,6 +44,19 @@ public class ImageApi : IImageApi return AddOrUpdateAsync(imageId, imageUpload, cancellationToken); } + public async Task GetInfoAsync(int imageId, int? commentsPage, int? commentsPerPage, CancellationToken cancellationToken = default) + { + var formParams = new Dictionary + { + { "image_id", imageId.ToString() } + }; + formParams.AddIfValueNotNull("comments_page", commentsPage?.ToString()); + formParams.AddIfValueNotNull("comments_per_page", commentsPerPage?.ToString()); + + var response = await _context.PostAsync>(_logger, "pwg.images.getInfo", formParams, cancellationToken); + return response.Result; + } + public async Task ReadyForUploadAsync(CancellationToken cancellationToken = default) { var response = await _context.PostAsync>(_logger, "pwg.images.checkUpload", new Dictionary(), cancellationToken);