astral-api/Astral.Core/RepositoryInterfaces/IGenericRepository.cs
2024-12-11 20:36:30 +00:00

54 lines
1.8 KiB
C#

// <copyright file="IGenericRepository.cs" company="alveus.dev">
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
// </copyright>
namespace Astral.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);
}