-
Notifications
You must be signed in to change notification settings - Fork 48
New endpoint to support migration of SI to SP #4918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace ServiceControl.Audit.Infrastructure; | ||
|
|
||
| using System; | ||
| using System.Globalization; | ||
|
|
||
| public class DateTimeRange | ||
| { | ||
| public DateTime? From { get; } | ||
| public DateTime? To { get; } | ||
|
|
||
| public DateTimeRange(string from = null, string to = null) | ||
| { | ||
| if (from != null) | ||
| { | ||
| From = DateTime.Parse(from, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); | ||
| } | ||
| if (to != null) | ||
| { | ||
| To = DateTime.Parse(to, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); | ||
| } | ||
| } | ||
|
|
||
| public DateTimeRange(DateTime? from = null, DateTime? to = null) | ||
| { | ||
| From = from; | ||
| To = to; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||
| namespace ServiceControl.Audit.Auditing.MessagesView; | ||||||||||||||||
|
|
||||||||||||||||
| using System.Collections.Generic; | ||||||||||||||||
| using System.Threading; | ||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||
| using Infrastructure; | ||||||||||||||||
| using Infrastructure.WebApi; | ||||||||||||||||
| using Microsoft.AspNetCore.Mvc; | ||||||||||||||||
| using Persistence; | ||||||||||||||||
|
|
||||||||||||||||
| [ApiController] | ||||||||||||||||
| [Route("api")] | ||||||||||||||||
| public class GetMessages2Controller(IAuditDataStore dataStore) : ControllerBase | ||||||||||||||||
|
Comment on lines
+11
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be possible to use This is just pseudo typing but it would then become something like:
Suggested change
This also allows for a more clean usage of the deprecated API later on.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this PR
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ramonsmits I am not too concerned with api versioning given that we control the clients and this is not a publicly documented api so we can evolve it anyway we want as long our clients do not break. |
||||||||||||||||
| { | ||||||||||||||||
| [Route("messages2")] | ||||||||||||||||
johnsimons marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| [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; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception handling for invalid date string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exceptions in REST apis are hard, they don't really bubble to the UI,
So not sure what can we do better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is that this is currently throwing an exception. At least ignore the value if it's not valid so that the client still receives data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then they don't know they made a mistake, and they would get unexpected results.
This is a tricky topic that, unfortunately, our REST API does not handle well.
So, I am cautious about introducing a new pattern that is not well thought out.