return IOrderedQueryable and order by id by default

This commit is contained in:
Pilzinsel64
2025-11-21 08:45:09 +01:00
parent 42bb1f884a
commit 7c6c216b02
3 changed files with 10 additions and 15 deletions

View File

@@ -19,6 +19,8 @@ public abstract class BaseHandler<TEntity, TUpdateMsg>(IApiServer server)
public event EventHandler<TEntity>? OnDeleteItem;
protected readonly bool isNamedObjectType = typeof(TEntity).IsAssignableTo(typeof(INamedObject));
/// <summary>
/// Gets the base route (endpoint) for the most API calls.
/// </summary>
@@ -102,6 +104,13 @@ public abstract class BaseHandler<TEntity, TUpdateMsg>(IApiServer server)
return entities;
}
protected virtual IOrderedQueryable<TEntity> SortEntities(IQueryable<TEntity> entities)
{
if (isNamedObjectType)
return entities.OrderBy(n => ((INamedObject)n).Name);
return entities.OrderBy(n => n.Id);
}
protected abstract ApiResult? UpdateEntity(EntityUpdate update);
protected abstract IDataObject ToClient(TEntity entity);