From 512dd18a41eda25062bb7de0a785a91035e9800b Mon Sep 17 00:00:00 2001 From: sguming Date: Sat, 24 Aug 2024 05:57:24 +0930 Subject: [PATCH 1/3] Finish --- blotztask-api/Controllers/TaskController.cs | 5 +++++ blotztask-api/Services/TaskService.cs | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/blotztask-api/Controllers/TaskController.cs b/blotztask-api/Controllers/TaskController.cs index 214e2bf..b686441 100644 --- a/blotztask-api/Controllers/TaskController.cs +++ b/blotztask-api/Controllers/TaskController.cs @@ -23,5 +23,10 @@ public async Task GetTaskByID(int id) { return Ok(await _taskService.GetTaskByID(id)); } + [HttpDelete("{id}")] + public async Task DeteleTaskByID(int id) + { + return Ok(await _taskService.DeleteTaskByID(id)); + } } } diff --git a/blotztask-api/Services/TaskService.cs b/blotztask-api/Services/TaskService.cs index 1054ed1..3affd63 100644 --- a/blotztask-api/Services/TaskService.cs +++ b/blotztask-api/Services/TaskService.cs @@ -8,6 +8,7 @@ public interface ITaskService { public Task> GetTodoItems(); public Task GetTaskByID(int Id); + public Task DeleteTaskByID(int Id); } public class TaskService : ITaskService @@ -49,6 +50,18 @@ public async Task GetTaskByID(int Id) return await Task.FromResult(taskItems[Id]); } + public async Task DeleteTaskByID(int Id) + { + var taskItem = await _dbContext.TaskItems.FindAsync(Id); + if (taskItem == null) + { + return false; + } + + _dbContext.TaskItems.Remove(taskItem); + await _dbContext.SaveChangesAsync(); + return true; + } } From a795ae9387d75f8dd0771b37199ec949a522ff61 Mon Sep 17 00:00:00 2001 From: sguming Date: Sat, 12 Oct 2024 05:14:50 +1030 Subject: [PATCH 2/3] change --- blotztask-api/Controllers/TaskController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/blotztask-api/Controllers/TaskController.cs b/blotztask-api/Controllers/TaskController.cs index 16e1fb5..45e7912 100644 --- a/blotztask-api/Controllers/TaskController.cs +++ b/blotztask-api/Controllers/TaskController.cs @@ -30,6 +30,7 @@ public async Task GetTaskByID(int id) public async Task DeteleTaskByID(int id) { return Ok(await _taskService.DeleteTaskByID(id)); + } [HttpPost] public async Task AddTask([FromBody] AddTaskItemDTO addtaskItem) From a13ad3e82843edec870ef9a01ef978a587556a46 Mon Sep 17 00:00:00 2001 From: sguming Date: Sat, 12 Oct 2024 05:44:36 +1030 Subject: [PATCH 3/3] token needed --- blotztask-api/Controllers/TaskController.cs | 15 ++++++++++++--- blotztask-api/appsettings.json | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/blotztask-api/Controllers/TaskController.cs b/blotztask-api/Controllers/TaskController.cs index 45e7912..fb74860 100644 --- a/blotztask-api/Controllers/TaskController.cs +++ b/blotztask-api/Controllers/TaskController.cs @@ -27,11 +27,20 @@ public async Task GetTaskByID(int id) } [HttpDelete("{id}")] - public async Task DeteleTaskByID(int id) + public async Task DeleteTaskByID(int id) { - return Ok(await _taskService.DeleteTaskByID(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 AddTask([FromBody] AddTaskItemDTO addtaskItem) { diff --git a/blotztask-api/appsettings.json b/blotztask-api/appsettings.json index 1501a09..a76bc21 100644 --- a/blotztask-api/appsettings.json +++ b/blotztask-api/appsettings.json @@ -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": {