diff --git a/blotztask-api/Services/TaskService.cs b/blotztask-api/Services/TaskService.cs index 2450029..1a0b13e 100644 --- a/blotztask-api/Services/TaskService.cs +++ b/blotztask-api/Services/TaskService.cs @@ -44,15 +44,25 @@ public async Task> GetTodoItems() } public async Task GetTaskByID(int Id) { - - var taskItems = new List - { - new TaskItemDTO { Id = 0, Title = "Task 0", Description = "Description for Task 1", IsDone = false, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }, - new TaskItemDTO { Id = 1, Title = "Task 1", Description = "Description for Task 2", IsDone = true, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }, - new TaskItemDTO { Id = 2, Title = "Task 2", Description = "Description for Task 3", IsDone = false, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now } - }; + var task = await _dbContext.TaskItems.FindAsync(Id); + + if (task == null) + { + throw new NotFoundException($"Task with ID {Id} not found."); + } + + var result = new TaskItemDTO() + { + Id = task.Id, + Title = task.Title, + Description = task.Description, + DueDate = task.DueDate, + IsDone = task.IsDone, + CreatedAt = task.CreatedAt, + UpdatedAt = task.UpdatedAt + }; - return await Task.FromResult(taskItems[Id]); + return result; } public async Task AddTask(AddTaskItemDTO addtaskItem)