Skip to content

Commit

Permalink
Merge branch 'release/v2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Feb 2, 2025
2 parents de7116a + 23df531 commit a53632f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public class BookController : BasicCrudController<BookDto, BookEntity, int, Empt
private BookManager _manager;
}

public class BookManager : EfModelManager<BookEntity, BookDto, int, EmptyAdditionalFilters>
public class BookManager : EfModelManager<BookDto, BookEntity, int, EmptyAdditionalFilters>
{
public BookManager(ModelContext modelContext, ILoggerFactory loggerFactory) : base(modelContext, BookFactory.Create, loggerFactory)
{
Expand Down Expand Up @@ -200,7 +200,7 @@ public class StationController : BasicCrudController<StationDto, StationEntity,
```

```csharp
public class StationManager : EfModelManager<StationEntity, StationDto, int>
public class StationManager : EfModelManager<StationDto, StationEntity, int>
{
public StationManager(ModelContext modelContext, ILoggerFactory loggerFactory) : base(modelContext, StationFactory.Create, loggerFactory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@
namespace Wissance.WebApiToolkit.Controllers
{

/// <summary>
/// This is a basic Read Controller implementing two operations:
/// 1. Get multiple items via api/controller/[page={20} & size={50} & sort=name & order=asc|desc ] with paging
/// and sorting by one column and filtering by any number of parameters, sort is a name of column/property
/// order is a sort order only asc and desc values are allowed.
/// Examples with Station controller:
/// - ~/api/Station to get items with default paging (page = 1, size = 25)
/// - ~/api/Station?page=2&size=50 to get items with paging options (page = 2, size = 50)
/// - ~/api/Station?page=1&size=40&sort=name&order=desc to get items with paging and sorting by column/property
/// name and in desc order (from Z to A)
/// - ~/api/Station?page=1&size=40&sort=name&order=desc&from=2022-01-01&to=2024-12-31 to get items with paging,
/// sorting and filter by date in range (2022-01-01, 2024-12-31)
/// 2. Get single item via api by id, example with Station controller:
/// - ~/api/Station/145 to get station with id = 145
/// Restrictions:
/// 1. We are working with a single type of result representation inn Response (TRes).
/// 2. To get custom filters there should be a class implementing IReadFilter, you could just return an
/// empty dictionary and act with TFilter on you own way.
/// 3. There are no option (currently) to receive all data without paging
/// </summary>
/// <typeparam name="TRes">Is A DTO object type to return back</typeparam>
/// <typeparam name="TData">Is a type that represents persistent object (i.e. Entity class)</typeparam>
/// <typeparam name="TId">Is a type of persistant object identifier</typeparam>
/// <typeparam name="TFilter">Is a type of filter class</typeparam>
public abstract class BasicReadController<TRes, TData, TId, TFilter> : BasicPagedDataController
where TRes: class
where TFilter: class, IReadFilterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ namespace Wissance.WebApiToolkit.Managers
/// * GetByIdAsync method for obtain one item by id
/// * Delete method
/// </summary>
/// <typeparam name="TObj">Model class implements IModelIdentifiable</typeparam>
/// <typeparam name="TRes">DTO class (representation of Model in other systems i.e. in frontend))</typeparam>
/// <typeparam name="TObj">Model class implements IModelIdentifiable</typeparam>
/// <typeparam name="TId">Identifier type that is using as database table PK</typeparam>
public abstract class EfModelManager <TObj, TRes, TId> : IModelManager<TRes, TObj, TId>
public abstract class EfModelManager <TRes, TObj, TId> : IModelManager<TRes, TObj, TId>
where TObj: class, IModelIdentifiable<TId>
where TRes: class
where TId: IComparable
Expand All @@ -41,7 +41,7 @@ public EfModelManager(DbContext dbContext, Func<TObj, IDictionary<string, string
ILoggerFactory loggerFactory)
{
_dbContext = dbContext ?? throw new ArgumentNullException("dbContext");
_logger = loggerFactory.CreateLogger<EfModelManager<TObj, TRes, TId>>();
_logger = loggerFactory.CreateLogger<EfModelManager<TRes, TObj, TId>>();
_defaultCreateFunc = createFunc;
_filterFunc = filterFunc;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public virtual Task<OperationResultDto<bool>> BulkDeleteAsync(TId[] objectsIds)
throw new NotImplementedException();
}

private readonly ILogger<EfModelManager<TObj, TRes, TId>> _logger;
private readonly ILogger<EfModelManager<TRes, TObj, TId>> _logger;
private readonly DbContext _dbContext;
private readonly Func<TObj, TRes> _defaultCreateFunc;
private readonly Func<TObj, IDictionary<string, string>, bool> _filterFunc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Wissance.WebApiToolkit.Managers
{
public abstract class EfSoftRemovableModelManager<TObj, TRes, TId> : IModelManager<TRes, TObj, TId>
public abstract class EfSoftRemovableModelManager<TRes, TObj, TId> : IModelManager<TRes, TObj, TId>
where TObj: class, IModelIdentifiable<TId>, IModelSoftRemovable
where TRes: class
where TId: IComparable
Expand All @@ -30,7 +30,7 @@ public EfSoftRemovableModelManager(DbContext dbContext, Func<TObj, IDictionary<s
ILoggerFactory loggerFactory)
{
_dbContext = dbContext ?? throw new ArgumentNullException("dbContext");
_logger = loggerFactory.CreateLogger<EfModelManager<TObj, TRes, TId>>();
_logger = loggerFactory.CreateLogger<EfSoftRemovableModelManager<TRes, TObj, TId>>();
_defaultCreateFunc = createFunc;
_filterFunc = filterFunc;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ public virtual Task<OperationResultDto<bool>> BulkDeleteAsync(TId[] objectsIds)
throw new NotImplementedException();
}

private readonly ILogger<EfModelManager<TObj, TRes, TId>> _logger;
private readonly ILogger<EfSoftRemovableModelManager<TRes, TObj, TId>> _logger;
private readonly DbContext _dbContext;
private readonly Func<TObj, TRes> _defaultCreateFunc;
private readonly Func<TObj, IDictionary<string, string>, bool> _filterFunc;
Expand Down

0 comments on commit a53632f

Please sign in to comment.