diff --git a/src/backend/server/Todo/Todo.Api/Controllers/TodosController.cs b/src/backend/server/Todo/Todo.Api/Controllers/TodosController.cs index 9259c98..2cfa88b 100644 --- a/src/backend/server/Todo/Todo.Api/Controllers/TodosController.cs +++ b/src/backend/server/Todo/Todo.Api/Controllers/TodosController.cs @@ -16,20 +16,16 @@ public class TodosController : ControllerBase } [HttpPost] - public async Task> CreateTodo([FromBody] CreateTodoRequest request) - { - var todo = await _todoRepository.CreateTodoAsync(request.Title); - - return Ok(todo); - } + public async Task> CreateTodo([FromBody] CreateTodoRequest request) => + Ok(await _todoRepository.CreateTodoAsync(request.Title)); [HttpGet] - public async Task>> GetTodos() - { - var todos = await _todoRepository.GetTodosAsync(); + public async Task>> GetTodos() => + Ok(await _todoRepository.GetTodosAsync()); - return Ok(todos); - } + [HttpGet] + public async Task>> GetNotDoneTodos() => + Ok(await _todoRepository.GetNotDoneTodos()); public record CreateTodoRequest { diff --git a/src/backend/server/Todo/Todo.Api/Hubs/TodoHub.cs b/src/backend/server/Todo/Todo.Api/Hubs/TodoHub.cs index fcc4d53..101f049 100644 --- a/src/backend/server/Todo/Todo.Api/Hubs/TodoHub.cs +++ b/src/backend/server/Todo/Todo.Api/Hubs/TodoHub.cs @@ -18,36 +18,47 @@ namespace Todo.Api.Hubs { var _ = await _todoRepository.CreateTodoAsync(todoTitle); - var todos = await _todoRepository.GetTodosAsync(); + var todos = await _todoRepository.GetNotDoneTodos(); var serializedTodos = JsonSerializer.Serialize(todos .Select(t => new TodoResponse { Id = t.Id, Title = t.Title }) .ToList()); - await Clients.Caller.SendAsync("todos", serializedTodos); + await Clients.Caller.SendAsync("getInboxTodos", serializedTodos); } - + public async Task UpdateTodo(string todoId, bool todoStatus) { await _todoRepository.UpdateTodoStatus(todoId, todoStatus); - var todos = await _todoRepository.GetTodosAsync(); + var todos = await _todoRepository.GetNotDoneTodos(); var serializedTodos = JsonSerializer.Serialize(todos .Select(t => new TodoResponse { Id = t.Id, Title = t.Title, Status = t.Status }) .ToList()); - await Clients.Caller.SendAsync("todos", serializedTodos); + await Clients.Caller.SendAsync("getInboxTodos", serializedTodos); } public async Task GetTodos() { var todos = await _todoRepository.GetTodosAsync(); var serializedTodos = JsonSerializer.Serialize(todos - .Select(t => new TodoResponse { Id = t.Id, Title = t.Title, Status = t.Status}) + .Select(t => new TodoResponse { Id = t.Id, Title = t.Title, Status = t.Status }) .ToList()); await Clients.Caller.SendAsync("todos", serializedTodos); } + + + public async Task GetInboxTodos() + { + var todos = await _todoRepository.GetNotDoneTodos(); + var serializedTodos = JsonSerializer.Serialize(todos + .Select(t => new TodoResponse { Id = t.Id, Title = t.Title, Status = t.Status }) + .ToList()); + + await Clients.Caller.SendAsync("getInboxTodos", serializedTodos); + } } } \ No newline at end of file diff --git a/src/backend/server/Todo/Todo.Core/Interfaces/Persistence/ITodoRepository.cs b/src/backend/server/Todo/Todo.Core/Interfaces/Persistence/ITodoRepository.cs index 3f5fcb9..3a722dc 100644 --- a/src/backend/server/Todo/Todo.Core/Interfaces/Persistence/ITodoRepository.cs +++ b/src/backend/server/Todo/Todo.Core/Interfaces/Persistence/ITodoRepository.cs @@ -5,4 +5,5 @@ public interface ITodoRepository Task CreateTodoAsync(string title); Task> GetTodosAsync(); Task UpdateTodoStatus(string todoId, bool todoStatus); + Task> GetNotDoneTodos(); } \ No newline at end of file diff --git a/src/backend/server/Todo/Todo.Persistence/Mongo/Repositories/TodoRepository.cs b/src/backend/server/Todo/Todo.Persistence/Mongo/Repositories/TodoRepository.cs index fed9133..daaba12 100644 --- a/src/backend/server/Todo/Todo.Persistence/Mongo/Repositories/TodoRepository.cs +++ b/src/backend/server/Todo/Todo.Persistence/Mongo/Repositories/TodoRepository.cs @@ -20,7 +20,7 @@ public class TodoRepository : ITodoRepository { var todo = new MongoTodo() { Title = title }; await _todosCollection.InsertOneAsync(todo); - return new Core.Entities.Todo() { Id = todo.Id, Title = todo.Title }; + return new Core.Entities.Todo() { Id = todo.Id, Title = todo.Title, Status = false}; } public async Task> GetTodosAsync() @@ -38,4 +38,10 @@ public class TodoRepository : ITodoRepository .UpdateOneAsync(t => t.Id == todoId, Builders.Update.Set(t => t.Status, todoStatus)); } + + public async Task> GetNotDoneTodos() + { + var todos = await GetTodosAsync(); + return todos.Where(t => t.Status == false); + } } \ No newline at end of file diff --git a/src/client/.idea/runConfigurations/dev.xml b/src/client/.idea/runConfigurations/dev.xml new file mode 100644 index 0000000..c19e5b3 --- /dev/null +++ b/src/client/.idea/runConfigurations/dev.xml @@ -0,0 +1,13 @@ + + + + + +