diff --git a/src/Todo.CLI/Handlers/ListCommandHandler.cs b/src/Todo.CLI/Handlers/ListCommandHandler.cs index 60f30c1..f5e5add 100644 --- a/src/Todo.CLI/Handlers/ListCommandHandler.cs +++ b/src/Todo.CLI/Handlers/ListCommandHandler.cs @@ -13,7 +13,7 @@ public static ICommandHandler Create(IServiceProvider serviceProvider) { return CommandHandler.Create(async () => { - var todoItemRetriever = (ITodoItemRetriever)serviceProvider.GetService(typeof(ITodoItemRetriever)); + var todoItemRetriever = (ITodoItemRepository)serviceProvider.GetService(typeof(ITodoItemRepository)); var todoItems = await todoItemRetriever.ListAsync(); foreach (var item in todoItems) { diff --git a/src/Todo.CLI/Program.cs b/src/Todo.CLI/Program.cs index 92be320..205c4e3 100644 --- a/src/Todo.CLI/Program.cs +++ b/src/Todo.CLI/Program.cs @@ -9,6 +9,7 @@ using Todo.Core; using Microsoft.Graph; using Todo.CLI.Auth; +using Todo.Core.Repository; namespace Todo.CLI { @@ -25,7 +26,7 @@ static int Main(string[] args) var services = new ServiceCollection() .AddSingleton(typeof(TodoCliConfiguration), todoCliConfig) - .AddTransient(factory => new TodoItemRetriever(TodoCliAuthenticationProviderFactory.GetAuthenticationProvider(factory))); + .AddTransient(factory => new TodoItemRepository(TodoCliAuthenticationProviderFactory.GetAuthenticationProvider(factory))); var serviceProvider = services.BuildServiceProvider(); diff --git a/src/Todo.Core/Model/TodoItem.cs b/src/Todo.Core/Model/TodoItem.cs new file mode 100644 index 0000000..b317cd2 --- /dev/null +++ b/src/Todo.Core/Model/TodoItem.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Todo.Core.Model +{ + public class TodoItem + { + public string Subject { get; set; } + } +} diff --git a/src/Todo.Core/ITodoItemRetriever.cs b/src/Todo.Core/Repository/ITodoItemRepository.cs similarity index 58% rename from src/Todo.Core/ITodoItemRetriever.cs rename to src/Todo.Core/Repository/ITodoItemRepository.cs index bf8af56..d7397cc 100644 --- a/src/Todo.Core/ITodoItemRetriever.cs +++ b/src/Todo.Core/Repository/ITodoItemRepository.cs @@ -3,11 +3,12 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using Todo.Core.Model; namespace Todo.Core { - public interface ITodoItemRetriever + public interface ITodoItemRepository { - Task> ListAsync(); + Task> ListAsync(); } } diff --git a/src/Todo.Core/Repository/RepositoryBase.cs b/src/Todo.Core/Repository/RepositoryBase.cs new file mode 100644 index 0000000..ca9364b --- /dev/null +++ b/src/Todo.Core/Repository/RepositoryBase.cs @@ -0,0 +1,17 @@ +using Microsoft.Graph; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Todo.Core.Repository +{ + public abstract class RepositoryBase + { + protected IAuthenticationProvider AuthenticationProvider { get; } + + public RepositoryBase(IAuthenticationProvider authenticationProvider) + { + AuthenticationProvider = authenticationProvider; + } + } +} diff --git a/src/Todo.Core/Repository/TodoItemRepository.cs b/src/Todo.Core/Repository/TodoItemRepository.cs new file mode 100644 index 0000000..2a19f21 --- /dev/null +++ b/src/Todo.Core/Repository/TodoItemRepository.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Graph; +using Todo.Core.Model; + +namespace Todo.Core.Repository +{ + public class TodoItemRepository : RepositoryBase, ITodoItemRepository + { + public TodoItemRepository(IAuthenticationProvider authenticationProvider) + : base(authenticationProvider) + { + } + + public async Task> ListAsync() + { + var graphServiceClient = new GraphServiceClient(AuthenticationProvider); + var tasks = await graphServiceClient.Me.Outlook.Tasks.Request().GetAsync(); + return tasks.Select(task => new TodoItem() + { + Subject = task.Subject + }); + } + } +} diff --git a/src/Todo.Core/TodoItemRetriever.cs b/src/Todo.Core/TodoItemRetriever.cs deleted file mode 100644 index e43e7d3..0000000 --- a/src/Todo.Core/TodoItemRetriever.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Graph; - -namespace Todo.Core -{ - public class TodoItemRetriever : ITodoItemRetriever - { - private IAuthenticationProvider AuthenticationProvider { get; } - - public TodoItemRetriever(IAuthenticationProvider authenticationProvider) - { - AuthenticationProvider = authenticationProvider; - } - - public async Task> ListAsync() - { - var graphServiceClient = new GraphServiceClient(AuthenticationProvider); - return await graphServiceClient.Me.Outlook.Tasks.Request().GetAsync(); - } - } -}