From 231bdab22395bbe585ac14f0e9a6fc7b560d4e52 Mon Sep 17 00:00:00 2001 From: Oliver Pelly Date: Mon, 2 Mar 2026 17:24:47 -0800 Subject: [PATCH] parent id fix --- api/src/Controllers/StudentController.cs | 24 +++++++++++++++++++ .../DataTransferObjects/CreateGoalDto.cs | 1 + .../Repositories/StudentRepository.cs | 1 + .../add-goal-modal/add-goal-modal.html | 12 ++++++++++ .../add-goal-modal/add-goal-modal.scss | 11 +++++++-- .../add-goal-modal/add-goal-modal.ts | 8 ++++++- .../components/goal-list/goal-list.html | 15 ++++++++---- .../components/goal-list/goal-list.scss | 7 ++++++ .../src/app/shared/classes/create-goal.dto.ts | 1 + 9 files changed, 72 insertions(+), 8 deletions(-) diff --git a/api/src/Controllers/StudentController.cs b/api/src/Controllers/StudentController.cs index 11f12f6..52f1e98 100644 --- a/api/src/Controllers/StudentController.cs +++ b/api/src/Controllers/StudentController.cs @@ -163,6 +163,30 @@ public class StudentController : BaseController }); } + if (dto.GoalParentId.HasValue) + { + var summary = await _studentRepository.GetGoalSummaryAsync(idStudent); + var parentGoal = summary?.Goals.FirstOrDefault(g => g.GoalId == dto.GoalParentId.Value); + + if (parentGoal is null) + { + return BadRequest(new ResponseResult + { + Success = false, + Message = "Parent goal not found." + }); + } + + if (parentGoal.GoalParentId.HasValue) + { + return BadRequest(new ResponseResult + { + Success = false, + Message = "The selected parent goal already has a parent." + }); + } + } + var created = await _studentRepository.InsertGoalAsync(idStudent, userId, dto); if (created is null) { diff --git a/api/src/DataAccess/Models/DataTransferObjects/CreateGoalDto.cs b/api/src/DataAccess/Models/DataTransferObjects/CreateGoalDto.cs index be3c3ec..4dad0a3 100644 --- a/api/src/DataAccess/Models/DataTransferObjects/CreateGoalDto.cs +++ b/api/src/DataAccess/Models/DataTransferObjects/CreateGoalDto.cs @@ -5,4 +5,5 @@ public class CreateGoalDto public string? Title { get; set; } public string? Description { get; set; } public string? Category { get; set; } + public Guid? GoalParentId { get; set; } } diff --git a/api/src/DataAccess/Repositories/StudentRepository.cs b/api/src/DataAccess/Repositories/StudentRepository.cs index 126d70e..a9d44d1 100644 --- a/api/src/DataAccess/Repositories/StudentRepository.cs +++ b/api/src/DataAccess/Repositories/StudentRepository.cs @@ -110,6 +110,7 @@ public class StudentRepository new { p_id_goal = newGoalId.ToString(), + p_id_goal_parent = dto.GoalParentId?.ToString(), p_id_student = idStudent.ToString(), p_id_user = userId.ToString(), p_title = dto.Title, diff --git a/ui/winstudentgoaltracker/src/app/desktop/components/add-goal-modal/add-goal-modal.html b/ui/winstudentgoaltracker/src/app/desktop/components/add-goal-modal/add-goal-modal.html index 3af25da..e820cbd 100644 --- a/ui/winstudentgoaltracker/src/app/desktop/components/add-goal-modal/add-goal-modal.html +++ b/ui/winstudentgoaltracker/src/app/desktop/components/add-goal-modal/add-goal-modal.html @@ -32,6 +32,18 @@ /> + @if (parentGoalOptions().length > 0) { +
+ + +
+ } +