forked from dotnetcore/Util
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryControllerBase.cs
More file actions
59 lines (54 loc) · 2.03 KB
/
QueryControllerBase.cs
File metadata and controls
59 lines (54 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Util.Applications;
using Util.Applications.Dtos;
using Util.Datas.Queries;
namespace Util.Webs.Controllers {
/// <summary>
/// 查询控制器
/// </summary>
/// <typeparam name="TDto">数据传输对象类型</typeparam>
/// <typeparam name="TQuery">查询参数类型</typeparam>
public abstract class QueryControllerBase<TDto, TQuery> : WebApiControllerBase
where TQuery : IQueryParameter
where TDto : class, IDto, new() {
/// <summary>
/// Crud服务
/// </summary>
private readonly ICrudService<TDto, TQuery> _service;
/// <summary>
/// 初始化查询控制器
/// </summary>
/// <param name="service">Crud服务</param>
protected QueryControllerBase( ICrudService<TDto, TQuery> service ) {
_service = service;
}
/// <summary>
/// 获取单个实例,调用范例:GET URL(/api/customers/1)
/// </summary>
/// <param name="id">标识</param>
[HttpGet( "{id}" )]
public virtual async Task<IActionResult> GetAsync( string id ) {
var result = await _service.GetByIdAsync( id );
return Success( result );
}
/// <summary>
/// 查询,调用范例:GET URL(/api/customers/query?name=a)
/// </summary>
/// <param name="query">查询参数</param>
[HttpGet( "Query" )]
public virtual async Task<IActionResult> QueryAsync( TQuery query ) {
var result = await _service.QueryAsync( query );
return Success( result );
}
/// <summary>
/// 分页查询,调用范例:GET URL(/api/customers?name=a)
/// </summary>
/// <param name="query">查询参数</param>
[HttpGet]
public virtual async Task<IActionResult> PagerQueryAsync( TQuery query ) {
var result = await _service.PagerQueryAsync( query );
return Success( result );
}
}
}