This commit is contained in:
2026-03-04 17:08:03 -08:00
parent 6e73012430
commit 69f68cc391
9 changed files with 136 additions and 6 deletions
+43
View File
@@ -246,6 +246,49 @@ public class StudentController : BaseController
});
}
[HttpGet("goals/{idGoal:guid}/progress-events")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<IEnumerable<ProgressEventResponse>>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<IEnumerable<ProgressEventResponse>>), StatusCodes.Status404NotFound)]
public async Task<ActionResult<ResponseResult<IEnumerable<ProgressEventResponse>>>> GetProgressEventsForGoal(Guid idGoal)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
if (error is not null)
{
return error;
}
var studentId = await _studentRepository.GetStudentIdForGoalAsync(idGoal);
if (!studentId.HasValue)
{
return NotFound(new ResponseResult<IEnumerable<ProgressEventResponse>>
{
Success = false,
Message = "Goal not found."
});
}
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
if (!students.Select(s => s.StudentId).Contains(studentId.Value))
{
return NotFound(new ResponseResult<IEnumerable<ProgressEventResponse>>
{
Success = false,
Message = "Goal not found."
});
}
var progressEvents = await _studentRepository.GetProgressEventsForGoalAsync(idGoal);
return Ok(new ResponseResult<IEnumerable<ProgressEventResponse>>
{
Success = true,
Message = "Progress events retrieved successfully.",
Data = progressEvents
});
}
[HttpPost]
[Authorize(Roles = $"{UserRoles.Teacher}")]
[ProducesResponseType(typeof(ResponseResult<StudentResponse>), StatusCodes.Status201Created)]
@@ -0,0 +1,6 @@
namespace WinStudentGoalTracker.DataAccess;
public class dbGoalStudentRow
{
public Guid StudentId { get; set; }
}
@@ -0,0 +1,9 @@
namespace WinStudentGoalTracker.DataAccess;
public class dbProgressEventRow
{
public required Guid ProgressEventId { get; set; }
public string? Content { get; set; }
public DateTime? CreatedAt { get; set; }
public string? CreatedByName { get; set; }
}
@@ -101,6 +101,37 @@ public class StudentRepository
return row is not null;
}
public async Task<Guid?> GetStudentIdForGoalAsync(Guid idGoal)
{
using var db = Connection;
var row = await db.QuerySingleOrDefaultAsync<dbGoalStudentRow>(
"sp_Goal_GetById",
new { p_id_goal = idGoal.ToString() },
commandType: CommandType.StoredProcedure);
return row?.StudentId;
}
public async Task<IEnumerable<ProgressEventResponse>> GetProgressEventsForGoalAsync(Guid idGoal)
{
using var db = Connection;
var rows = await db.QueryAsync<dbProgressEventRow>(
"sp_ProgressEvent_GetByGoalId",
new
{
p_id_goal = idGoal.ToString()
},
commandType: CommandType.StoredProcedure);
return rows.Select(r => new ProgressEventResponse
{
ProgressEventId = r.ProgressEventId,
Content = r.Content,
CreatedAt = r.CreatedAt,
CreatedByName = r.CreatedByName
});
}
public async Task<StudentGoalItem?> InsertGoalAsync(Guid idStudent, Guid userId, CreateGoalDto dto)
{
var newGoalId = Guid.NewGuid();
@@ -0,0 +1,9 @@
namespace WinStudentGoalTracker.Models;
public class ProgressEventResponse
{
public Guid ProgressEventId { get; set; }
public string? Content { get; set; }
public DateTime? CreatedAt { get; set; }
public string? CreatedByName { get; set; }
}