Exemple #1
0
        public async Task <IEnumerable <DocumentToAnalysisResponse> > GetDocumentsToAnalysis(Guid userId)
        {
            var allAnalysisEvents = await _facade.GetAllUserDocumentAnalysesAsync(userId);

            DocumentAnalysisStatusChangedEvent GetInitialEvent(Guid docId) =>
            allAnalysisEvents.First(e => e.Status == OperationStatus.NotInitialized && e.DocumentId == docId);

            var documents = allAnalysisEvents
                            .Where(e => e.Status is OperationStatus.NotStarted or OperationStatus.NotInitialized or OperationStatus.Failed)
                            .GroupBy(e => e.DocumentId)
                            .Select(group => group.OrderByDescending(e => e.OccurenceDate).First())
                            .Select(e => e with {
                DocumentName = GetInitialEvent(e.DocumentId).DocumentName
            });;
Exemple #2
0
        public async Task <List <AnalysisStatusDto> > GetUserAnalysesAsync(Guid userId)
        {
            var allAnalysesEvents = await _facade.GetAllUserDocumentAnalysesAsync(userId);


            DocumentAnalysisStatusChangedEvent GetInitialEvent(Guid docId) =>
            allAnalysesEvents.FirstOrDefault(e => e.Status == OperationStatus.NotStarted && e.DocumentId == docId);

            var analysesAndRelatedEvents = allAnalysesEvents
                                           .Where(a => a.Status != OperationStatus.NotStarted && !a.TaskId.Equals(Guid.Empty))
                                           .GroupBy(a => a.TaskId);


            return(analysesAndRelatedEvents.Select(events =>
                                                   events.OrderByDescending(e => e.OccurenceDate).First())
                   .Select(latestEvent => new AnalysisStatusDto(latestEvent))
                   .Select(a => a with {
                DocumentName = GetInitialEvent(a.DocumentId)?.DocumentName ?? "No info"
            })