consolidated API endpoint for student data loading

This commit is contained in:
2026-04-08 17:10:34 -07:00
parent f798801212
commit e0a34f4c59
11 changed files with 348 additions and 101 deletions
+46
View File
@@ -97,6 +97,52 @@ public class StudentController : BaseController
});
}
[HttpGet("{idStudent:guid}/full")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<StudentFullProfileResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<StudentFullProfileResponse>), StatusCodes.Status404NotFound)]
public async Task<ActionResult<ResponseResult<StudentFullProfileResponse>>> GetFullProfile(Guid idStudent)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
if (error is not null)
{
return error;
}
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role, "all");
if (!students.Select(s => s.StudentId).Contains(idStudent))
{
return NotFound(new ResponseResult<StudentFullProfileResponse>
{
Success = false,
Message = "Student not found."
});
}
var profile = await _studentRepository.GetFullProfileAsync(idStudent);
if (profile is null)
{
return NotFound(new ResponseResult<StudentFullProfileResponse>
{
Success = false,
Message = "Student not found."
});
}
// Enrich with ownership info from the authorization query.
var match = students.Single(s => s.StudentId == idStudent);
profile.Student.OwnerName = match.OwnerName;
profile.Student.IsMine = match.IsMine;
return Ok(new ResponseResult<StudentFullProfileResponse>
{
Success = true,
Message = "Student profile retrieved successfully.",
Data = profile
});
}
[HttpGet("{idStudent:guid}/goals")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<StudentGoalSummary>), StatusCodes.Status200OK)]
@@ -0,0 +1,7 @@
namespace WinStudentGoalTracker.DataAccess;
public class dbProgressEventBenchmarkRow
{
public required Guid ProgressEventId { get; set; }
public required Guid BenchmarkId { get; set; }
}
@@ -0,0 +1,10 @@
namespace WinStudentGoalTracker.DataAccess;
public class dbProgressEventWithGoalRow
{
public required Guid ProgressEventId { get; set; }
public required Guid GoalId { get; set; }
public string? Content { get; set; }
public DateTime? CreatedAt { get; set; }
public string? CreatedByName { get; set; }
}
@@ -367,6 +367,78 @@ public class StudentRepository
return rowsAffected > 0;
}
// *****************************************************************
// Returns a full student profile: student card, goals, benchmarks,
// progress events, and benchmark/event associations in one call.
// *****************************************************************
public async Task<StudentFullProfileResponse?> GetFullProfileAsync(Guid idStudent)
{
using var db = Connection;
using var multi = await db.QueryMultipleAsync(
"sp_Student_GetFullProfile",
new { p_id_student = idStudent.ToString() },
commandType: CommandType.StoredProcedure);
// Result set 1: Student card
var student = await multi.ReadSingleOrDefaultAsync<StudentResponse>();
if (student is null) return null;
// Result set 2: Goals
var goalRows = (await multi.ReadAsync<dbStudentGoalRow>()).ToList();
// Result set 3: Benchmarks
var benchmarkRows = (await multi.ReadAsync<dbStudentBenchmarkRow>()).ToList();
// Result set 4: Progress events
var eventRows = (await multi.ReadAsync<dbProgressEventWithGoalRow>()).ToList();
// Result set 5: Benchmark/event associations
var linkRows = (await multi.ReadAsync<dbProgressEventBenchmarkRow>()).ToList();
return new StudentFullProfileResponse
{
Student = student,
Goals = goalRows.Select(r => new StudentGoalItem
{
GoalId = r.GoalId,
GoalParentId = r.GoalParentId,
Description = r.Description,
Category = r.Category,
Baseline = r.Baseline,
TargetCompletionDate = r.TargetCompletionDate,
CloseDate = r.CloseDate,
Achieved = r.Achieved,
CloseNotes = r.CloseNotes,
ProgressEventCount = r.ProgressEventCount,
BenchmarkCount = r.BenchmarkCount
}).ToList(),
Benchmarks = benchmarkRows.Select(r => new StudentBenchmarkItem
{
BenchmarkId = r.BenchmarkId,
GoalId = r.GoalId,
GoalCategory = r.GoalCategory,
Benchmark = r.Benchmark,
ShortName = r.ShortName,
CreatedByName = r.CreatedByName,
CreatedAt = r.CreatedAt,
UpdatedAt = r.UpdatedAt
}).ToList(),
ProgressEvents = eventRows.Select(r => new ProgressEventWithGoalResponse
{
ProgressEventId = r.ProgressEventId,
GoalId = r.GoalId,
Content = r.Content,
CreatedAt = r.CreatedAt,
CreatedByName = r.CreatedByName
}).ToList(),
ProgressEventBenchmarks = linkRows.Select(r => new ProgressEventBenchmarkLink
{
ProgressEventId = r.ProgressEventId,
BenchmarkId = r.BenchmarkId
}).ToList()
};
}
// *****************************************************************
// Returns a full progress report for a student within the given
// date range. Calls sp_ProgressReport_GetByStudentId which returns
@@ -0,0 +1,25 @@
namespace WinStudentGoalTracker.Models;
public class StudentFullProfileResponse
{
public required StudentResponse Student { get; set; }
public List<StudentGoalItem> Goals { get; set; } = [];
public List<StudentBenchmarkItem> Benchmarks { get; set; } = [];
public List<ProgressEventWithGoalResponse> ProgressEvents { get; set; } = [];
public List<ProgressEventBenchmarkLink> ProgressEventBenchmarks { get; set; } = [];
}
public class ProgressEventWithGoalResponse
{
public Guid ProgressEventId { get; set; }
public Guid GoalId { get; set; }
public string? Content { get; set; }
public DateTime? CreatedAt { get; set; }
public string? CreatedByName { get; set; }
}
public class ProgressEventBenchmarkLink
{
public Guid ProgressEventId { get; set; }
public Guid BenchmarkId { get; set; }
}