galaeth-draft/Galaeth.Core/RepositoryInterfaces/IGenericRepository.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2024-11-17 10:31:01 +01:00
namespace Galaeth.Core.RepositoryInterfaces;
/// <summary>
/// Generic repository with auto-generated CRUD operations.
/// </summary>
/// <typeparam name="TEntity">The entity this repository handles.</typeparam>
/// <typeparam name="TKeyType">The data type of the primary key.</typeparam>
public interface IGenericRepository<TEntity, TKeyType>
where TEntity : class
{
/// <summary>
/// Find an entity by its id.
/// </summary>
/// <param name="id">The entity's id.</param>
/// <returns>The entity, or null if not found.</returns>
Task<TEntity> FindByIdAsync(TKeyType id);
/// <summary>
/// Retrieve all entities.
/// </summary>
/// <returns>Collection of entities.</returns>
Task<IEnumerable<TEntity>> GetAllAsync();
/// <summary>
/// Add an entity to the table and return it's new id.
/// </summary>
/// <param name="entity">The entity to add.</param>
/// <returns>The id of the new entity.</returns>
Task<TKeyType> AddAsync(TEntity entity);
/// <summary>
/// Add multiple entities to the table.
/// </summary>
/// <param name="entities">The entities to add.</param>
/// <returns>The id of the new entity.</returns>
Task AddAsync(IEnumerable<TEntity> entities);
/// <summary>
/// Update an entity.
/// </summary>
/// <param name="entity">The entity (needs an id) to update.</param>
/// <returns>True if entity updated.</returns>
Task<bool> UpdateAsync(TEntity entity);
/// <summary>
/// Delete an entity by its id.
/// </summary>
/// <param name="id">The entity id.</param>
Task DeleteAsync(TKeyType id);
}