use RESTful style for GET & POST to child entity endpoints
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
using Pilz.Data;
|
||||
using Pilz.Net.Api.Messages;
|
||||
using Pilz.Net.Extensions;
|
||||
|
||||
namespace Pilz.Net.Api.Client;
|
||||
|
||||
public abstract class BaseChildItemClient<T>(IApiClient client) : BaseClient<T>(client), IBaseChildItemClient<T> where T : IDataObject
|
||||
{
|
||||
public override string ApiEndpoint => ApiEndpointParent + ApiEndpointChild;
|
||||
public abstract string ApiEndpointParent { get; }
|
||||
public abstract string ApiEndpointChild { get; }
|
||||
|
||||
public virtual async Task<IEnumerable<T>> GetAll(int parentId)
|
||||
{
|
||||
return (await client.SendRequest<GeneralItemMessages<T>.Items>(ApiEndpoint, HttpMethod.Get, new ApiParameterCollection
|
||||
{
|
||||
["parent"] = parentId,
|
||||
})).EnsureOk().Items;
|
||||
return (await client.SendRequest<GeneralItemMessages<T>.Items>($"{ApiEndpointParent}/{parentId}{ApiEndpointChild}", HttpMethod.Get)).EnsureOk().Items;
|
||||
}
|
||||
|
||||
public override async Task<T> Save(T item)
|
||||
@@ -26,12 +26,8 @@ public abstract class BaseChildItemClient<T>(IApiClient client) : BaseClient<T>(
|
||||
if (item.Id != 0)
|
||||
return await Save(item);
|
||||
return (await client.SendRequest<GeneralItemMessages<T>.Item>(
|
||||
ApiEndpoint,
|
||||
$"{ApiEndpointParent}/{parentId}{ApiEndpointChild}",
|
||||
HttpMethod.Post,
|
||||
GenerateUpdateMessage(item, true),
|
||||
new ApiParameterCollection
|
||||
{
|
||||
["parent"] = parentId,
|
||||
})).EnsureOk().Item;
|
||||
GenerateUpdateMessage(item, true))).EnsureOk().Item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user