Skip to content

Commit

Permalink
Implement get task by id without mock (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterOu8 authored Oct 31, 2024
1 parent f350a63 commit 465a19a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions blotztask-api/Services/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@ public async Task<List<TaskItemDTO>> GetTodoItems()
}
public async Task<TaskItemDTO> GetTaskByID(int Id)
{

var taskItems = new List<TaskItemDTO>
{
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<string> AddTask(AddTaskItemDTO addtaskItem)
Expand Down

0 comments on commit 465a19a

Please sign in to comment.