From 9f72588a255a1dbbcb67c293cd65f0322cd79998 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Thu, 4 Dec 2025 14:03:34 -0600 Subject: [PATCH 1/6] added conditional .Include()'s for each sub-table in GetTaskById --- Web.Api/Persistence/Repositories/TaskItemRepo.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index 6d08cba..d963205 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -22,10 +22,13 @@ public TaskItemRepo(TaskManagerAppDBContext context) /// /// /// - public async Task GetTaskByIdAsync(Guid taskId, Guid userId) + public async Task GetTaskByIdAsync(Guid taskId, Guid userId, bool includeNotes, bool includeStatus, bool include) { - return await _context.TaskItems.Include(item => item.TaskItemNotes).Include(history => history.TaskItemStatusHistories) - .ThenInclude(stat => stat.Status).SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + TaskItem task; + if () + + //return await _context.TaskItems.Include(item => item.TaskItemNotes).Include(history => history.TaskItemStatusHistories) + // .ThenInclude(stat => stat.Status).SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } public async Task CreateTaskAsync(TaskItem taskItem) From e17c20df652f66bf899f4ecd322cd43df298d68b Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Thu, 4 Dec 2025 14:03:50 -0600 Subject: [PATCH 2/6] ^ --- .../Persistence/Repositories/TaskItemRepo.cs | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index d963205..d9cfe9f 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -22,13 +22,32 @@ public TaskItemRepo(TaskManagerAppDBContext context) /// /// /// - public async Task GetTaskByIdAsync(Guid taskId, Guid userId, bool includeNotes, bool includeStatus, bool include) + public async Task GetTaskByIdAsync(Guid taskId, Guid userId, bool includeNotes, bool includeTaskinLists, bool includeStatusHist, bool includeParent, bool includeChildren) { - TaskItem task; - if () + IQueryable query = _context.TaskItems; + if (includeNotes) + { + query = query.Include(task => task.TaskItemNotes); + } + if(includeTaskinLists) + { + query = query.Include(task => task.TaskWithinLists); + } + if(includeStatusHist) + { + query = query.Include(task => task.TaskItemStatusHistories) + .ThenInclude(stat => stat.Status); + } + if (includeParent) + { + query = query.Include(task => task.SubTaskTaskItems); + } + if (includeChildren) + { + query = query.Include(task => task.SubTaskSubTaskItems); + } - //return await _context.TaskItems.Include(item => item.TaskItemNotes).Include(history => history.TaskItemStatusHistories) - // .ThenInclude(stat => stat.Status).SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + return await query.FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } public async Task CreateTaskAsync(TaskItem taskItem) From 09782373fe88d69ab19ff43dced6dcb7d724cf11 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Thu, 4 Dec 2025 14:16:46 -0600 Subject: [PATCH 3/6] Updated all GetTaskById references --- Web.Api/Controllers/TaskController.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index dd364fa..f2042f6 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -35,7 +35,7 @@ public async Task> GetTaskById([FromHeader] Guid userId, G return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, true, false, false); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -115,7 +115,7 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta await _unitOfWork.TaskItem.CreateTaskAsync(taskCreation); //UofW takes the TaskItem class and calls the CreateTask method from the TaskItemRepo await _unitOfWork.SaveChangesAsync(); //UofW calls the SaveChanges method - taskCreation = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskCreation.Id, userId); + taskCreation = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskCreation.Id, userId, true, false, true, false, false); _logger.LogInformation($"Task Creation is Successfull for userId {userId}"); @@ -169,7 +169,7 @@ public async Task> CreateNote([FromHeader] Guid user return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, false, false, false, false, false); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -221,7 +221,7 @@ public async Task> DeleteNote([FromHeader] Guid userId, Gu return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, false, false, false); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -264,7 +264,7 @@ public async Task> DeleteTaskById([FromHeader] Guid userId _logger.LogWarning ($"User id {userId} not authorized"); return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, false, false, false, false, false); if (taskItem is null) { _logger.LogWarning($"Task item {taskId} not found for user {userId}"); @@ -318,7 +318,7 @@ public async Task> StatusChangeComplete([FromHeader] Guid return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, true, false, false); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -389,7 +389,7 @@ public async Task> EditTask([FromHeader] Guid userId, Guid return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, true, false, false); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); From c4f3956378c4e113e97eb47d0026cb60779496a4 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Fri, 5 Dec 2025 13:53:37 -0600 Subject: [PATCH 4/6] Changed GetTaskById into seperate methods --- Web.Api/Controllers/TaskController.cs | 12 ++--- .../Persistence/Repositories/TaskItemRepo.cs | 44 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index f2042f6..e66e61e 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -354,12 +354,12 @@ public async Task> StatusChangeComplete([FromHeader] Guid CreatedUser = n.CreatedUserId }).ToList(), - CurrentStatus = new StatusDto - { - Id = _statusChange.CompleteId, - Name = _statusChange.Complete, - Code = _statusChange.Code2 - }, + CurrentStatus = new StatusDto + { + Id = _statusChange.CompleteId, + Name = _statusChange.Complete, + Code = _statusChange.Code2 + }, CreatedDate = taskItem.CreatedDate, CreatedUserId = taskItem.CreatedUserId, diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index d9cfe9f..1ccf2d7 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -22,32 +22,28 @@ public TaskItemRepo(TaskManagerAppDBContext context) /// /// /// - public async Task GetTaskByIdAsync(Guid taskId, Guid userId, bool includeNotes, bool includeTaskinLists, bool includeStatusHist, bool includeParent, bool includeChildren) + + public async Task GetTaskByIdAsync(Guid userId, Guid taskId) { - IQueryable query = _context.TaskItems; - if (includeNotes) - { - query = query.Include(task => task.TaskItemNotes); - } - if(includeTaskinLists) - { - query = query.Include(task => task.TaskWithinLists); - } - if(includeStatusHist) - { - query = query.Include(task => task.TaskItemStatusHistories) - .ThenInclude(stat => stat.Status); - } - if (includeParent) - { - query = query.Include(task => task.SubTaskTaskItems); - } - if (includeChildren) - { - query = query.Include(task => task.SubTaskSubTaskItems); - } + return await _context.TaskItems.FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + } + + public async Task GetTaskNotesByIdAsync(Guid taskId, Guid userId) + { + return await _context.TaskItems.Include(task => task.TaskItemNotes).FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + } - return await query.FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + public async Task GetTaskTaskWithinListsByIdAsync(Guid taskId, Guid userId) + { + return await _context.TaskItems.Include(task => task.TaskWithinLists).FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + } + + public async Task GetTaskNotesAndStatusByIdAsync(Guid taskId, Guid userId) + { + return await _context.TaskItems.Include(task => task.TaskItemNotes) + .Include(task => task.TaskItemStatusHistories) + .ThenInclude(stat => stat.Status) + .FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } public async Task CreateTaskAsync(TaskItem taskItem) From 80268cf9195efa072a71a2641319c87cb874bad9 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Fri, 5 Dec 2025 14:50:54 -0600 Subject: [PATCH 5/6] Updated TaskController with newly implemented GetTaskById methods --- Web.Api/Controllers/TaskController.cs | 16 ++++++++-------- Web.Api/Persistence/Repositories/TaskItemRepo.cs | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index e66e61e..2663a46 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -35,8 +35,8 @@ public async Task> GetTaskById([FromHeader] Guid userId, G return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, true, false, false); - if (taskItem is null) + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskNotesAndStatusByIdAsync(taskId, userId); + if(taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); return NotFound(taskId); @@ -115,7 +115,7 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta await _unitOfWork.TaskItem.CreateTaskAsync(taskCreation); //UofW takes the TaskItem class and calls the CreateTask method from the TaskItemRepo await _unitOfWork.SaveChangesAsync(); //UofW calls the SaveChanges method - taskCreation = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskCreation.Id, userId, true, false, true, false, false); + taskCreation = await _unitOfWork.TaskItem.GetTaskNotesAndStatusByIdAsync(taskCreation.Id, userId); _logger.LogInformation($"Task Creation is Successfull for userId {userId}"); @@ -169,7 +169,7 @@ public async Task> CreateNote([FromHeader] Guid user return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, false, false, false, false, false); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -221,7 +221,7 @@ public async Task> DeleteNote([FromHeader] Guid userId, Gu return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, false, false, false); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskNotesByIdAsync(taskId, userId); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -264,7 +264,7 @@ public async Task> DeleteTaskById([FromHeader] Guid userId _logger.LogWarning ($"User id {userId} not authorized"); return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, false, false, false, false, false); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskNotesAndStatusByIdAsync(taskId, userId); if (taskItem is null) { _logger.LogWarning($"Task item {taskId} not found for user {userId}"); @@ -318,7 +318,7 @@ public async Task> StatusChangeComplete([FromHeader] Guid return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, true, false, false); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskNotesAndStatusByIdAsync(taskId, userId); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); @@ -389,7 +389,7 @@ public async Task> EditTask([FromHeader] Guid userId, Guid return StatusCode(403); } - TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskId, userId, true, false, true, false, false); + TaskItem? taskItem = await _unitOfWork.TaskItem.GetTaskNotesAndStatusByIdAsync(taskId, userId); if (taskItem is null) { _logger.LogWarning($"TaskId {taskId} not found for UserId {userId}"); diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index 1ccf2d7..2626e0b 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -23,19 +23,19 @@ public TaskItemRepo(TaskManagerAppDBContext context) /// /// - public async Task GetTaskByIdAsync(Guid userId, Guid taskId) + public async Task GetTaskByIdAsync(Guid taskId, Guid userId) { - return await _context.TaskItems.FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); - } + return await _context.TaskItems.SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + } public async Task GetTaskNotesByIdAsync(Guid taskId, Guid userId) { - return await _context.TaskItems.Include(task => task.TaskItemNotes).FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + return await _context.TaskItems.Include(task => task.TaskItemNotes).SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } public async Task GetTaskTaskWithinListsByIdAsync(Guid taskId, Guid userId) { - return await _context.TaskItems.Include(task => task.TaskWithinLists).FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + return await _context.TaskItems.Include(task => task.TaskWithinLists).SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } public async Task GetTaskNotesAndStatusByIdAsync(Guid taskId, Guid userId) @@ -43,7 +43,7 @@ public TaskItemRepo(TaskManagerAppDBContext context) return await _context.TaskItems.Include(task => task.TaskItemNotes) .Include(task => task.TaskItemStatusHistories) .ThenInclude(stat => stat.Status) - .FirstOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); + .SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } public async Task CreateTaskAsync(TaskItem taskItem) From ff3bef6bf8f007f8b6cf283f1fee3ae1886476b4 Mon Sep 17 00:00:00 2001 From: JCruz6725 Date: Tue, 13 Jan 2026 15:54:47 -0600 Subject: [PATCH 6/6] Added ParentId to get task by id. --- Web.Api/Controllers/TaskController.cs | 1 + Web.Api/Dto/Response/TaskDto.cs | 1 + Web.Api/Persistence/Repositories/TaskItemRepo.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index 2663a46..2fce4d7 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -50,6 +50,7 @@ public async Task> GetTaskById([FromHeader] Guid userId, G Priority = taskItem.Priority, CreatedDate = taskItem.CreatedDate, CreatedUserId = taskItem.CreatedUserId, + ParentId = taskItem.SubTaskSubTaskItems.SingleOrDefault()?.TaskItemId, Notes = taskItem.TaskItemNotes.Select //within the TaskDto create a new List of Notes that grabs TaskItemNotes and set their properties (note => new NoteDto //create new instance of NoteDto { diff --git a/Web.Api/Dto/Response/TaskDto.cs b/Web.Api/Dto/Response/TaskDto.cs index 0fff8a9..41345d5 100644 --- a/Web.Api/Dto/Response/TaskDto.cs +++ b/Web.Api/Dto/Response/TaskDto.cs @@ -11,5 +11,6 @@ public class TaskDto public List StatusHistories { get; set; } = []; public DateTime CreatedDate { get; set; } public Guid CreatedUserId { get; set; } + public Guid? ParentId { get; set; } } } diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index 2626e0b..79f62d9 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -41,6 +41,7 @@ public TaskItemRepo(TaskManagerAppDBContext context) public async Task GetTaskNotesAndStatusByIdAsync(Guid taskId, Guid userId) { return await _context.TaskItems.Include(task => task.TaskItemNotes) + .Include(task => task.SubTaskSubTaskItems) .Include(task => task.TaskItemStatusHistories) .ThenInclude(stat => stat.Status) .SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId);