Skip to content

Commit

Permalink
added forgotten endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterOu8 committed Nov 5, 2024
1 parent 13c2129 commit cb56f74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
8 changes: 7 additions & 1 deletion blotztask-api/Controllers/TaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ public async Task<IActionResult> GetTaskByID(int id)
{
return Ok(await _taskService.GetTaskByID(id));
}


[HttpGet("due-date/{date}")]
public async Task<IActionResult> GetTaskByDate(DateOnly date)
{
return Ok(await _taskService.GetTaskByDate(date));
}

[HttpPost]
public async Task<IActionResult> AddTask([FromBody] AddTaskItemDTO addtaskItem)
{
Expand Down
26 changes: 25 additions & 1 deletion blotztask-api/Services/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.EntityFrameworkCore;
using BlotzTask.Data.Entities;
using BlotzTask.Models.CustomError;
using System.Threading.Tasks;

namespace BlotzTask.Services;

Expand All @@ -13,6 +14,7 @@ public interface ITaskService
public Task<int> EditTask(int Id, EditTaskItemDTO editTaskItem);
public Task<string> AddTask(AddTaskItemDTO addtaskItem);
public Task<int> CompleteTask(int id);
public Task<List<TaskItemDTO>> GetTaskByDate(DateOnly date);
}

public class TaskService : ITaskService
Expand Down Expand Up @@ -107,7 +109,7 @@ public async Task<int> 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;
Expand All @@ -117,5 +119,27 @@ public async Task<int> CompleteTask(int taskId)

return taskId;
}

public async Task<List<TaskItemDTO>> 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}");
}
}
}

0 comments on commit cb56f74

Please sign in to comment.