From d812ba682c1215b4d45e88edd284f94cd1a5b553 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 11 Nov 2025 13:47:46 -0600 Subject: [PATCH 1/9] Implemented assigning newly created task to existing list --- Web.Api/Controllers/TaskController.cs | 27 +++++++++++++++++++++++++++ Web.Api/Dto/Request/TaskCreateDto.cs | 1 + 2 files changed, 28 insertions(+) diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index 43f341b..192795b 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -99,6 +99,33 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta taskCreation.DueDate = taskCreatedDto.DueDate.Value; //enetered value } + List? userListCollection = await _unitOfWork.List.GetAllListAsync(userId); + if (taskCreatedDto.ListTitle != null && userListCollection.Count != 0) //user requested to assign task to list & user has existing list(s) + { + List? listUserChose = userListCollection.FirstOrDefault(l => l.Name == taskCreatedDto.ListTitle); + if (listUserChose != null) + { + listUserChose.TaskWithinLists.Add( + new TaskWithinList() + { + CreatedUserId = userId, + TaskItem = taskCreation, + CreatedDate = DateTime.Now + } + ); + } + else + { + //Return to user, list does not exist + return NotFound($"{ taskCreatedDto.ListTitle} list does not exist for user {userId}."); + } + } + else if (taskCreatedDto.ListTitle != null && userListCollection.Count == 0) + { + //Return to user, you have not created any lists + return BadRequest($"No lists exist under user {userId}"); + } + 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); diff --git a/Web.Api/Dto/Request/TaskCreateDto.cs b/Web.Api/Dto/Request/TaskCreateDto.cs index 14ddf46..cb9f875 100644 --- a/Web.Api/Dto/Request/TaskCreateDto.cs +++ b/Web.Api/Dto/Request/TaskCreateDto.cs @@ -5,5 +5,6 @@ public class TaskCreateDto public string Title { get; set; } public DateTime? DueDate { get; set; } public int Priority { get; set; } + public string? ListTitle { get; set; } = null; } } From 65ad71f8c4ef8fcad73e4ea0dbf14d09c2c06135 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 11 Nov 2025 16:09:13 -0600 Subject: [PATCH 2/9] Implemented movement of exisiting task to existing list --- Web.Api/Controllers/ListController.cs | 39 ++++++++++++++++++++++++-- Web.Api/Persistence/Models/TaskItem.cs | 4 +-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Web.Api/Controllers/ListController.cs b/Web.Api/Controllers/ListController.cs index 30c5d68..cf246e2 100644 --- a/Web.Api/Controllers/ListController.cs +++ b/Web.Api/Controllers/ListController.cs @@ -86,9 +86,44 @@ public async Task>> GetAllList([FromHeader] Guid [HttpPost("{listId}/move-task", Name = "MoveTaskToList")] - public Task> MoveTaskToList([FromHeader] Guid userId, Guid listId, TaskListMoveDto taskListMoveDto) + public async Task> MoveTaskToList([FromHeader] Guid userId, Guid listId, TaskListMoveDto taskListMoveDto) { - throw new NotImplementedException(); + if (!await _unitOfWork.User.IsUserInDbAsync(userId)) + { + return StatusCode(403); + } + + TaskItem? userTask = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskListMoveDto.TaskId, userId); + List? userList = await _unitOfWork.List.GetListByIdAsync(listId, userId); + if (userTask != null && userList != null) + { + if (userTask.TaskWithinLists.Count == 0) //task not assigned to a list + { + userList.TaskWithinLists.Add( + new TaskWithinList() + { + TaskListId = listId, + TaskItemId = userTask.Id, + CreatedDate = userTask.CreatedDate, + //TaskItem = userTask, + CreatedUserId = userId + } + ); + } + else //task is in a preexisting list + { + //throw new NotImplementedException(); + return BadRequest("Task already belongs to a list"); + } + + await _unitOfWork.SaveChangesAsync(); + } + else if (userList == null) + { + return BadRequest($"Requested list does not exist for user {userId}"); + } + + return Ok(listId); } } } diff --git a/Web.Api/Persistence/Models/TaskItem.cs b/Web.Api/Persistence/Models/TaskItem.cs index a8c59e2..5bf3be0 100644 --- a/Web.Api/Persistence/Models/TaskItem.cs +++ b/Web.Api/Persistence/Models/TaskItem.cs @@ -19,9 +19,9 @@ public partial class TaskItem public virtual User CreatedUser { get; set; } = null!; - public virtual ICollection SubTaskSubTaskItems { get; set; } = new List(); + public virtual ICollection SubTaskSubTaskItems { get; set; } = new List(); //children tasks - public virtual ICollection SubTaskTaskItems { get; set; } = new List(); + public virtual ICollection SubTaskTaskItems { get; set; } = new List(); //parent task public virtual ICollection TaskItemNotes { get; set; } = new List(); From 6a411287e60f1036a0bff3979724d48ca9295f53 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 11 Nov 2025 17:09:07 -0600 Subject: [PATCH 3/9] Moving task from one list to another in progress --- Web.Api/Controllers/ListController.cs | 17 +++++++++++++---- .../Persistence/Repositories/TaskItemRepo.cs | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Web.Api/Controllers/ListController.cs b/Web.Api/Controllers/ListController.cs index cf246e2..5829386 100644 --- a/Web.Api/Controllers/ListController.cs +++ b/Web.Api/Controllers/ListController.cs @@ -105,17 +105,26 @@ public async Task> MoveTaskToList([FromHeader] Guid userId TaskListId = listId, TaskItemId = userTask.Id, CreatedDate = userTask.CreatedDate, - //TaskItem = userTask, CreatedUserId = userId } ); } + //need to check if task is already in the list user wants to put it in else //task is in a preexisting list { - //throw new NotImplementedException(); - return BadRequest("Task already belongs to a list"); - } + userTask.TaskWithinLists.Clear(); //Remove list from task + //Remove task from list + List list = await _unitOfWork.List.GetAllListAsync(userId); + (list.ElementAt(0)).TaskWithinLists.Clear(); + userTask.TaskWithinLists = [ + new TaskWithinList(){ + TaskListId = listId, + CreatedDate = userTask.CreatedDate, + CreatedUserId = userTask.CreatedUserId, + } + ]; + } await _unitOfWork.SaveChangesAsync(); } else if (userList == null) diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index 38199e7..753b201 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -55,5 +55,10 @@ public void DeleteNote(TaskItemNote taskItemNote) { _context.Remove(taskItemNote); } + + public void DeleteTask(TaskItem taskItem) + { + _context.Remove(taskItem); + } } } From d0c0fba320df5f555e25e47f128d34a8e15a68a3 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Thu, 13 Nov 2025 10:08:17 -0600 Subject: [PATCH 4/9] Added elseif statement to check whether task already in requested list --- Web.Api/Controllers/ListController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Web.Api/Controllers/ListController.cs b/Web.Api/Controllers/ListController.cs index 5829386..98db989 100644 --- a/Web.Api/Controllers/ListController.cs +++ b/Web.Api/Controllers/ListController.cs @@ -110,7 +110,11 @@ public async Task> MoveTaskToList([FromHeader] Guid userId ); } //need to check if task is already in the list user wants to put it in - else //task is in a preexisting list + else if (userTask.TaskWithinLists.ElementAt(0).TaskList == userList) + { + return BadRequest("Task already exist in the list"); + } + else //task is in a different preexisting list { userTask.TaskWithinLists.Clear(); //Remove list from task //Remove task from list From 8ba46f41dae2f021924da8d3f38957c23d1e6f8b Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Thu, 13 Nov 2025 15:21:15 -0600 Subject: [PATCH 5/9] Fixed task creation with list implementation and implemented feature where you can move task from lists --- Web.Api/Controllers/ListController.cs | 42 +++++++++---------- Web.Api/Controllers/TaskController.cs | 13 +++--- Web.Api/Persistence/Repositories/ListRepo.cs | 2 + .../Persistence/Repositories/TaskItemRepo.cs | 12 +++++- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/Web.Api/Controllers/ListController.cs b/Web.Api/Controllers/ListController.cs index 98db989..de9cbbd 100644 --- a/Web.Api/Controllers/ListController.cs +++ b/Web.Api/Controllers/ListController.cs @@ -93,45 +93,43 @@ public async Task> MoveTaskToList([FromHeader] Guid userId return StatusCode(403); } - TaskItem? userTask = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskListMoveDto.TaskId, userId); - List? userList = await _unitOfWork.List.GetListByIdAsync(listId, userId); - if (userTask != null && userList != null) + TaskItem? task = await _unitOfWork.TaskItem.GetTaskByIdAsync(taskListMoveDto.TaskId, userId); + List? destinationList = await _unitOfWork.List.GetListByIdAsync(listId, userId); + if (task != null && destinationList != null) { - if (userTask.TaskWithinLists.Count == 0) //task not assigned to a list + if (task.TaskWithinLists.Count == 0) //task not assigned to a list { - userList.TaskWithinLists.Add( + destinationList.TaskWithinLists.Add( new TaskWithinList() { - TaskListId = listId, - TaskItemId = userTask.Id, - CreatedDate = userTask.CreatedDate, - CreatedUserId = userId + TaskItem = task, + CreatedUserId = userId, + CreatedDate = task.CreatedDate, } ); } - //need to check if task is already in the list user wants to put it in - else if (userTask.TaskWithinLists.ElementAt(0).TaskList == userList) + else if (task.TaskWithinLists.First().TaskList == destinationList) //check if task is already in the list user wants to put it in { return BadRequest("Task already exist in the list"); } - else //task is in a different preexisting list + else //task is currently in a different preexisting list { - userTask.TaskWithinLists.Clear(); //Remove list from task - //Remove task from list - List list = await _unitOfWork.List.GetAllListAsync(userId); - (list.ElementAt(0)).TaskWithinLists.Clear(); + //Remove connection to old list + TaskWithinList oldTaskWithinList = task.TaskWithinLists.First(); + _unitOfWork.TaskItem.DeleteTaskWithinLists(oldTaskWithinList); - userTask.TaskWithinLists = [ + //Reassign connection to destinationList + destinationList.TaskWithinLists.Add( new TaskWithinList(){ - TaskListId = listId, - CreatedDate = userTask.CreatedDate, - CreatedUserId = userTask.CreatedUserId, + TaskItem = task, + CreatedUserId = userId, + CreatedDate = task.CreatedDate, } - ]; + ); } await _unitOfWork.SaveChangesAsync(); } - else if (userList == null) + else if (destinationList == null) { return BadRequest($"Requested list does not exist for user {userId}"); } diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index 192795b..9e98d85 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -76,6 +76,8 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta //Request DTO //create a new instance of TaskItem //calls the TaskItem prop and set the task created dto to its prop + + TaskItem? taskCreation = new TaskItem() { Title = taskCreatedDto.Title, @@ -100,7 +102,7 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta } List? userListCollection = await _unitOfWork.List.GetAllListAsync(userId); - if (taskCreatedDto.ListTitle != null && userListCollection.Count != 0) //user requested to assign task to list & user has existing list(s) + if (taskCreatedDto.ListTitle != null && userListCollection.Count != 0) //user has existing list(s) { List? listUserChose = userListCollection.FirstOrDefault(l => l.Name == taskCreatedDto.ListTitle); if (listUserChose != null) @@ -110,14 +112,14 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta { CreatedUserId = userId, TaskItem = taskCreation, - CreatedDate = DateTime.Now + CreatedDate = DateTime.Now, } ); } else { //Return to user, list does not exist - return NotFound($"{ taskCreatedDto.ListTitle} list does not exist for user {userId}."); + return NotFound($"{taskCreatedDto.ListTitle} list does not exist for user {userId}."); } } else if (taskCreatedDto.ListTitle != null && userListCollection.Count == 0) @@ -126,9 +128,10 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta return BadRequest($"No lists exist under user {userId}"); } - await _unitOfWork.TaskItem.CreateTaskAsync(taskCreation); //UofW takes the TaskItem class and calls the CreateTask method from the TaskItemRepo + + 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); //Response DTO //create a new instance of TaskDto diff --git a/Web.Api/Persistence/Repositories/ListRepo.cs b/Web.Api/Persistence/Repositories/ListRepo.cs index a057205..25f3e59 100644 --- a/Web.Api/Persistence/Repositories/ListRepo.cs +++ b/Web.Api/Persistence/Repositories/ListRepo.cs @@ -31,5 +31,7 @@ public async Task> GetAllListAsync(Guid Id) { return await _context.Lists.Where(c => c.CreatedUserId == Id).ToListAsync(); } + + } } diff --git a/Web.Api/Persistence/Repositories/TaskItemRepo.cs b/Web.Api/Persistence/Repositories/TaskItemRepo.cs index 753b201..2c5e1c3 100644 --- a/Web.Api/Persistence/Repositories/TaskItemRepo.cs +++ b/Web.Api/Persistence/Repositories/TaskItemRepo.cs @@ -25,8 +25,11 @@ public TaskItemRepo(TaskManagerAppDBContext context) /// public async Task GetTaskByIdAsync(Guid taskId, Guid userId) { - 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 _context.TaskItems.Include(item => item.TaskItemNotes) + .Include(twl => twl.TaskWithinLists) + .Include(history => history.TaskItemStatusHistories) + .ThenInclude(stat => stat.Status) + .SingleOrDefaultAsync(ti => ti.Id == taskId && ti.CreatedUserId == userId); } @@ -60,5 +63,10 @@ public void DeleteTask(TaskItem taskItem) { _context.Remove(taskItem); } + + public void DeleteTaskWithinLists(TaskWithinList taskWithinLists) + { + _context.Remove(taskWithinLists); + } } } From 3a58470e6e558f38d65fb8d990843becd3f0e3f0 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 18 Nov 2025 14:05:59 -0600 Subject: [PATCH 6/9] changed requested list from string to Guid to grab exact list rather than name --- Web.Api/Controllers/TaskController.cs | 8 ++++---- Web.Api/Dto/Request/TaskCreateDto.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Web.Api/Controllers/TaskController.cs b/Web.Api/Controllers/TaskController.cs index 9e98d85..d9da668 100644 --- a/Web.Api/Controllers/TaskController.cs +++ b/Web.Api/Controllers/TaskController.cs @@ -102,9 +102,9 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta } List? userListCollection = await _unitOfWork.List.GetAllListAsync(userId); - if (taskCreatedDto.ListTitle != null && userListCollection.Count != 0) //user has existing list(s) + if (taskCreatedDto.ListId != null && userListCollection.Count != 0) //user request to add task to list & has existing list(s) { - List? listUserChose = userListCollection.FirstOrDefault(l => l.Name == taskCreatedDto.ListTitle); + List? listUserChose = userListCollection.FirstOrDefault(l => l.Id == taskCreatedDto.ListId); if (listUserChose != null) { listUserChose.TaskWithinLists.Add( @@ -119,10 +119,10 @@ public async Task> CreateTask([FromHeader] Guid userId, Ta else { //Return to user, list does not exist - return NotFound($"{taskCreatedDto.ListTitle} list does not exist for user {userId}."); + return NotFound($"{taskCreatedDto.ListId} list does not exist for user {userId}."); } } - else if (taskCreatedDto.ListTitle != null && userListCollection.Count == 0) + else if (taskCreatedDto.ListId != null && userListCollection.Count == 0) { //Return to user, you have not created any lists return BadRequest($"No lists exist under user {userId}"); diff --git a/Web.Api/Dto/Request/TaskCreateDto.cs b/Web.Api/Dto/Request/TaskCreateDto.cs index cb9f875..42d2dfd 100644 --- a/Web.Api/Dto/Request/TaskCreateDto.cs +++ b/Web.Api/Dto/Request/TaskCreateDto.cs @@ -5,6 +5,6 @@ public class TaskCreateDto public string Title { get; set; } public DateTime? DueDate { get; set; } public int Priority { get; set; } - public string? ListTitle { get; set; } = null; + public Guid? ListId { get; set; } = null; } } From bee9f56ad05e82df02b4e08bfc50f3f8e59d7175 Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 18 Nov 2025 15:07:14 -0600 Subject: [PATCH 7/9] added return for if taskid is invalid and started working on response dto --- Web.Api/Controllers/AdminController.cs | 1 + Web.Api/Controllers/ListController.cs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Web.Api/Controllers/AdminController.cs b/Web.Api/Controllers/AdminController.cs index 14b14ef..68fa08d 100644 --- a/Web.Api/Controllers/AdminController.cs +++ b/Web.Api/Controllers/AdminController.cs @@ -13,6 +13,7 @@ public class AdminController : ControllerBase private readonly StatusChange statusChange; private readonly TaskManagerAppDBContext context; const int DEFAULT_PRIORITY = 5; + private ILogger logger; public AdminController(IOptions statusChangeOptions, TaskManagerAppDBContext context, ILogger logger) diff --git a/Web.Api/Controllers/ListController.cs b/Web.Api/Controllers/ListController.cs index de9cbbd..f06503e 100644 --- a/Web.Api/Controllers/ListController.cs +++ b/Web.Api/Controllers/ListController.cs @@ -133,8 +133,27 @@ public async Task> MoveTaskToList([FromHeader] Guid userId { return BadRequest($"Requested list does not exist for user {userId}"); } + else //task is null + { + return BadRequest($"Requested task does not exist for user {userId}"); + } - return Ok(listId); + ListDto destinationListDto = new ListDto() + { + Id = destinationList.Id, + Name = destinationList.Name, + TaskItems = destinationList.TaskWithinLists.Select(twl => new TaskDto + { + Id = twl.TaskItem.Id, + Title = twl.TaskItem.Title, + DueDate = twl.TaskItem.DueDate, + Priority = twl.TaskItem.Priority, + CreatedDate = twl.TaskItem.CreatedDate, + CreatedUserId = twl.TaskItem.CreatedUserId, + }).ToArray() + }; + + return Ok(destinationListDto); } } } From e6ca9883d72b5a60c139afd077e10466e9468bcb Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 18 Nov 2025 16:13:50 -0600 Subject: [PATCH 8/9] Finished creating response body for moving tasks between lists --- Web.Api/Controllers/ListController.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Web.Api/Controllers/ListController.cs b/Web.Api/Controllers/ListController.cs index f06503e..cb8a321 100644 --- a/Web.Api/Controllers/ListController.cs +++ b/Web.Api/Controllers/ListController.cs @@ -150,6 +150,13 @@ public async Task> MoveTaskToList([FromHeader] Guid userId Priority = twl.TaskItem.Priority, CreatedDate = twl.TaskItem.CreatedDate, CreatedUserId = twl.TaskItem.CreatedUserId, + CurrentStatus = twl.TaskItem.TaskItemStatusHistories.OrderByDescending(s => s.CreatedDate) + .Select(s => new StatusDto + { + Id = s.Status.Id, + Name = s.Status.Name, + Code = s.Status.Code + }).FirstOrDefault(), }).ToArray() }; From e9a4186dba24e1db30173abcc8955fe996983fde Mon Sep 17 00:00:00 2001 From: jacieylyn Date: Tue, 2 Dec 2025 11:39:23 -0600 Subject: [PATCH 9/9] Removed extra logger variable --- Web.Api/Controllers/AdminController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Web.Api/Controllers/AdminController.cs b/Web.Api/Controllers/AdminController.cs index 1e68d1c..6cec37d 100644 --- a/Web.Api/Controllers/AdminController.cs +++ b/Web.Api/Controllers/AdminController.cs @@ -15,7 +15,6 @@ public class AdminController : ControllerBase private readonly TaskManagerAppDBContext context; private readonly ILogger logger; const int DEFAULT_PRIORITY = 5; - private ILogger logger; public AdminController(IOptions statusChangeOptions, TaskManagerAppDBContext context, ILogger logger)