From 171aeb6e5edcf8ae08d0f0c5c6e6dda045118f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Fri, 21 Oct 2022 21:45:08 +0200 Subject: [PATCH] updates getall to provide some parameters --- .../Piwigo.Client.Tests/AlbumApi.getList.json | 59 +++++++++++++++++++ ...ld_return_all_existing_albums.verified.txt | 16 ----- ...ld_return_all_existing_albums.verified.txt | 42 +++++++++++++ .../Piwigo.Client.Tests/AlbumApiTests.cs | 24 +++----- .../Piwigo.Client.Tests.csproj | 5 +- PiwigoDotnet/Piwigo.Client/AlbumApi.cs | 46 +++++++++++---- PiwigoDotnet/Piwigo.Client/IAlbumApi.cs | 10 +++- PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs | 11 ++++ PiwigoDotnet/PiwigoDotnet.sln.DotSettings | 3 +- 9 files changed, 171 insertions(+), 45 deletions(-) create mode 100644 PiwigoDotnet/Piwigo.Client.Tests/AlbumApi.getList.json delete mode 100644 PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetAll_should_return_all_existing_albums.verified.txt create mode 100644 PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetList_should_return_all_existing_albums.verified.txt create mode 100644 PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs diff --git a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApi.getList.json b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApi.getList.json new file mode 100644 index 0000000..a23fd22 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApi.getList.json @@ -0,0 +1,59 @@ +{ + stat: "ok", + result: { + categories: [ + { + id: 7, + name: "LocalTestAlbum", + comment: "", + permalink: null, + status: "public", + uppercats: "7", + global_rank: "1", + id_uppercat: null, + nb_images: 4, + total_nb_images: 4, + representative_picture_id: "1", + date_last: "2022-10-20 22:01:32", + max_date_last: "2022-10-20 22:01:32", + nb_categories: 0, + url: "http://localhost:8080/index.php?/category/7", + tn_url: "http://localhost:8080/i.php?/upload/2022/10/20/20221020220129-6b8c2a7d-th.jpg" + }, + { + id: 6, + name: "UnittestMain2", + comment: "comment", + permalink: null, + status: "public", + uppercats: "6", + global_rank: "2", + id_uppercat: null, + nb_images: 0, + total_nb_images: 0, + representative_picture_id: null, + date_last: null, + max_date_last: null, + nb_categories: 0, + url: "http://localhost:8080/index.php?/category/6" + }, + { + id: 1, + name: "UnitTestMain", + comment: "", + permalink: null, + status: "public", + uppercats: "1", + global_rank: "3", + id_uppercat: null, + nb_images: 0, + total_nb_images: 0, + representative_picture_id: null, + date_last: null, + max_date_last: null, + nb_categories: 1, + url: "http://localhost:8080/index.php?/category/1" + } + ] + } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetAll_should_return_all_existing_albums.verified.txt b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetAll_should_return_all_existing_albums.verified.txt deleted file mode 100644 index ff41af6..0000000 --- a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetAll_should_return_all_existing_albums.verified.txt +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - id: 1, - name: UnitTestMain - }, - { - id: 3, - name: UnitTestSub2, - id_uppercat: 1 - }, - { - id: 2, - name: UnitTestSub1, - id_uppercat: 1 - } -] \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetList_should_return_all_existing_albums.verified.txt b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetList_should_return_all_existing_albums.verified.txt new file mode 100644 index 0000000..a52ebde --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.GetList_should_return_all_existing_albums.verified.txt @@ -0,0 +1,42 @@ +[ + { + id: 7, + name: LocalTestAlbum, + comment: , + status: public, + uppercats: 7, + global_rank: 1, + nb_images: 4, + total_nb_images: 4, + representative_picture_id: 1, + date_last: 2022-10-20 22:01:32, + max_date_last: 2022-10-20 22:01:32, + nb_categories: 0, + url: http://localhost:8080/index.php?/category/7, + tn_url: http://localhost:8080/i.php?/upload/2022/10/20/20221020220129-6b8c2a7d-th.jpg + }, + { + id: 6, + name: UnittestMain2, + comment: comment, + status: public, + uppercats: 6, + global_rank: 2, + nb_images: 0, + total_nb_images: 0, + nb_categories: 0, + url: http://localhost:8080/index.php?/category/6 + }, + { + id: 1, + name: UnitTestMain, + comment: , + status: public, + uppercats: 1, + global_rank: 3, + nb_images: 0, + total_nb_images: 0, + nb_categories: 1, + url: http://localhost:8080/index.php?/category/1 + } +] \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs index 3bb2047..a95bce2 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs +++ b/PiwigoDotnet/Piwigo.Client.Tests/AlbumApiTests.cs @@ -136,25 +136,17 @@ public class AlbumApiTests : ApiTestsBase } [Test] - public async Task GetAll_should_return_all_existing_albums() + public async Task GetList_should_return_all_existing_albums() { - var serverResponse = new PiwigoResponse - { - Status = "ok", - Result = new AlbumList - { - Albums = new List - { - new() { Id = 1, Name = "UnitTestMain" }, - new() { Id = 3, Name = "UnitTestSub2", IdUpperCat = 1 }, - new() { Id = 2, Name = "UnitTestSub1", IdUpperCat = 1 } - } - } - }; - SetJsonResult(serverResponse); - var response = await _albumApi.GetAllAsync(); + await SetJsonResultFromFileAsync("AlbumApi.getList.json"); + + var response = await _albumApi.GetListAsync(1, true, false, ThumbnailSize.Small); CorrectMethodShouldGetCalled("pwg.categories.getList"); + CorrectParamShouldGetSent("cat_id", "1"); + CorrectParamShouldGetSent("recursive", "true"); + CorrectParamShouldGetSent("fullname", "false"); + CorrectParamShouldGetSent("thumbnail_size", "small"); await Verify(response); } diff --git a/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj b/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj index ede3f2f..daca17a 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj +++ b/PiwigoDotnet/Piwigo.Client.Tests/Piwigo.Client.Tests.csproj @@ -29,7 +29,10 @@ ImageApiTests.cs - + + Always + + AlbumApiTests.cs diff --git a/PiwigoDotnet/Piwigo.Client/AlbumApi.cs b/PiwigoDotnet/Piwigo.Client/AlbumApi.cs index a766859..c629c4b 100644 --- a/PiwigoDotnet/Piwigo.Client/AlbumApi.cs +++ b/PiwigoDotnet/Piwigo.Client/AlbumApi.cs @@ -57,14 +57,7 @@ public class AlbumApi : IAlbumApi AlbumPosition? position = null, CancellationToken cancellationToken = default) { var statusValue = GetAlbumStatusValue(status); - - var positionValue = position switch - { - AlbumPosition.First => "first", - AlbumPosition.Last => "last", - null => null, - _ => throw new ArgumentOutOfRangeException(nameof(position), position, null) - }; + var positionValue = GetPositionValue(position); var formParams = new Dictionary { { "name", name } }; formParams.AddIfValueNotNull("parent", parentId?.ToString()).AddIfValueNotNull("comment", comment).AddIfValueNotNull("visible", visible?.ToString()) @@ -99,13 +92,46 @@ public class AlbumApi : IAlbumApi await _context.PostAsync(_logger, "pwg.categories.setInfo", formParams, cancellationToken); } - public async Task> GetAllAsync(CancellationToken cancellationToken = default) + public async Task> GetListAsync(int? albumId, bool? recursive, bool? fullName, ThumbnailSize? thumbnailSize, + CancellationToken cancellationToken = default) { - var formParams = new Dictionary { { "recursive", "true" } }; + var thumbnailSizeValue = GetThumbnailSizeValue(thumbnailSize); + + var formParams = new Dictionary(); + + formParams.AddIfValueNotNull("cat_id", albumId?.ToString()).AddIfValueNotNull("recursive", recursive?.ToString()).AddIfValueNotNull("fullname", fullName?.ToString()) + .AddIfValueNotNull("thumbnail_size", thumbnailSizeValue); + var response = await _context.PostAsync>(_logger, "pwg.categories.getList", formParams, cancellationToken); return new ReadOnlyCollection(response.Result.Albums); } + private static string? GetPositionValue(AlbumPosition? position) + { + return position switch + { + AlbumPosition.First => "first", + AlbumPosition.Last => "last", + null => null, + _ => throw new ArgumentOutOfRangeException(nameof(position), position, null) + }; + } + + private static string? GetThumbnailSizeValue(ThumbnailSize? thumbnailSize) + { + return thumbnailSize switch + { + ThumbnailSize.Thumb => "thumb", + ThumbnailSize.Square => "square", + ThumbnailSize.Small => "small", + ThumbnailSize.Medium => "medium", + ThumbnailSize.Large => "large", + ThumbnailSize.XxLarge => "xxlarge", + null => null, + _ => throw new ArgumentOutOfRangeException(nameof(thumbnailSize), thumbnailSize, null) + }; + } + private static string? GetAlbumStatusValue(AlbumStatus? status) { return status switch diff --git a/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs b/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs index 4e28c44..d5ae15d 100644 --- a/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs +++ b/PiwigoDotnet/Piwigo.Client/IAlbumApi.cs @@ -5,15 +5,23 @@ namespace Piwigo.Client; public interface IAlbumApi { Task CalculateOrphansAsync(int albumId, CancellationToken cancellationToken = default); + Task DeleteAsync(int albumId, string apiToken, CancellationToken cancellationToken = default); + Task MoveAsync(int albumId, int parentAlbumId, string apiToken, CancellationToken cancellationToken = default); + Task DeleteRepresentativeAsync(int albumId, CancellationToken cancellationToken = default); + Task RefreshRepresentativeAsync(int albumId, CancellationToken cancellationToken = default); + Task SetRepresentativeAsync(int albumId, int imageId, CancellationToken cancellationToken = default); + Task SetRankAsync(int albumId, int rank, CancellationToken cancellationToken = default); + Task SetInfoAsync(int albumId, string name, string? comment, AlbumStatus? status, CancellationToken cancellationToken = default); + Task AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, AlbumStatus? status = null, bool? commentable = null, AlbumPosition? position = null, CancellationToken cancellationToken = default); - Task> GetAllAsync(CancellationToken cancellationToken = default); + Task> GetListAsync(int? albumId, bool? recursive, bool? fullName, ThumbnailSize? thumbnailSize, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs b/PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs new file mode 100644 index 0000000..2ce720b --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs @@ -0,0 +1,11 @@ +namespace Piwigo.Client; + +public enum ThumbnailSize +{ + Thumb = 0, + Square, + Small, + Medium, + Large, + XxLarge +} \ No newline at end of file diff --git a/PiwigoDotnet/PiwigoDotnet.sln.DotSettings b/PiwigoDotnet/PiwigoDotnet.sln.DotSettings index b1e22f3..34f0e8b 100644 --- a/PiwigoDotnet/PiwigoDotnet.sln.DotSettings +++ b/PiwigoDotnet/PiwigoDotnet.sln.DotSettings @@ -67,4 +67,5 @@ True True True - True \ No newline at end of file + True + True \ No newline at end of file