From 0349317c2d55a52f8653882410d50d2b754e8170 Mon Sep 17 00:00:00 2001 From: Mehmet Seckin Date: Tue, 15 Oct 2019 20:34:19 +0000 Subject: [PATCH] Implement --all option Implements an "--all" option for the list command and changes the default behaviour to retireve non completed tasks only. --- src/Todo.CLI/Commands/ListCommand.cs | 7 +++++++ src/Todo.CLI/Handlers/ListCommandHandler.cs | 4 ++-- src/Todo.Core/Repository/ITodoItemRepository.cs | 2 +- src/Todo.Core/Repository/TodoItemRepository.cs | 10 ++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Todo.CLI/Commands/ListCommand.cs b/src/Todo.CLI/Commands/ListCommand.cs index fd0c0bf..f0a363e 100644 --- a/src/Todo.CLI/Commands/ListCommand.cs +++ b/src/Todo.CLI/Commands/ListCommand.cs @@ -11,7 +11,14 @@ public ListCommand(IServiceProvider serviceProvider) : base("list") { Description = "Retrieves a list of the to do items."; + AddOption(GetAllOption()); + Handler = ListCommandHandler.Create(serviceProvider); } + + private Option GetAllOption() + { + return new Option(new string[] { "-a", "--all" }, "Lists all to do items including the completed ones."); + } } } \ No newline at end of file diff --git a/src/Todo.CLI/Handlers/ListCommandHandler.cs b/src/Todo.CLI/Handlers/ListCommandHandler.cs index f5e5add..2b17fc9 100644 --- a/src/Todo.CLI/Handlers/ListCommandHandler.cs +++ b/src/Todo.CLI/Handlers/ListCommandHandler.cs @@ -11,10 +11,10 @@ public class ListCommandHandler { public static ICommandHandler Create(IServiceProvider serviceProvider) { - return CommandHandler.Create(async () => + return CommandHandler.Create(async (all) => { var todoItemRetriever = (ITodoItemRepository)serviceProvider.GetService(typeof(ITodoItemRepository)); - var todoItems = await todoItemRetriever.ListAsync(); + var todoItems = await todoItemRetriever.ListAsync(all); foreach (var item in todoItems) { Console.WriteLine(item.Subject); diff --git a/src/Todo.Core/Repository/ITodoItemRepository.cs b/src/Todo.Core/Repository/ITodoItemRepository.cs index 03051c7..e1d67b1 100644 --- a/src/Todo.Core/Repository/ITodoItemRepository.cs +++ b/src/Todo.Core/Repository/ITodoItemRepository.cs @@ -10,6 +10,6 @@ namespace Todo.Core public interface ITodoItemRepository { Task AddAsync(string subject); - Task> ListAsync(); + Task> ListAsync(bool listAll); } } diff --git a/src/Todo.Core/Repository/TodoItemRepository.cs b/src/Todo.Core/Repository/TodoItemRepository.cs index a5e149d..f09607c 100644 --- a/src/Todo.Core/Repository/TodoItemRepository.cs +++ b/src/Todo.Core/Repository/TodoItemRepository.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.Graph; using Todo.Core.Model; +using TaskStatus = Microsoft.Graph.TaskStatus; namespace Todo.Core.Repository { @@ -24,10 +25,15 @@ await graphServiceClient.Me.Outlook.Tasks.Request().AddAsync(new OutlookTask() }); } - public async Task> ListAsync() + public async Task> ListAsync(bool listAll) { var graphServiceClient = new GraphServiceClient(AuthenticationProvider); - var tasks = await graphServiceClient.Me.Outlook.Tasks.Request().GetAsync(); + var request = graphServiceClient.Me.Outlook.Tasks.Request(); + if(!listAll) + { + request.Filter($"status ne '{TaskStatus.Completed.ToString().ToLower()}'"); + } + var tasks = await request.GetAsync(); return tasks.Select(task => new TodoItem() { Subject = task.Subject