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

Finish DeleteTaskByID #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion blotztask-api/Controllers/TaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,22 @@ public async Task<IActionResult> GetTaskByID(int id)
{
return Ok(await _taskService.GetTaskByID(id));
}


[HttpDelete("{id}")]
public async Task<IActionResult> DeleteTaskByID(int id)
{
var result = await _taskService.DeleteTaskByID(id);

if (result)
{
return Ok($"Task with ID {id} has been successfully deleted");
}
else
{
return NotFound($"Task with ID {id} not found");
}
}

[HttpPost]
public async Task<IActionResult> AddTask([FromBody] AddTaskItemDTO addtaskItem)
{
Expand Down
16 changes: 15 additions & 1 deletion blotztask-api/Services/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
{
public Task<List<TaskItemDTO>> GetTodoItems();
public Task<TaskItemDTO> GetTaskByID(int Id);
public Task<int> EditTask(int Id, EditTaskItemDTO editTaskItem);
public Task<bool> DeleteTaskByID(int Id);

public Task<int> EditTask(int Id, EditTaskItemDTO editTaskItem);
public Task<string> AddTask(AddTaskItemDTO addtaskItem);
}

Expand All @@ -35,7 +37,7 @@
})
.ToListAsync();
}
catch (Exception ex)

Check warning on line 40 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;
Expand All @@ -53,6 +55,18 @@

return await Task.FromResult(taskItems[Id]);
}
public async Task<bool> DeleteTaskByID(int Id)
{
var taskItem = await _dbContext.TaskItems.FindAsync(Id);
if (taskItem == null)
{
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of return true false, can you return meaning full string message ?

}

_dbContext.TaskItems.Remove(taskItem);
await _dbContext.SaveChangesAsync();
return true;
}

public async Task<string> AddTask(AddTaskItemDTO addtaskItem)
{
Expand Down
3 changes: 2 additions & 1 deletion blotztask-api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"DefaultConnection": "data source=localhost;initial catalog=BlotzTaskAppDb;trusted_connection=true;TrustServerCertificate=True"
"DefaultConnection": "Server=DESKTOP-O3H0KT0;Database=BlotzTaskAppDb;Trusted_Connection=True;TrustServerCertificate=True;"

},
"Serilog": {
"MinimumLevel": {
Expand Down
Loading