-
Notifications
You must be signed in to change notification settings - Fork 46
/
GetMessagesController.cs
104 lines (92 loc) · 4.45 KB
/
GetMessagesController.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
namespace ServiceControl.Audit.Auditing.MessagesView
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Infrastructure;
using Infrastructure.WebApi;
using Microsoft.AspNetCore.Mvc;
using Persistence;
[ApiController]
[Route("api")]
public class GetMessagesController(IAuditDataStore dataStore) : ControllerBase
{
[Route("messages")]
[HttpGet]
public async Task<IList<MessagesView>> GetAllMessages([FromQuery] PagingInfo pagingInfo, [FromQuery] SortInfo sortInfo, [FromQuery(Name = "include_system_messages")] bool includeSystemMessages)
{
var result = await dataStore.GetMessages(includeSystemMessages, pagingInfo, sortInfo);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
[Route("endpoints/{endpoint}/messages")]
[HttpGet]
public async Task<IList<MessagesView>> GetEndpointMessages([FromQuery] PagingInfo pagingInfo, [FromQuery] SortInfo sortInfo, [FromQuery(Name = "include_system_messages")] bool includeSystemMessages, string endpoint)
{
var result = await dataStore.QueryMessagesByReceivingEndpoint(includeSystemMessages, endpoint, pagingInfo, sortInfo);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
[Route("endpoints/{endpoint}/audit-count")]
[HttpGet]
public async Task<IList<AuditCount>> GetEndpointAuditCounts([FromQuery] PagingInfo pagingInfo, string endpoint)
{
var result = await dataStore.QueryAuditCounts(endpoint);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
[Route("messages/{id}/body")]
[HttpGet]
public async Task<IActionResult> Get(string id)
{
var result = await dataStore.GetMessageBody(id);
if (result.Found == false)
{
return NotFound();
}
if (result.HasContent == false)
{
return NoContent();
}
if (result.StringContent == null && result.StreamContent == null)
{
throw new Exception($"Metadata for message '{id}' indicated that a body was present but no content could be found in storage");
}
Response.Headers.ETag = result.ETag;
var contentType = result.ContentType ?? "text/*";
return result.StringContent != null ? Content(result.StringContent, contentType) : File(result.StreamContent, contentType);
}
[Route("messages/search")]
[HttpGet]
public async Task<IList<MessagesView>> Search([FromQuery] PagingInfo pagingInfo, [FromQuery] SortInfo sortInfo, string q)
{
var result = await dataStore.QueryMessages(q, pagingInfo, sortInfo);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
[Route("messages/search/{keyword}")]
[HttpGet]
public async Task<IList<MessagesView>> SearchByKeyWord([FromQuery] PagingInfo pagingInfo, [FromQuery] SortInfo sortInfo, string keyword)
{
var result = await dataStore.QueryMessages(keyword, pagingInfo, sortInfo);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
[Route("endpoints/{endpoint}/messages/search")]
[HttpGet]
public async Task<IList<MessagesView>> Search([FromQuery] PagingInfo pagingInfo, [FromQuery] SortInfo sortInfo, string endpoint, string q)
{
var result = await dataStore.QueryMessagesByReceivingEndpointAndKeyword(endpoint, q, pagingInfo, sortInfo);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
[Route("endpoints/{endpoint}/messages/search/{keyword}")]
[HttpGet]
public async Task<IList<MessagesView>> SearchByKeyword([FromQuery] PagingInfo pagingInfo, [FromQuery] SortInfo sortInfo, string endpoint, string keyword)
{
var result = await dataStore.QueryMessagesByReceivingEndpointAndKeyword(endpoint, keyword, pagingInfo, sortInfo);
Response.WithQueryStatsAndPagingInfo(result.QueryStats, pagingInfo);
return result.Results;
}
}
}