Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get task from ID #49

Merged
merged 10 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.excalidraw
./vs
5 changes: 5 additions & 0 deletions blotztask-api/Controllers/TaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ public async Task<IActionResult> GetAllTask()
{
return Ok(await _taskService.GetTodoItems());
}
[HttpGet("{id}")]
public async Task<IActionResult> GetTaskByID(int id)
{
return Ok(await _taskService.GetTaskByID(id));
}
}
}
6 changes: 5 additions & 1 deletion blotztask-api/Models/TaskItemDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
{
public class TaskItemDTO
{
public string DisplayId { get; set; }
public int Id { get; set; }
public string Title { get; set; }

Check warning on line 6 in blotztask-api/Models/TaskItemDTO.cs

View workflow job for this annotation

GitHub Actions / build-and-test-backend

Non-nullable property 'Title' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in blotztask-api/Models/TaskItemDTO.cs

View workflow job for this annotation

GitHub Actions / build-and-test-backend

Non-nullable property 'Title' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Description { get; set; }

Check warning on line 7 in blotztask-api/Models/TaskItemDTO.cs

View workflow job for this annotation

GitHub Actions / build-and-test-backend

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in blotztask-api/Models/TaskItemDTO.cs

View workflow job for this annotation

GitHub Actions / build-and-test-backend

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool IsDone { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
16 changes: 15 additions & 1 deletion blotztask-api/Services/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public interface ITaskService
{
public Task<List<TaskItemDTO>> GetTodoItems();
public Task<TaskItemDTO> GetTaskByID(int Id);
}

public class TaskService : ITaskService
Expand All @@ -25,16 +26,29 @@
return await _dbContext.TaskItems
.Select(x => new TaskItemDTO
{
DisplayId = $"Task-{x.Id}",
Id = x.Id,
Title = x.Title
})
.ToListAsync();
}
catch (Exception ex)

Check warning on line 34 in blotztask-api/Services/TaskService.cs

View workflow job for this annotation

GitHub Actions / build-and-test-backend

The variable 'ex' is declared but never used

Check warning on line 34 in blotztask-api/Services/TaskService.cs

View workflow job for this annotation

GitHub Actions / build-and-test-backend

The variable 'ex' is declared but never used
{
//TODO: Add some error log throw (havent create PBI)
throw;
}
}
public async Task<TaskItemDTO> GetTaskByID(int Id)
{

var taskItems = new List<TaskItemDTO>
sguming marked this conversation as resolved.
Show resolved Hide resolved
{
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 }
};

return await Task.FromResult(taskItems[Id]);
}

}

Loading