diff --git a/src/backend/server/src/Todo.Api/Controllers/TodosController.cs b/src/backend/server/src/Todo.Api/Controllers/TodosController.cs index 2cfa88b..a5fdc9f 100644 --- a/src/backend/server/src/Todo.Api/Controllers/TodosController.cs +++ b/src/backend/server/src/Todo.Api/Controllers/TodosController.cs @@ -17,7 +17,7 @@ public class TodosController : ControllerBase [HttpPost] public async Task> CreateTodo([FromBody] CreateTodoRequest request) => - Ok(await _todoRepository.CreateTodoAsync(request.Title)); + Ok(await _todoRepository.CreateTodoAsync(request.Title, String.Empty)); [HttpGet] public async Task>> GetTodos() => diff --git a/src/backend/server/src/Todo.Api/Hubs/Models/TodoResponse.cs b/src/backend/server/src/Todo.Api/Hubs/Models/TodoResponse.cs index ae5d28a..ca9f681 100644 --- a/src/backend/server/src/Todo.Api/Hubs/Models/TodoResponse.cs +++ b/src/backend/server/src/Todo.Api/Hubs/Models/TodoResponse.cs @@ -11,5 +11,8 @@ public record TodoResponse public string Title { get; init; } [JsonPropertyName("status")] - public bool Status { get; init; } + public bool Status { get; init; } + + [JsonPropertyName("project")] + public string Project { get; set; } } \ No newline at end of file diff --git a/src/backend/server/src/Todo.Api/Hubs/TodoHub.cs b/src/backend/server/src/Todo.Api/Hubs/TodoHub.cs index 101f049..59a6523 100644 --- a/src/backend/server/src/Todo.Api/Hubs/TodoHub.cs +++ b/src/backend/server/src/Todo.Api/Hubs/TodoHub.cs @@ -14,14 +14,14 @@ namespace Todo.Api.Hubs _todoRepository = todoRepository; } - public async Task CreateTodo(string todoTitle) + public async Task CreateTodo(string todoTitle, string projectName) { - var _ = await _todoRepository.CreateTodoAsync(todoTitle); + var _ = await _todoRepository.CreateTodoAsync(todoTitle, projectName); var todos = await _todoRepository.GetNotDoneTodos(); var serializedTodos = JsonSerializer.Serialize(todos - .Select(t => new TodoResponse { Id = t.Id, Title = t.Title }) + .Select(t => new TodoResponse { Id = t.Id, Title = t.Title, Project = t.Project }) .ToList()); await Clients.Caller.SendAsync("getInboxTodos", serializedTodos); @@ -34,7 +34,8 @@ namespace Todo.Api.Hubs var todos = await _todoRepository.GetNotDoneTodos(); 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, Project = t.Project }) .ToList()); await Clients.Caller.SendAsync("getInboxTodos", serializedTodos); @@ -44,7 +45,7 @@ namespace Todo.Api.Hubs { 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, Project = t.Project }) .ToList()); await Clients.Caller.SendAsync("todos", serializedTodos); @@ -55,7 +56,7 @@ namespace Todo.Api.Hubs { var todos = await _todoRepository.GetNotDoneTodos(); 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, Project = t.Project }) .ToList()); await Clients.Caller.SendAsync("getInboxTodos", serializedTodos); diff --git a/src/backend/server/src/Todo.Core/Entities/Todo.cs b/src/backend/server/src/Todo.Core/Entities/Todo.cs index ef0c713..11e8b24 100644 --- a/src/backend/server/src/Todo.Core/Entities/Todo.cs +++ b/src/backend/server/src/Todo.Core/Entities/Todo.cs @@ -5,4 +5,5 @@ public record Todo public string Id { get; init; } public string Title { get; init; } public bool Status { get; init; } + public string Project { get; init; } } \ No newline at end of file diff --git a/src/backend/server/src/Todo.Core/Interfaces/Persistence/ITodoRepository.cs b/src/backend/server/src/Todo.Core/Interfaces/Persistence/ITodoRepository.cs index 3a722dc..149ccf0 100644 --- a/src/backend/server/src/Todo.Core/Interfaces/Persistence/ITodoRepository.cs +++ b/src/backend/server/src/Todo.Core/Interfaces/Persistence/ITodoRepository.cs @@ -2,7 +2,7 @@ namespace Todo.Core.Interfaces.Persistence; public interface ITodoRepository { - Task CreateTodoAsync(string title); + Task CreateTodoAsync(string title, string projectName); Task> GetTodosAsync(); Task UpdateTodoStatus(string todoId, bool todoStatus); Task> GetNotDoneTodos(); diff --git a/src/backend/server/src/Todo.Persistence/Mongo/Repositories/Dtos/MongoTodo.cs b/src/backend/server/src/Todo.Persistence/Mongo/Repositories/Dtos/MongoTodo.cs index 7f291f1..c9d645e 100644 --- a/src/backend/server/src/Todo.Persistence/Mongo/Repositories/Dtos/MongoTodo.cs +++ b/src/backend/server/src/Todo.Persistence/Mongo/Repositories/Dtos/MongoTodo.cs @@ -11,4 +11,5 @@ public record MongoTodo [BsonRequired] public string Title { get; init; } [BsonRequired] public bool Status { get; set; } + public string ProjectName { get; set; } = String.Empty; } \ No newline at end of file diff --git a/src/backend/server/src/Todo.Persistence/Mongo/Repositories/TodoRepository.cs b/src/backend/server/src/Todo.Persistence/Mongo/Repositories/TodoRepository.cs index b475b39..ccc7c5e 100644 --- a/src/backend/server/src/Todo.Persistence/Mongo/Repositories/TodoRepository.cs +++ b/src/backend/server/src/Todo.Persistence/Mongo/Repositories/TodoRepository.cs @@ -15,11 +15,12 @@ public class TodoRepository : ITodoRepository _todosCollection = database.GetCollection("todos"); } - public async Task CreateTodoAsync(string title) + public async Task CreateTodoAsync(string title, string projectName) { - var todo = new MongoTodo() { Title = title }; + var todo = new MongoTodo() { Title = title, ProjectName = projectName }; await _todosCollection.InsertOneAsync(todo); - return new Core.Entities.Todo() { Id = todo.Id, Title = todo.Title, Status = false}; + return new Core.Entities.Todo() + { Id = todo.Id, Title = todo.Title, Status = false, Project = todo.ProjectName }; } public async Task> GetTodosAsync() @@ -28,14 +29,14 @@ public class TodoRepository : ITodoRepository return todos .ToEnumerable() .Select(t => - new Core.Entities.Todo() { Id = t.Id, Title = t.Title, Status = t.Status}); + new Core.Entities.Todo() { Id = t.Id, Title = t.Title, Status = t.Status, Project = t.ProjectName }); } public async Task UpdateTodoStatus(string todoId, bool todoStatus) { await _todosCollection .UpdateOneAsync(t => t.Id == todoId, - Builders.Update.Set(t => t.Status, todoStatus)); + Builders.Update.Set(t => t.Status, todoStatus)); } public async Task> GetNotDoneTodos() diff --git a/src/client/src/components/todos/addTodo.tsx b/src/client/src/components/todos/addTodo.tsx index 83b0b0d..5020210 100644 --- a/src/client/src/components/todos/addTodo.tsx +++ b/src/client/src/components/todos/addTodo.tsx @@ -21,8 +21,8 @@ export function AddTodo(props: {}) { return ( { - createTodo(todoName); + onAdd={(todoName, project) => { + createTodo(todoName, project); }} onClose={() => setCollapsed(CollapsedState.collapsed)} /> diff --git a/src/client/src/components/todos/collapsed/addTodoForm.tsx b/src/client/src/components/todos/collapsed/addTodoForm.tsx index 9677962..132a371 100644 --- a/src/client/src/components/todos/collapsed/addTodoForm.tsx +++ b/src/client/src/components/todos/collapsed/addTodoForm.tsx @@ -1,30 +1,43 @@ import { FC, useState } from "react"; export const AddTodoForm: FC<{ - onAdd: (todoName: string) => void; + onAdd: (todoName: string, project: string) => void; onClose: () => void; }> = ({ onAdd, onClose }) => { const [todoName, setTodoName] = useState(""); + const [project, setProject] = useState(""); return (
{ e.preventDefault(); - onAdd(todoName); + onAdd(todoName, project); setTodoName(""); }} >
-
- setTodoName(e.target.value)} - /> +
+
+ setTodoName(e.target.value)} + /> +
+
+ setProject(e.target.value)} + /> +