lots of work done

This commit is contained in:
2026-03-02 16:23:29 -08:00
parent be4873283d
commit ef09a76bb4
25 changed files with 644 additions and 157 deletions
+75 -1
View File
@@ -97,11 +97,85 @@ public class StudentController : BaseController
});
}
[HttpGet("{idStudent:guid}/goals")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult<StudentGoalSummary>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<StudentGoalSummary>), StatusCodes.Status404NotFound)]
public async Task<ActionResult<ResponseResult<StudentGoalSummary>>> GetGoals(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<StudentGoalSummary>
{
Success = false,
Message = "Student not found."
});
}
var summary = await _studentRepository.GetGoalSummaryAsync(idStudent);
return Ok(new ResponseResult<StudentGoalSummary>
{
Success = true,
Message = "Goals retrieved successfully.",
Data = summary
});
}
[HttpPost("{idStudent:guid}/progress-event")]
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
[ProducesResponseType(typeof(ResponseResult), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ResponseResult), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ResponseResult), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ResponseResult>> AddProgressEvent(Guid idStudent, [FromBody] AddProgressEventDto 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
{
Success = false,
Message = "Student not found."
});
}
var created = await _studentRepository.AddProgressEventAsync(userId, dto);
if (!created)
{
return BadRequest(new ResponseResult
{
Success = false,
Message = "Unable to add progress event."
});
}
return StatusCode(StatusCodes.Status201Created, new ResponseResult
{
Success = true,
Message = "Progress event added successfully."
});
}
[HttpPost]
[Authorize(Roles = $"{UserRoles.Teacher}")]
[ProducesResponseType(typeof(ResponseResult<StudentResponse>), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ResponseResult<StudentResponse>), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ResponseResult<StudentResponse>>> Create([FromBody] CreateStudentDto newStudentData)
public async Task<ActionResult<ResponseResult<StudentResponse>>> CreateStudent([FromBody] CreateStudentDto newStudentData)
{
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
@@ -0,0 +1,8 @@
namespace WinStudentGoalTracker.DataAccess;
public class AddProgressEventDto
{
public Guid GoalId { get; set; }
public string? Content { get; set; }
public bool IsSensitive { get; set; }
}
@@ -0,0 +1,12 @@
namespace WinStudentGoalTracker.DataAccess;
public class dbStudentGoalRow
{
public string? StudentIdentifier { get; set; }
public required Guid GoalId { get; set; }
public Guid? GoalParentId { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public int ProgressEventCount { get; set; }
}
@@ -83,4 +83,48 @@ public class StudentRepository
commandType: CommandType.StoredProcedure);
return rowsAffected > 0;
}
public async Task<bool> AddProgressEventAsync(Guid userId, AddProgressEventDto dto)
{
using var db = Connection;
var rowsAffected = await db.ExecuteAsync(
"sp_ProgressEvent_Insert",
new
{
p_id_progress_event = Guid.NewGuid().ToString(),
p_id_goal = dto.GoalId.ToString(),
p_id_user_created = userId.ToString(),
p_content = dto.Content,
p_is_sensitive = dto.IsSensitive ? 1 : 0
},
commandType: CommandType.StoredProcedure);
return rowsAffected > 0;
}
public async Task<StudentGoalSummary?> GetGoalSummaryAsync(Guid idStudent)
{
using var db = Connection;
var rows = await db.QueryAsync<dbStudentGoalRow>(
"sp_Goal_GetByStudentId",
new { p_id_student = idStudent.ToString() },
commandType: CommandType.StoredProcedure);
var list = rows.ToList();
if (list.Count == 0) return null;
return new StudentGoalSummary
{
StudentIdentifier = list[0].StudentIdentifier,
Goals = list.Select(r => new StudentGoalItem
{
GoalId = r.GoalId,
GoalParentId = r.GoalParentId,
Title = r.Title,
Description = r.Description,
Category = r.Category,
ProgressEventCount = r.ProgressEventCount
}).ToList()
};
}
}
@@ -0,0 +1,11 @@
namespace WinStudentGoalTracker.Models;
public class StudentGoalItem
{
public Guid GoalId { get; set; }
public Guid? GoalParentId { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public int ProgressEventCount { get; set; }
}
@@ -0,0 +1,7 @@
namespace WinStudentGoalTracker.Models;
public class StudentGoalSummary
{
public string? StudentIdentifier { get; set; }
public List<StudentGoalItem> Goals { get; set; } = [];
}