-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathGetMessages2Controller.cs
More file actions
60 lines (56 loc) · 2.06 KB
/
Copy pathGetMessages2Controller.cs
File metadata and controls
60 lines (56 loc) · 2.06 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
60
namespace ServiceControl.Audit.Auditing.MessagesView;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Infrastructure;
using Infrastructure.WebApi;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Persistence;
using ServiceControl.Infrastructure.Auth;
[ApiController]
[Route("api")]
public class GetMessages2Controller(IAuditDataStore dataStore) : ControllerBase
{
[Authorize(Policy = Permissions.AuditMessageView)]
[Route("messages2")]
[HttpGet]
public async Task<IList<MessagesView>> GetAllMessages(
[FromQuery] SortInfo sortInfo,
[FromQuery(Name = "page_size")] int pageSize,
[FromQuery(Name = "endpoint_name")] string endpointName,
[FromQuery(Name = "from")] string from,
[FromQuery(Name = "to")] string to,
string q,
CancellationToken cancellationToken)
{
QueryResult<IList<MessagesView>> result;
var pagingInfo = new PagingInfo(pageSize: pageSize);
if (string.IsNullOrWhiteSpace(endpointName))
{
if (string.IsNullOrWhiteSpace(q))
{
result = await dataStore.GetMessages(false, pagingInfo, sortInfo, new DateTimeRange(from, to), cancellationToken);
}
else
{
result = await dataStore.QueryMessages(q, pagingInfo, sortInfo, new DateTimeRange(from, to), cancellationToken);
}
}
else
{
if (string.IsNullOrWhiteSpace(q))
{
result = await dataStore.QueryMessagesByReceivingEndpoint(false, endpointName, pagingInfo, sortInfo,
new DateTimeRange(from, to), cancellationToken);
}
else
{
result = await dataStore.QueryMessagesByReceivingEndpointAndKeyword(endpointName, q, pagingInfo,
sortInfo, new DateTimeRange(from, to), cancellationToken);
}
}
Response.WithTotalCount(result.QueryStats.TotalCount);
return result.Results;
}
}