Exemple #1
0
 public async Task <IActionResult> GetAsync([FromQuery] ReportInputDto reportInputDto, [FromQuery] string token)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(await ReportService.GetReport(reportInputDto)));
 }
Exemple #2
0
        public async Task <IEnumerable <ReportResultDto> > GetReport(ReportInputDto reportInput)
        {
            var lexeme   = GetLexeme(reportInput.Lexeme);
            var language = GetLanguage(reportInput.LanguageId);

            if (lexeme == null)
            {
                return(new List <ReportResultDto>());
            }

            var fromDate = reportInput.FromDate.StartOfDay();
            var toDate   = reportInput.ToDate.EndOfDay();

            var reportDates         = SplitReport(fromDate, toDate);
            var existingReportItems = AnalysisService.LoadExistingReportItems(fromDate, toDate, lexeme, language);

            var reportItems = new List <ReportItem>();

            foreach (var reportDate in reportDates)
            {
                var existing = existingReportItems.Where(ri => ri.FromDate == reportDate);
                if (existing.Any())
                {
                    reportItems.AddRange(existing);
                }
                else
                {
                    var newReportItems = await AnalysisService.GenerateReportAsync(reportDate, lexeme, language);

                    reportItems.AddRange(AnalysisService.SaveReportItems(newReportItems));
                    ;
                }
            }

            reportItems = reportItems.OrderBy(ri => ri.FromDate).ToList();

            return(reportItems.Select(r => new ReportResultDto(r)));
        }