Exemplo n.º 1
0
    public async Task <JsonResult> GetTasksToReview()
    {
        if (TryGetTodoistApiKeyForCurrentRequest() is null)
        {
            throw new InvalidOperationException("Todoist API Key was not found in cookie nor env variable");
        }

        IList <TodoTask> allTasks = (await _repository.GetAllTasks());
        List <TodoTask>  tasks    = allTasks.ToList();

        // parse estimated time in a natural language
        foreach (TodoTask todoTask in tasks)
        {
            if (todoTask.content is not null)
            {
                TimespanParseResult parsedDuration = _timespanParser.Parse(todoTask.content);

                if (parsedDuration.Success)
                {
                    todoTask.SetOriginalDurationInMinutes((Int32)parsedDuration.Duration.TotalMinutes);
                }
            }
        }

        foreach (TodoTask task in tasks)
        {
            task.SaveOriginalValues();
        }

        tasks = FilterTasksAndReturnOnlyOnesThatNeedReview(tasks);

        return(Json(tasks));
    }
Exemplo n.º 2
0
    /// <inheritdoc />
    public TimespanParseResult Parse(string naturalLanguageTimeSpan)
    {
        foreach (var parser in _parsers)
        {
            var parseResult = parser.Parse(naturalLanguageTimeSpan);
            if (parseResult.Success)
            {
                return(parseResult);
            }
        }

        return(TimespanParseResult.CreateFailure());
    }