Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Commit

Permalink
Refactor query context
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Jun 4, 2019
1 parent debf279 commit dd9f7cc
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 55 deletions.
7 changes: 4 additions & 3 deletions src/BioEngine.Core.API/ContentEntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BioEngine.Core.Abstractions;
using BioEngine.Core.API.Models;
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
Expand All @@ -13,17 +14,17 @@ namespace BioEngine.Core.API
{
public abstract class
ContentEntityController<TEntity, TRepository, TResponse, TRequest> : RequestRestController<
TEntity, ContentEntityQueryContext<TEntity>, TRepository, TResponse, TRequest>
TEntity, TRepository, TResponse, TRequest>
where TEntity : class, IContentEntity, IEntity
where TResponse : class, IContentResponseRestModel<TEntity>
where TRequest : class, IContentRequestRestModel<TEntity>
where TRepository : IContentEntityRepository<TEntity, ContentEntityQueryContext<TEntity>>
where TRepository : IContentEntityRepository<TEntity>
{
private readonly ContentBlocksRepository _blocksRepository;
protected BioEntitiesManager EntitiesManager { get; }

protected ContentEntityController(
BaseControllerContext<TEntity, ContentEntityQueryContext<TEntity>, TRepository> context,
BaseControllerContext<TEntity, TRepository> context,
BioEntitiesManager entitiesManager, ContentBlocksRepository blocksRepository) : base(context)
{
_blocksRepository = blocksRepository;
Expand Down
5 changes: 2 additions & 3 deletions src/BioEngine.Core.API/Controllers/MenuController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
using BioEngine.Core.Repository;
using BioEngine.Core.Web;

namespace BioEngine.Core.API.Controllers
{
public class MenuController : ResponseRequestRestController<Menu, QueryContext<Menu>, MenuRepository, Entities.Menu>
public class MenuController : ResponseRequestRestController<Menu, MenuRepository, Entities.Menu>
{
public MenuController(BaseControllerContext<Menu, QueryContext<Menu>, MenuRepository> context) : base(context)
public MenuController(BaseControllerContext<Menu, MenuRepository> context) : base(context)
{
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/BioEngine.Core.API/Controllers/SectionsController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
using BioEngine.Core.Entities;
using BioEngine.Core.Repository;
using BioEngine.Core.Web;

namespace BioEngine.Core.API.Controllers
{
public class SectionsController : SectionController<Section, ContentEntityQueryContext<Section>, SectionsRepository,
Entities.Section>
public class SectionsController : SectionController<Section, SectionsRepository, Entities.Section>
{
public SectionsController(
BaseControllerContext<Section, ContentEntityQueryContext<Section>, SectionsRepository> context) :
base(context)
public SectionsController(BaseControllerContext<Section, SectionsRepository> context) : base(context)
{
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/BioEngine.Core.API/Controllers/SitesController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
using BioEngine.Core.Entities;
using BioEngine.Core.Repository;
using BioEngine.Core.Web;

namespace BioEngine.Core.API.Controllers
{
public class
SitesController : ResponseRequestRestController<Site, QueryContext<Site>, SitesRepository, Entities.Site>
SitesController : ResponseRequestRestController<Site, SitesRepository, Entities.Site>
{
public SitesController(BaseControllerContext<Site, QueryContext<Site>, SitesRepository> context) : base(context)
public SitesController(BaseControllerContext<Site, SitesRepository> context) : base(context)
{
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/BioEngine.Core.API/Controllers/TagsController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
using BioEngine.Core.Entities;
using BioEngine.Core.Repository;
using BioEngine.Core.Web;

namespace BioEngine.Core.API.Controllers
{
public class TagsController : ResponseRequestRestController<Tag, QueryContext<Tag>, TagsRepository, Entities.Tag>
public class TagsController : ResponseRequestRestController<Tag, TagsRepository, Entities.Tag>
{
public TagsController(BaseControllerContext<Tag, QueryContext<Tag>, TagsRepository> context) : base(context)
public TagsController(BaseControllerContext<Tag, TagsRepository> context) : base(context)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Models/ContentEntityRestModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using BioEngine.Core.Entities;
using BioEngine.Core.Abstractions;

namespace BioEngine.Core.API.Models
{
Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Models/IRequestRestModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using BioEngine.Core.Entities;
using BioEngine.Core.Abstractions;
using ContentBlock = BioEngine.Core.API.Entities.ContentBlock;

namespace BioEngine.Core.API.Models
Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Models/IResponseRestModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using BioEngine.Core.Entities;
using BioEngine.Core.Abstractions;
using ContentBlock = BioEngine.Core.API.Entities.ContentBlock;

namespace BioEngine.Core.API.Models
Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Models/RestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BioEngine.Core.Abstractions;
using BioEngine.Core.API.Entities;
using BioEngine.Core.Entities;
using BioEngine.Core.Properties;
using Newtonsoft.Json;

Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Models/SectionEntityRestModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using BioEngine.Core.Entities;
using BioEngine.Core.Abstractions;

namespace BioEngine.Core.API.Models
{
Expand Down
1 change: 1 addition & 0 deletions src/BioEngine.Core.API/Models/SectionRestModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BioEngine.Core.Abstractions;
using BioEngine.Core.Entities;

namespace BioEngine.Core.API.Models
Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Models/SiteEntityRestModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using BioEngine.Core.Entities;
using BioEngine.Core.Abstractions;

namespace BioEngine.Core.API.Models
{
Expand Down
20 changes: 9 additions & 11 deletions src/BioEngine.Core.API/RequestRestController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using BioEngine.Core.Abstractions;
using BioEngine.Core.API.Models;
using BioEngine.Core.API.Response;
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
using BioEngine.Core.Repository;
using BioEngine.Core.Web;
Expand All @@ -13,16 +13,15 @@
namespace BioEngine.Core.API
{
public abstract class
RequestRestController<TEntity, TQueryContext, TRepository, TResponse, TRequest> : ResponseRestController<TEntity
, TQueryContext, TRepository,
RequestRestController<TEntity, TRepository, TResponse, TRequest> : ResponseRestController<TEntity
, TRepository,
TResponse>
where TEntity : class, IEntity
where TResponse : class, IResponseRestModel<TEntity>
where TRequest : class, IRequestRestModel<TEntity>
where TQueryContext : QueryContext<TEntity>, new()
where TRepository : IBioRepository<TEntity, TQueryContext>
where TRepository : IBioRepository<TEntity>
{
protected RequestRestController(BaseControllerContext<TEntity, TQueryContext, TRepository> context) :
protected RequestRestController(BaseControllerContext<TEntity, TRepository> context) :
base(context)
{
}
Expand Down Expand Up @@ -131,14 +130,13 @@ protected virtual Task AfterDeleteAsync(TEntity domainModel)
}

public abstract class
ResponseRequestRestController<TEntity, TQueryContext, TRepository, TRequestResponse> :
RequestRestController<TEntity, TQueryContext, TRepository, TRequestResponse, TRequestResponse>
ResponseRequestRestController<TEntity, TRepository, TRequestResponse> :
RequestRestController<TEntity, TRepository, TRequestResponse, TRequestResponse>
where TEntity : class, IEntity
where TRequestResponse : class, IResponseRestModel<TEntity>, IRequestRestModel<TEntity>
where TQueryContext : QueryContext<TEntity>, new()
where TRepository : IBioRepository<TEntity, TQueryContext>
where TRepository : IBioRepository<TEntity>
{
protected ResponseRequestRestController(BaseControllerContext<TEntity, TQueryContext, TRepository> context) :
protected ResponseRequestRestController(BaseControllerContext<TEntity, TRepository> context) :
base(context)
{
}
Expand Down
16 changes: 7 additions & 9 deletions src/BioEngine.Core.API/ResponseRestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
using System.Text;
using System.Threading.Tasks;
using System.Web;
using BioEngine.Core.Abstractions;
using BioEngine.Core.API.Interfaces;
using BioEngine.Core.API.Models;
using BioEngine.Core.API.Response;
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
using BioEngine.Core.Repository;
using BioEngine.Core.DB.Queries;
using BioEngine.Core.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -17,15 +16,14 @@

namespace BioEngine.Core.API
{
public abstract class ResponseRestController<TEntity, TQueryContext, TRepository, TResponse> : ApiController
public abstract class ResponseRestController<TEntity, TRepository, TResponse> : ApiController
where TResponse : IResponseRestModel<TEntity>
where TEntity : class, IEntity
where TQueryContext : QueryContext<TEntity>, new()
where TRepository : IBioRepository<TEntity, TQueryContext>
where TRepository : IBioRepository<TEntity>
{
protected TRepository Repository { get; }

protected ResponseRestController(BaseControllerContext<TEntity, TQueryContext, TRepository> context) : base(context)
protected ResponseRestController(BaseControllerContext<TEntity, TRepository> context) : base(context)
{
Repository = context.Repository;
}
Expand Down Expand Up @@ -72,9 +70,9 @@ public virtual async Task<ActionResult<int>> CountAsync([FromQuery] int limit =
return Ok(result);
}

protected TQueryContext GetQueryContext(int limit, int offset, string order, string filter)
protected IQueryContext<TEntity> GetQueryContext(int limit, int offset, string order, string filter)
{
var context = new TQueryContext();
var context = HttpContext.RequestServices.GetRequiredService<IQueryContext<TEntity>>();
if (limit > 0)
{
context.Limit = limit;
Expand Down
14 changes: 7 additions & 7 deletions src/BioEngine.Core.API/SectionController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.Threading.Tasks;
using BioEngine.Core.Abstractions;
using BioEngine.Core.API.Models;
using BioEngine.Core.DB;
using BioEngine.Core.Entities;
Expand All @@ -18,9 +19,9 @@ public abstract class
where TData : ITypedData, new()
where TResponse : class, IContentResponseRestModel<TEntity>
where TRequest : SectionRestModel<TEntity>, IContentRequestRestModel<TEntity>
where TRepository : IContentEntityRepository<TEntity, ContentEntityQueryContext<TEntity>>
where TRepository : IContentEntityRepository<TEntity>
{
protected SectionController(BaseControllerContext<TEntity, ContentEntityQueryContext<TEntity>, TRepository> context,
protected SectionController(BaseControllerContext<TEntity, TRepository> context,
BioEntitiesManager entitiesManager,
ContentBlocksRepository blocksRepository) : base(context, entitiesManager, blocksRepository)
{
Expand All @@ -37,14 +38,13 @@ public override async Task<ActionResult<StorageItem>> UploadAsync([FromQuery] st
}

public abstract class
SectionController<TEntity, TQueryContext, TRepository, TResponse> : ResponseRestController<TEntity,
TQueryContext, TRepository, TResponse>
SectionController<TEntity, TRepository, TResponse> : ResponseRestController<TEntity,
TRepository, TResponse>
where TEntity : Section, IEntity
where TResponse : IResponseRestModel<TEntity>
where TRepository : IBioRepository<TEntity, TQueryContext>
where TQueryContext : QueryContext<TEntity>, new()
where TRepository : IBioRepository<TEntity>
{
protected SectionController(BaseControllerContext<TEntity, TQueryContext, TRepository> context) : base(context)
protected SectionController(BaseControllerContext<TEntity, TRepository> context) : base(context)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BioEngine.Core.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected BioEngineApiStartup(IConfiguration configuration, IHostEnvironment hos

protected override IMvcBuilder ConfigureMvc(IMvcBuilder mvcBuilder)
{
return base.ConfigureMvc(mvcBuilder).AddApplicationPart(typeof(ResponseRestController<,,,>).Assembly);
return base.ConfigureMvc(mvcBuilder).AddApplicationPart(typeof(ResponseRestController<,,>).Assembly);
}

public override void ConfigureServices(IServiceCollection services)
Expand Down

0 comments on commit dd9f7cc

Please sign in to comment.