renames category to album even if the api reference uses category. piwigo uses album everywhere and this seems more logical
This commit is contained in:
parent
62679b0c09
commit
37c262e74f
@ -4,27 +4,45 @@ using Piwigo.Client.Contract;
|
|||||||
namespace Piwigo.Client.Tests;
|
namespace Piwigo.Client.Tests;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class CategoryApiTests : ApiTestsBase
|
public class AlbumApiTests : ApiTestsBase
|
||||||
{
|
{
|
||||||
private CategoryApi _categoryApi = null!;
|
private AlbumApi _albumApi = null!;
|
||||||
|
|
||||||
protected override void OnSetUp()
|
protected override void OnSetUp()
|
||||||
{
|
{
|
||||||
base.OnSetUp();
|
base.OnSetUp();
|
||||||
_categoryApi = new CategoryApi(Context, new NullLogger<CategoryApi>());
|
_albumApi = new AlbumApi(Context, new NullLogger<AlbumApi>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task GetAllCategories_should_return_all_existing_categories()
|
public async Task Add_should_create_album_and_return_id()
|
||||||
{
|
{
|
||||||
await LoginAsync();
|
await LoginAsync();
|
||||||
|
|
||||||
|
var serverResponse = new PiwigoResponse<AlbumAdded>
|
||||||
var serverResponse = new PiwigoResponse<PiwigoCategoryList>
|
|
||||||
{
|
{
|
||||||
Result = new PiwigoCategoryList
|
Result = new AlbumAdded
|
||||||
{
|
{
|
||||||
Categories = new List<PiwigoCategory>
|
Id = 1, Info = "Album added"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SetJsonResult(serverResponse);
|
||||||
|
var response = await _albumApi.AddAsync("UnittestMain2", null, "comment", true, CategoryStatus.Public, true, CategoryPosition.Last);
|
||||||
|
|
||||||
|
response.Should().BeGreaterOrEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetAll_should_return_all_existing_albums()
|
||||||
|
{
|
||||||
|
await LoginAsync();
|
||||||
|
|
||||||
|
var serverResponse = new PiwigoResponse<AlbumList>
|
||||||
|
{
|
||||||
|
Result = new AlbumList
|
||||||
|
{
|
||||||
|
Albums = new List<Album>
|
||||||
{
|
{
|
||||||
new() { Id = 1, Name = "UnitTestMain" },
|
new() { Id = 1, Name = "UnitTestMain" },
|
||||||
new() { Id = 3, Name = "UnitTestSub2", IdUpperCat = 1 },
|
new() { Id = 3, Name = "UnitTestSub2", IdUpperCat = 1 },
|
||||||
@ -33,7 +51,7 @@ public class CategoryApiTests : ApiTestsBase
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
SetJsonResult(serverResponse);
|
SetJsonResult(serverResponse);
|
||||||
var response = await _categoryApi.GetAllAsync();
|
var response = await _albumApi.GetAllAsync();
|
||||||
|
|
||||||
response.Should().HaveCount(3);
|
response.Should().HaveCount(3);
|
||||||
response.Should().SatisfyRespectively(c =>
|
response.Should().SatisfyRespectively(c =>
|
@ -4,35 +4,12 @@ using Piwigo.Client.Contract;
|
|||||||
|
|
||||||
namespace Piwigo.Client;
|
namespace Piwigo.Client;
|
||||||
|
|
||||||
internal static class DictionaryExtensions
|
public class AlbumApi : IAlbumApi
|
||||||
{
|
|
||||||
public static IDictionary<string, string> AddIfValueNotNull(this IDictionary<string, string> dictionary, string key, string? value)
|
|
||||||
{
|
|
||||||
if (dictionary == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(dictionary));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(key))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Value cannot be null or whitespace.", nameof(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value is not null)
|
|
||||||
{
|
|
||||||
dictionary.Add(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dictionary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CategoryApi : ICategoryApi
|
|
||||||
{
|
{
|
||||||
private readonly IPiwigoContext _context;
|
private readonly IPiwigoContext _context;
|
||||||
private readonly ILogger<CategoryApi> _logger;
|
private readonly ILogger<AlbumApi> _logger;
|
||||||
|
|
||||||
public CategoryApi(IPiwigoContext context, ILogger<CategoryApi> logger)
|
public AlbumApi(IPiwigoContext context, ILogger<AlbumApi> logger)
|
||||||
{
|
{
|
||||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
@ -70,11 +47,11 @@ public class CategoryApi : ICategoryApi
|
|||||||
return response.Result.Id.Value;
|
return response.Result.Id.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyCollection<PiwigoCategory>> GetAllAsync()
|
public async Task<IReadOnlyCollection<Album>> GetAllAsync()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Getting all existing categories from server");
|
_logger.LogInformation("Getting all existing categories from server");
|
||||||
var formParams = new Dictionary<string, string> { { "recursive", "true" } };
|
var formParams = new Dictionary<string, string> { { "recursive", "true" } };
|
||||||
var response = await _context.PostAsync<PiwigoResponse<PiwigoCategoryList>>(_logger, "pwg.categories.getList", formParams);
|
var response = await _context.PostAsync<PiwigoResponse<AlbumList>>(_logger, "pwg.categories.getList", formParams);
|
||||||
return new ReadOnlyCollection<PiwigoCategory>(response.Result.Categories);
|
return new ReadOnlyCollection<Album>(response.Result.Albums);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ using Newtonsoft.Json;
|
|||||||
namespace Piwigo.Client.Contract;
|
namespace Piwigo.Client.Contract;
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "StringLiteralTypo")]
|
[SuppressMessage("ReSharper", "StringLiteralTypo")]
|
||||||
public class PiwigoCategory
|
public class Album
|
||||||
{
|
{
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
public int Id { get; init; }
|
public int Id { get; init; }
|
9
PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs
Normal file
9
PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Piwigo.Client.Contract;
|
||||||
|
|
||||||
|
public class AlbumList
|
||||||
|
{
|
||||||
|
[JsonProperty("Categories")]
|
||||||
|
public IList<Album> Albums { get; init; } = null!;
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Piwigo.Client.Contract;
|
|
||||||
|
|
||||||
public class PiwigoCategoryList
|
|
||||||
{
|
|
||||||
[JsonProperty("Categories")]
|
|
||||||
public IList<PiwigoCategory> Categories { get; init; } = null!;
|
|
||||||
}
|
|
24
PiwigoDotnet/Piwigo.Client/DictionaryExtensions.cs
Normal file
24
PiwigoDotnet/Piwigo.Client/DictionaryExtensions.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
namespace Piwigo.Client;
|
||||||
|
|
||||||
|
internal static class DictionaryExtensions
|
||||||
|
{
|
||||||
|
public static IDictionary<string, string> AddIfValueNotNull(this IDictionary<string, string> dictionary, string key, string? value)
|
||||||
|
{
|
||||||
|
if (dictionary == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(dictionary));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Value cannot be null or whitespace.", nameof(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value is not null)
|
||||||
|
{
|
||||||
|
dictionary.Add(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dictionary;
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,10 @@ using Piwigo.Client.Contract;
|
|||||||
|
|
||||||
namespace Piwigo.Client;
|
namespace Piwigo.Client;
|
||||||
|
|
||||||
public interface ICategoryApi
|
public interface IAlbumApi
|
||||||
{
|
{
|
||||||
Task<int> AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, CategoryStatus? status = null, bool? commentable = null,
|
Task<int> AddAsync(string name, int? parentId = null, string? comment = null, bool? visible = null, CategoryStatus? status = null, bool? commentable = null,
|
||||||
CategoryPosition? position = null);
|
CategoryPosition? position = null);
|
||||||
|
|
||||||
Task<IReadOnlyCollection<PiwigoCategory>> GetAllAsync();
|
Task<IReadOnlyCollection<Album>> GetAllAsync();
|
||||||
}
|
}
|
@ -8,5 +8,5 @@ public interface IPiwigoClient
|
|||||||
ITagApi Tag { get; }
|
ITagApi Tag { get; }
|
||||||
IUserApi User { get; }
|
IUserApi User { get; }
|
||||||
ISessionApi Session { get; }
|
ISessionApi Session { get; }
|
||||||
ICategoryApi Category { get; }
|
IAlbumApi Album { get; }
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ namespace Piwigo.Client;
|
|||||||
|
|
||||||
public class PiwigoClient : IPiwigoClient
|
public class PiwigoClient : IPiwigoClient
|
||||||
{
|
{
|
||||||
public PiwigoClient(IGroupApi group, IImageApi image, IPermissionApi permission, ITagApi tag, IUserApi user, ISessionApi session, ICategoryApi category)
|
public PiwigoClient(IGroupApi group, IImageApi image, IPermissionApi permission, ITagApi tag, IUserApi user, ISessionApi session, IAlbumApi album)
|
||||||
{
|
{
|
||||||
Group = group ?? throw new ArgumentNullException(nameof(group));
|
Group = group ?? throw new ArgumentNullException(nameof(group));
|
||||||
Image = image ?? throw new ArgumentNullException(nameof(image));
|
Image = image ?? throw new ArgumentNullException(nameof(image));
|
||||||
@ -10,7 +10,7 @@ public class PiwigoClient : IPiwigoClient
|
|||||||
Tag = tag ?? throw new ArgumentNullException(nameof(tag));
|
Tag = tag ?? throw new ArgumentNullException(nameof(tag));
|
||||||
User = user ?? throw new ArgumentNullException(nameof(user));
|
User = user ?? throw new ArgumentNullException(nameof(user));
|
||||||
Session = session ?? throw new ArgumentNullException(nameof(session));
|
Session = session ?? throw new ArgumentNullException(nameof(session));
|
||||||
Category = category ?? throw new ArgumentNullException(nameof(category));
|
Album = album ?? throw new ArgumentNullException(nameof(album));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGroupApi Group { get; }
|
public IGroupApi Group { get; }
|
||||||
@ -19,5 +19,5 @@ public class PiwigoClient : IPiwigoClient
|
|||||||
public ITagApi Tag { get; }
|
public ITagApi Tag { get; }
|
||||||
public IUserApi User { get; }
|
public IUserApi User { get; }
|
||||||
public ISessionApi Session { get; }
|
public ISessionApi Session { get; }
|
||||||
public ICategoryApi Category { get; }
|
public IAlbumApi Album { get; }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user