public async Task <IActionResult> CatchUp([FromBody] string apiKey) { if (string.IsNullOrWhiteSpace(apiKey) || apiKey != _settings.ApiKey) { return(BadRequest(new string[] { Strings.NotAuthorized })); } var beanids = await _beanService.BeanIdsAsync(); var lowestDate = await _movementService.LowestDateAsync(); if (lowestDate == default) { return(Ok()); } var messages = new List <string>(); foreach (var beanid in beanids) { var result = await _movementService.CatchupAsync(beanid, _settings.MinimumValue, lowestDate); if (!result.Successful) { messages.Add(result.ErrorMessage()); } } if (messages.Any()) { return(BadRequest(messages.ToArray())); } return(Ok()); }
public static async Task <IResult> Catchup([FromBody] string key, IMovementService movementService, IBeanService beanService, IOptions <AppSettings> settings) { List <string> messages = new(); if (key != settings.Value.ApiKey) { return(Results.BadRequest(new ApiError(Strings.NotAuthorized))); } var beanids = await beanService.BeanIdsAsync(); var lowestDate = await movementService.LowestDateAsync(); if (lowestDate == default) { return(Results.Ok()); } foreach (var beanid in beanids) { var result = await movementService.CatchupAsync(beanid, settings.Value.MinimumValue, lowestDate); if (!result.Successful) { messages.Add(result.ErrorMessage()); } } if (messages.Any()) { return(Results.BadRequest(new ApiError(messages.ToArray()))); } return(Results.Ok()); }