Updates to encompass benchmarks

This commit is contained in:
ivan-pelly
2026-03-07 16:10:55 -08:00
parent 69e96403f4
commit 3d531298e2
65 changed files with 2505 additions and 86 deletions
+148
View File
@@ -130,6 +130,39 @@ public class StudentController : BaseController
});
}
[HttpGet("{idStudent:guid}/benchmarks")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<StudentBenchmarkSummary>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<StudentBenchmarkSummary>), StatusCodes.Status404NotFound)]
public async Task<ActionResult<ResponseResult<StudentBenchmarkSummary>>> GetBenchmarks(Guid idStudent)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
if (error is not null)
{
return error;
}
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
if (!students.Select(s => s.StudentId).Contains(idStudent))
{
return NotFound(new ResponseResult<StudentBenchmarkSummary>
{
Success = false,
Message = "Student not found."
});
}
var summary = await _studentRepository.GetBenchmarkSummaryAsync(idStudent);
return Ok(new ResponseResult<StudentBenchmarkSummary>
{
Success = true,
Message = "Benchmarks retrieved successfully.",
Data = summary
});
}
[HttpPost("{idStudent:guid}/goals")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<StudentGoalItem>), StatusCodes.Status201Created)]
@@ -205,6 +238,38 @@ public class StudentController : BaseController
});
}
[HttpPut("{idStudent:guid}/goals/{idGoal:guid}")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<object>), StatusCodes.Status404NotFound)]
public async Task<ActionResult<ResponseResult<object>>> UpdateGoal(Guid idStudent, Guid idGoal, [FromBody] UpdateGoalDto dto)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
if (error is not null)
{
return error;
}
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
if (!students.Select(s => s.StudentId).Contains(idStudent))
{
return NotFound(new ResponseResult<object>
{
Success = false,
Message = "Student not found."
});
}
var updated = await _studentRepository.UpdateGoalAsync(idGoal, dto);
return Ok(new ResponseResult<object>
{
Success = true,
Message = updated ? "Goal updated successfully." : "No changes were applied."
});
}
[HttpPost("{idStudent:guid}/progress-event")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult), StatusCodes.Status201Created)]
@@ -411,4 +476,87 @@ public class StudentController : BaseController
Message = "Student deleted."
});
}
[HttpPost("{idStudent:guid}/benchmarks")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<StudentBenchmarkItem>), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ResponseResult<StudentBenchmarkItem>), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ResponseResult<StudentBenchmarkItem>), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ResponseResult<StudentBenchmarkItem>>> CreateBenchmark(Guid idStudent, [FromBody] CreateBenchmarkDto dto)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
if (error is not null)
{
return error;
}
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
if (!students.Select(s => s.StudentId).Contains(idStudent))
{
return NotFound(new ResponseResult<StudentBenchmarkItem>
{
Success = false,
Message = "Student not found."
});
}
if (!PermissionService.IsAllowed(role, EntityType.Benchmark, PermissionAction.Create, isMine: true))
{
return BadRequest(new ResponseResult<StudentBenchmarkItem>
{
Success = false,
Message = "Unable to create benchmark. - Permission Matrix"
});
}
var created = await _studentRepository.InsertBenchmarkAsync(dto.GoalId, userId, dto);
if (created is null)
{
return BadRequest(new ResponseResult<StudentBenchmarkItem>
{
Success = false,
Message = "Unable to create benchmark."
});
}
return StatusCode(StatusCodes.Status201Created, new ResponseResult<StudentBenchmarkItem>
{
Success = true,
Message = "Benchmark created successfully.",
Data = created
});
}
[HttpPut("{idStudent:guid}/benchmarks/{idBenchmark:guid}")]
[Authorize(Roles = $"{UserRoles.Teacher}")]
[ProducesResponseType(typeof(ResponseResult<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<object>), StatusCodes.Status404NotFound)]
public async Task<ActionResult<ResponseResult<object>>> UpdateBenchmark(Guid idStudent, Guid idBenchmark, [FromBody] UpdateBenchmarkDto dto)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
if (error is not null)
{
return error;
}
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
if (!students.Select(s => s.StudentId).Contains(idStudent))
{
return NotFound(new ResponseResult<object>
{
Success = false,
Message = "Student not found."
});
}
var updated = await _studentRepository.UpdateBenchmarkAsync(idBenchmark, dto.Benchmark);
return Ok(new ResponseResult<object>
{
Success = true,
Message = updated ? "Changes applied successfully." : "No changes were applied."
});
}
}