Skip to content

Commit

Permalink
Implement --all option
Browse files Browse the repository at this point in the history
Implements an "--all" option for the list command
and changes the default behaviour to retireve non
completed tasks only.
  • Loading branch information
mehmetseckin committed Oct 15, 2019
1 parent 116a5bd commit 0349317
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Todo.CLI/Commands/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
4 changes: 2 additions & 2 deletions src/Todo.CLI/Handlers/ListCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class ListCommandHandler
{
public static ICommandHandler Create(IServiceProvider serviceProvider)
{
return CommandHandler.Create(async () =>
return CommandHandler.Create<bool>(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);
Expand Down
2 changes: 1 addition & 1 deletion src/Todo.Core/Repository/ITodoItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace Todo.Core
public interface ITodoItemRepository
{
Task AddAsync(string subject);
Task<IEnumerable<TodoItem>> ListAsync();
Task<IEnumerable<TodoItem>> ListAsync(bool listAll);
}
}
10 changes: 8 additions & 2 deletions src/Todo.Core/Repository/TodoItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.Graph;
using Todo.Core.Model;
using TaskStatus = Microsoft.Graph.TaskStatus;

namespace Todo.Core.Repository
{
Expand All @@ -24,10 +25,15 @@ await graphServiceClient.Me.Outlook.Tasks.Request().AddAsync(new OutlookTask()
});
}

public async Task<IEnumerable<TodoItem>> ListAsync()
public async Task<IEnumerable<TodoItem>> 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
Expand Down

0 comments on commit 0349317

Please sign in to comment.