updates getall to provide some parameters
This commit is contained in:
parent
007d1caacf
commit
171aeb6e5e
59
PiwigoDotnet/Piwigo.Client.Tests/AlbumApi.getList.json
Normal file
59
PiwigoDotnet/Piwigo.Client.Tests/AlbumApi.getList.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
[
|
||||
{
|
||||
id: 1,
|
||||
name: UnitTestMain
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: UnitTestSub2,
|
||||
id_uppercat: 1
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: UnitTestSub1,
|
||||
id_uppercat: 1
|
||||
}
|
||||
]
|
@ -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
|
||||
}
|
||||
]
|
@ -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<AlbumList>
|
||||
{
|
||||
Status = "ok",
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
@ -29,7 +29,10 @@
|
||||
<None Update="ImageApiTests.GetImages_should_return_expected_images.verified.txt">
|
||||
<DependentUpon>ImageApiTests.cs</DependentUpon>
|
||||
</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>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
@ -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<string, string> { { "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<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);
|
||||
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)
|
||||
{
|
||||
return status switch
|
||||
|
@ -5,15 +5,23 @@ namespace Piwigo.Client;
|
||||
public interface IAlbumApi
|
||||
{
|
||||
Task<AlbumOrphans> 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<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);
|
||||
|
||||
Task<IReadOnlyCollection<Album>> GetAllAsync(CancellationToken cancellationToken = default);
|
||||
Task<IReadOnlyCollection<Album>> GetListAsync(int? albumId, bool? recursive, bool? fullName, ThumbnailSize? thumbnailSize, CancellationToken cancellationToken = default);
|
||||
}
|
11
PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs
Normal file
11
PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace Piwigo.Client;
|
||||
|
||||
public enum ThumbnailSize
|
||||
{
|
||||
Thumb = 0,
|
||||
Square,
|
||||
Small,
|
||||
Medium,
|
||||
Large,
|
||||
XxLarge
|
||||
}
|
@ -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_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/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>
|
Loading…
Reference in New Issue
Block a user