updates getall to provide some parameters

This commit is contained in:
Philipp Häfelfinger 2022-10-21 21:45:08 +02:00
parent 007d1caacf
commit 171aeb6e5e
9 changed files with 171 additions and 45 deletions

View File

@ -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"
}
]
}
}

View File

@ -1,16 +0,0 @@
[
{
id: 1,
name: UnitTestMain
},
{
id: 3,
name: UnitTestSub2,
id_uppercat: 1
},
{
id: 2,
name: UnitTestSub1,
id_uppercat: 1
}
]

View File

@ -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
}
]

View File

@ -136,25 +136,17 @@ public class AlbumApiTests : ApiTestsBase
} }
[Test] [Test]
public async Task GetAll_should_return_all_existing_albums() public async Task GetList_should_return_all_existing_albums()
{ {
var serverResponse = new PiwigoResponse<AlbumList> await SetJsonResultFromFileAsync("AlbumApi.getList.json");
{
Status = "ok", var response = await _albumApi.GetListAsync(1, true, false, ThumbnailSize.Small);
Result = new AlbumList
{
Albums = new List<Album>
{
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();
CorrectMethodShouldGetCalled("pwg.categories.getList"); CorrectMethodShouldGetCalled("pwg.categories.getList");
CorrectParamShouldGetSent("cat_id", "1");
CorrectParamShouldGetSent("recursive", "true");
CorrectParamShouldGetSent("fullname", "false");
CorrectParamShouldGetSent("thumbnail_size", "small");
await Verify(response); await Verify(response);
} }

View File

@ -29,7 +29,10 @@
<None Update="ImageApiTests.GetImages_should_return_expected_images.verified.txt"> <None Update="ImageApiTests.GetImages_should_return_expected_images.verified.txt">
<DependentUpon>ImageApiTests.cs</DependentUpon> <DependentUpon>ImageApiTests.cs</DependentUpon>
</None> </None>
<None Update="AlbumApiTests.GetAll_should_return_all_existing_albums.verified.txt"> <None Update="AlbumApi.getList.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="AlbumApiTests.GetList_should_return_all_existing_albums.verified.txt">
<DependentUpon>AlbumApiTests.cs</DependentUpon> <DependentUpon>AlbumApiTests.cs</DependentUpon>
</None> </None>
</ItemGroup> </ItemGroup>

View File

@ -57,14 +57,7 @@ public class AlbumApi : IAlbumApi
AlbumPosition? position = null, CancellationToken cancellationToken = default) AlbumPosition? position = null, CancellationToken cancellationToken = default)
{ {
var statusValue = GetAlbumStatusValue(status); var statusValue = GetAlbumStatusValue(status);
var positionValue = GetPositionValue(position);
var positionValue = position switch
{
AlbumPosition.First => "first",
AlbumPosition.Last => "last",
null => null,
_ => throw new ArgumentOutOfRangeException(nameof(position), position, null)
};
var formParams = new Dictionary<string, string> { { "name", name } }; var formParams = new Dictionary<string, string> { { "name", name } };
formParams.AddIfValueNotNull("parent", parentId?.ToString()).AddIfValueNotNull("comment", comment).AddIfValueNotNull("visible", visible?.ToString()) formParams.AddIfValueNotNull("parent", parentId?.ToString()).AddIfValueNotNull("comment", comment).AddIfValueNotNull("visible", visible?.ToString())
@ -99,13 +92,46 @@ public class AlbumApi : IAlbumApi
await _context.PostAsync<PiwigoResponse>(_logger, "pwg.categories.setInfo", formParams, cancellationToken); await _context.PostAsync<PiwigoResponse>(_logger, "pwg.categories.setInfo", formParams, cancellationToken);
} }
public async Task<IReadOnlyCollection<Album>> GetAllAsync(CancellationToken cancellationToken = default) public async Task<IReadOnlyCollection<Album>> GetListAsync(int? albumId, bool? recursive, bool? fullName, ThumbnailSize? thumbnailSize,
CancellationToken cancellationToken = default)
{ {
var formParams = new Dictionary<string, string> { { "recursive", "true" } }; var thumbnailSizeValue = GetThumbnailSizeValue(thumbnailSize);
var formParams = new Dictionary<string, string>();
formParams.AddIfValueNotNull("cat_id", albumId?.ToString()).AddIfValueNotNull("recursive", recursive?.ToString()).AddIfValueNotNull("fullname", fullName?.ToString())
.AddIfValueNotNull("thumbnail_size", thumbnailSizeValue);
var response = await _context.PostAsync<PiwigoResponse<AlbumList>>(_logger, "pwg.categories.getList", formParams, cancellationToken); var response = await _context.PostAsync<PiwigoResponse<AlbumList>>(_logger, "pwg.categories.getList", formParams, cancellationToken);
return new ReadOnlyCollection<Album>(response.Result.Albums); return new ReadOnlyCollection<Album>(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) private static string? GetAlbumStatusValue(AlbumStatus? status)
{ {
return status switch return status switch

View File

@ -5,15 +5,23 @@ namespace Piwigo.Client;
public interface IAlbumApi public interface IAlbumApi
{ {
Task<AlbumOrphans> CalculateOrphansAsync(int albumId, CancellationToken cancellationToken = default); Task<AlbumOrphans> CalculateOrphansAsync(int albumId, CancellationToken cancellationToken = default);
Task DeleteAsync(int albumId, string apiToken, CancellationToken cancellationToken = default); Task DeleteAsync(int albumId, string apiToken, CancellationToken cancellationToken = default);
Task MoveAsync(int albumId, int parentAlbumId, string apiToken, CancellationToken cancellationToken = default); Task MoveAsync(int albumId, int parentAlbumId, string apiToken, CancellationToken cancellationToken = default);
Task DeleteRepresentativeAsync(int albumId, CancellationToken cancellationToken = default); Task DeleteRepresentativeAsync(int albumId, CancellationToken cancellationToken = default);
Task RefreshRepresentativeAsync(int albumId, CancellationToken cancellationToken = default); Task RefreshRepresentativeAsync(int albumId, CancellationToken cancellationToken = default);
Task SetRepresentativeAsync(int albumId, int imageId, CancellationToken cancellationToken = default); Task SetRepresentativeAsync(int albumId, int imageId, CancellationToken cancellationToken = default);
Task SetRankAsync(int albumId, int rank, 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 SetInfoAsync(int albumId, string name, string? comment, AlbumStatus? status, CancellationToken cancellationToken = default);
Task<int> AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, AlbumStatus? status = null, bool? commentable = null, Task<int> AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, AlbumStatus? status = null, bool? commentable = null,
AlbumPosition? position = null, CancellationToken cancellationToken = default); AlbumPosition? position = null, CancellationToken cancellationToken = default);
Task<IReadOnlyCollection<Album>> GetAllAsync(CancellationToken cancellationToken = default); Task<IReadOnlyCollection<Album>> GetListAsync(int? albumId, bool? recursive, bool? fullName, ThumbnailSize? thumbnailSize, CancellationToken cancellationToken = default);
} }

View File

@ -0,0 +1,11 @@
namespace Piwigo.Client;
public enum ThumbnailSize
{
Thumb = 0,
Square,
Small,
Medium,
Large,
XxLarge
}

View File

@ -67,4 +67,5 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Piwigo/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/UserDictionary/Words/=Piwigo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=xxlarge/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>