From cb56f74282547d5f314112ccab3e82a7d4dd049d Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Nov 2024 02:00:51 +1100 Subject: [PATCH] added forgotten endpoints --- blotztask-api/Controllers/TaskController.cs | 8 ++++++- blotztask-api/Services/TaskService.cs | 26 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/blotztask-api/Controllers/TaskController.cs b/blotztask-api/Controllers/TaskController.cs index b770d16..f8e56b6 100644 --- a/blotztask-api/Controllers/TaskController.cs +++ b/blotztask-api/Controllers/TaskController.cs @@ -27,7 +27,13 @@ public async Task GetTaskByID(int id) { return Ok(await _taskService.GetTaskByID(id)); } - + + [HttpGet("due-date/{date}")] + public async Task GetTaskByDate(DateOnly date) + { + return Ok(await _taskService.GetTaskByDate(date)); + } + [HttpPost] public async Task AddTask([FromBody] AddTaskItemDTO addtaskItem) { diff --git a/blotztask-api/Services/TaskService.cs b/blotztask-api/Services/TaskService.cs index 1a0b13e..afa2aae 100644 --- a/blotztask-api/Services/TaskService.cs +++ b/blotztask-api/Services/TaskService.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using BlotzTask.Data.Entities; using BlotzTask.Models.CustomError; +using System.Threading.Tasks; namespace BlotzTask.Services; @@ -13,6 +14,7 @@ public interface ITaskService public Task EditTask(int Id, EditTaskItemDTO editTaskItem); public Task AddTask(AddTaskItemDTO addtaskItem); public Task CompleteTask(int id); + public Task> GetTaskByDate(DateOnly date); } public class TaskService : ITaskService @@ -107,7 +109,7 @@ public async Task CompleteTask(int taskId) if (task == null) { - throw new NotFoundException($"Task with ID {taskId} not found."); + throw new NotFoundException($"Task with ID {taskId} was not found."); } task.IsDone = true; @@ -117,5 +119,27 @@ public async Task CompleteTask(int taskId) return taskId; } + + public async Task> GetTaskByDate(DateOnly date) + { + try + { + return await _dbContext.TaskItems + .Where(task => task.DueDate == date) + .Select(task => new TaskItemDTO + { + Id = task.Id, + Title = task.Title, + Description = task.Description, + DueDate = task.DueDate, + IsDone = task.IsDone + }) + .ToListAsync(); + } + catch (Exception ex) + { + throw new Exception($"Unhandled exception: {ex.Message}"); + } + } }