GetAll also for child client
This commit is contained in:
@@ -7,6 +7,11 @@ public abstract class BaseClient<T>(IApiClient client) : IBaseClient<T> where T
|
||||
{
|
||||
public abstract string ApiEndpoint { get; }
|
||||
|
||||
public virtual async Task<IEnumerable<T>> GetAll()
|
||||
{
|
||||
return (await client.SendRequest<GeneralItemMessages<T>.Items>(ApiEndpoint, HttpMethod.Get)).EnsureOk().Items;
|
||||
}
|
||||
|
||||
public virtual async Task<T> Get(int id)
|
||||
{
|
||||
return (await client.SendRequest<GeneralItemMessages<T>.Item>($"{ApiEndpoint}/{id}", HttpMethod.Get)).EnsureOk().Item;
|
||||
|
||||
@@ -5,8 +5,4 @@ namespace Pilz.Net.Api.Client;
|
||||
|
||||
public abstract class BaseItemClient<T>(IApiClient client) : BaseClient<T>(client), IBaseItemClient<T> where T : IDataObject
|
||||
{
|
||||
public virtual async Task<IEnumerable<T>> GetAll()
|
||||
{
|
||||
return (await client.SendRequest<GeneralItemMessages<T>.Items>(ApiEndpoint, HttpMethod.Get)).EnsureOk().Items;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,6 @@ public interface IBaseClient<T> where T : IDataObject
|
||||
{
|
||||
Task Delete(int id);
|
||||
Task<T> Get(int id);
|
||||
Task<IEnumerable<T>> GetAll();
|
||||
Task<T> Save(T item);
|
||||
}
|
||||
|
||||
@@ -4,5 +4,4 @@ namespace Pilz.Net.Api.Client;
|
||||
|
||||
public interface IBaseItemClient<T> : IBaseClient<T> where T : IDataObject
|
||||
{
|
||||
Task<IEnumerable<T>> GetAll();
|
||||
}
|
||||
|
||||
@@ -34,8 +34,12 @@ public abstract class BaseChildItemHandler<TEntity, TParent, TUpdateMsg>(IApiSer
|
||||
{
|
||||
IQueryable<TEntity> list;
|
||||
|
||||
if (parent != 0 && server.Manager.Find(parent, out TParent? parentEntity))
|
||||
if (parent != 0)
|
||||
{
|
||||
if (!server.Manager.Find(parent, out TParent? parentEntity))
|
||||
return ApiResult.NotFound();
|
||||
list = GetChilds(parentEntity).AsQueryable();
|
||||
}
|
||||
else
|
||||
list = server.Manager.Get<TEntity>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user