Skip to content

Commit

Permalink
Implement add command
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetseckin committed Oct 15, 2019
1 parent 9f4cc4a commit c33562f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Todo.CLI/Commands/AddCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Text;
using Todo.CLI.Handlers;

namespace Todo.CLI.Commands
{
public class AddCommand : Command
{
public AddCommand(IServiceProvider serviceProvider) : base("add")
{
Description = "Adds a to do item.";

AddArgument(GetSubjectArgument());

Handler = AddCommandHandler.Create(serviceProvider);
}

private Argument GetSubjectArgument()
{
return new Argument("subject")
{
Description = "The subject of the new to do item.",
ArgumentType = typeof(string)
};
}
}
}
1 change: 1 addition & 0 deletions src/Todo.CLI/Commands/TodoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public TodoCommand(IServiceProvider serviceProvider)
Handler = TodoCommandHandler.Create();

// Add subcommands
AddCommand(new AddCommand(serviceProvider));
AddCommand(new ListCommand(serviceProvider));
}

Expand Down
21 changes: 21 additions & 0 deletions src/Todo.CLI/Handlers/AddCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Reflection;
using Todo.Core;

namespace Todo.CLI.Handlers
{
public class AddCommandHandler
{
public static ICommandHandler Create(IServiceProvider serviceProvider)
{
return CommandHandler.Create<string>(async (subject) =>
{
var todoItemRepository = (ITodoItemRepository)serviceProvider.GetService(typeof(ITodoItemRepository));
await todoItemRepository.AddAsync(subject);
});
}
}
}
2 changes: 1 addition & 1 deletion src/Todo.CLI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ClientId": "5c594999-30b1-4a68-afcf-56ce11715b4d",
"Scopes": [
"user.read",
"tasks.read"
"tasks.readwrite"
]
}
}
1 change: 1 addition & 0 deletions src/Todo.Core/Repository/ITodoItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Todo.Core
{
public interface ITodoItemRepository
{
Task AddAsync(string subject);
Task<IEnumerable<TodoItem>> ListAsync();
}
}
9 changes: 9 additions & 0 deletions src/Todo.Core/Repository/TodoItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public TodoItemRepository(IAuthenticationProvider authenticationProvider)
{
}

public async Task AddAsync(string subject)
{
var graphServiceClient = new GraphServiceClient(AuthenticationProvider);
await graphServiceClient.Me.Outlook.Tasks.Request().AddAsync(new OutlookTask()
{
Subject = subject
});
}

public async Task<IEnumerable<TodoItem>> ListAsync()
{
var graphServiceClient = new GraphServiceClient(AuthenticationProvider);
Expand Down

0 comments on commit c33562f

Please sign in to comment.