mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 09:57:37 +00:00
latest
This commit is contained in:
@@ -130,6 +130,57 @@ public class StudentController : BaseController
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("{idStudent:guid}/goals")]
|
||||
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.ProgramAdmin}")]
|
||||
[ProducesResponseType(typeof(ResponseResult<StudentGoalItem>), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(ResponseResult<StudentGoalItem>), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(ResponseResult<StudentGoalItem>), StatusCodes.Status400BadRequest)]
|
||||
public async Task<ActionResult<ResponseResult<StudentGoalItem>>> CreateGoal(Guid idStudent, [FromBody] CreateGoalDto 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<StudentGoalItem>
|
||||
{
|
||||
Success = false,
|
||||
Message = "Student not found."
|
||||
});
|
||||
}
|
||||
|
||||
if (!PermissionService.IsAllowed(role, EntityType.Goal, PermissionAction.Create))
|
||||
{
|
||||
return BadRequest(new ResponseResult<StudentGoalItem>
|
||||
{
|
||||
Success = false,
|
||||
Message = "Unable to create goal."
|
||||
});
|
||||
}
|
||||
|
||||
var created = await _studentRepository.InsertGoalAsync(idStudent, userId, dto);
|
||||
if (created is null)
|
||||
{
|
||||
return BadRequest(new ResponseResult<StudentGoalItem>
|
||||
{
|
||||
Success = false,
|
||||
Message = "Unable to create goal."
|
||||
});
|
||||
}
|
||||
|
||||
return StatusCode(StatusCodes.Status201Created, new ResponseResult<StudentGoalItem>
|
||||
{
|
||||
Success = true,
|
||||
Message = "Goal created successfully.",
|
||||
Data = created
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("{idStudent:guid}/progress-event")]
|
||||
[Authorize(Roles = $"{UserRoles.Teacher},{UserRoles.Paraeducator},{UserRoles.ProgramAdmin}")]
|
||||
[ProducesResponseType(typeof(ResponseResult), StatusCodes.Status201Created)]
|
||||
@@ -216,7 +267,7 @@ public class StudentController : BaseController
|
||||
[Authorize(Roles = $"{UserRoles.Teacher}")]
|
||||
[ProducesResponseType(typeof(ResponseResult<StudentResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ResponseResult<StudentResponse>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult<ResponseResult<StudentResponse>>> Update(Guid idStudent, [FromBody] UpdateStudentDto request)
|
||||
public async Task<ActionResult<ResponseResult<StudentResponse>>> UpdateStudent(Guid idStudent, [FromBody] UpdateStudentDto request)
|
||||
{
|
||||
var (userId, email, programId, role, error) = GetProgramUserFromClaims();
|
||||
if (error is not null)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace WinStudentGoalTracker.DataAccess;
|
||||
|
||||
public class CreateGoalDto
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? Category { get; set; }
|
||||
}
|
||||
@@ -101,6 +101,36 @@ public class StudentRepository
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
public async Task<StudentGoalItem?> InsertGoalAsync(Guid idStudent, Guid userId, CreateGoalDto dto)
|
||||
{
|
||||
var newGoalId = Guid.NewGuid();
|
||||
using var db = Connection;
|
||||
var rowsAffected = await db.ExecuteAsync(
|
||||
"sp_Goal_Insert",
|
||||
new
|
||||
{
|
||||
p_id_goal = newGoalId.ToString(),
|
||||
p_id_student = idStudent.ToString(),
|
||||
p_id_user = userId.ToString(),
|
||||
p_title = dto.Title,
|
||||
p_description = dto.Description,
|
||||
p_category = dto.Category
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
if (rowsAffected == 0) return null;
|
||||
|
||||
return new StudentGoalItem
|
||||
{
|
||||
GoalId = newGoalId,
|
||||
GoalParentId = null,
|
||||
Title = dto.Title,
|
||||
Description = dto.Description,
|
||||
Category = dto.Category,
|
||||
ProgressEventCount = 0
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<StudentGoalSummary?> GetGoalSummaryAsync(Guid idStudent)
|
||||
{
|
||||
using var db = Connection;
|
||||
@@ -110,7 +140,17 @@ public class StudentRepository
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
var list = rows.ToList();
|
||||
if (list.Count == 0) return null;
|
||||
if (list.Count == 0)
|
||||
{
|
||||
var student = await GetByIdAsync(idStudent);
|
||||
if (student is null) return null;
|
||||
|
||||
return new StudentGoalSummary
|
||||
{
|
||||
StudentIdentifier = student.Identifier,
|
||||
Goals = []
|
||||
};
|
||||
}
|
||||
|
||||
return new StudentGoalSummary
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user