mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 05:17:41 +00:00
latest
This commit is contained in:
@@ -27,19 +27,18 @@ public class StudentController : BaseController
|
||||
}
|
||||
|
||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
||||
var response = students.Select(StudentResponse.FromDatabaseModel);
|
||||
|
||||
return Ok(new ResponseResult<IEnumerable<StudentResponse>>
|
||||
{
|
||||
Success = true,
|
||||
Message = "Students retrieved successfully.",
|
||||
Data = response
|
||||
Data = students
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// TODO refactor with database changes to ensure
|
||||
// users who are a district admin are actually associated with a district, and
|
||||
// TODO refactor with database changes to ensure
|
||||
// users who are a district admin are actually associated with a district, and
|
||||
// then this endpoint should validate that the requested program is part of the district
|
||||
// Once that is in place, then district admins will be allowed to call this function.
|
||||
[HttpGet("program/{idProgram:guid}")]
|
||||
@@ -55,13 +54,12 @@ public class StudentController : BaseController
|
||||
}
|
||||
|
||||
var students = await _studentRepository.GetMyStudentsAsync(userId, idProgram, role);
|
||||
var response = students.Select(StudentResponse.FromDatabaseModel);
|
||||
|
||||
return Ok(new ResponseResult<IEnumerable<StudentResponse>>
|
||||
{
|
||||
Success = true,
|
||||
Message = "Students retrieved successfully.",
|
||||
Data = response
|
||||
Data = students
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,7 +78,7 @@ public class StudentController : BaseController
|
||||
|
||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
||||
|
||||
if (!students.Select(s => s.IdStudent).Contains(idStudent))
|
||||
if (!students.Select(s => s.StudentId).Contains(idStudent))
|
||||
{
|
||||
return NotFound(new ResponseResult<StudentResponse>
|
||||
{
|
||||
@@ -88,14 +86,14 @@ public class StudentController : BaseController
|
||||
Message = "Student not found."
|
||||
});
|
||||
}
|
||||
|
||||
var student = students.Single(s => s.IdStudent == idStudent);
|
||||
|
||||
var student = students.Single(s => s.StudentId == idStudent);
|
||||
|
||||
return Ok(new ResponseResult<StudentResponse>
|
||||
{
|
||||
Success = true,
|
||||
Message = "Student retrieved successfully.",
|
||||
Data = StudentResponse.FromDatabaseModel(student)
|
||||
Data = student
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,12 +130,11 @@ public class StudentController : BaseController
|
||||
});
|
||||
}
|
||||
|
||||
var response = StudentResponse.FromDatabaseModel(created);
|
||||
return CreatedAtAction(nameof(GetById), new { idStudent = response.IdStudent }, new ResponseResult<StudentResponse>
|
||||
return CreatedAtAction(nameof(GetById), new { idStudent = created.StudentId }, new ResponseResult<StudentResponse>
|
||||
{
|
||||
Success = true,
|
||||
Message = "Student created successfully.",
|
||||
Data = response
|
||||
Data = created
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,7 +152,7 @@ public class StudentController : BaseController
|
||||
|
||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
||||
|
||||
if (!students.Select(s => s.IdStudent).Contains(idStudent))
|
||||
if (!students.Select(s => s.StudentId).Contains(idStudent))
|
||||
{
|
||||
return NotFound(new ResponseResult<StudentResponse>
|
||||
{
|
||||
@@ -179,7 +176,7 @@ public class StudentController : BaseController
|
||||
{
|
||||
Success = true,
|
||||
Message = updated ? "Changes applied successfully." : "No changes were applied.",
|
||||
Data = StudentResponse.FromDatabaseModel(refreshed)
|
||||
Data = refreshed
|
||||
});
|
||||
}
|
||||
|
||||
@@ -197,7 +194,7 @@ public class StudentController : BaseController
|
||||
|
||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
||||
|
||||
if (!students.Select(s => s.IdStudent).Contains(idStudent))
|
||||
if (!students.Select(s => s.StudentId).Contains(idStudent))
|
||||
{
|
||||
return NotFound(new ResponseResult<StudentResponse>
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ public class StudentRepository
|
||||
{
|
||||
private IDbConnection Connection => new MySqlConnection(DatabaseManager.ConnectionString);
|
||||
|
||||
public async Task<IEnumerable<dbStudent>> GetMyStudentsAsync(Guid userId, Guid programId, string role)
|
||||
public async Task<IEnumerable<StudentResponse>> GetMyStudentsAsync(Guid userId, Guid programId, string role)
|
||||
{
|
||||
using var db = Connection;
|
||||
using var multi = await db.QueryMultipleAsync(
|
||||
@@ -18,29 +18,29 @@ public class StudentRepository
|
||||
new { p_id_program = programId.ToString(), p_id_user = userId.ToString() },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
var students = await multi.ReadAsync<dbStudent>();
|
||||
var students = await multi.ReadAsync<StudentResponse>();
|
||||
var assignments = await multi.ReadAsync<dbUserStudent>();
|
||||
|
||||
var myStudents = students.Where(s =>
|
||||
PermissionService.IsAllowed(role, EntityType.Student, PermissionAction.Read , assignments.Any(a => a.IdStudent == s.IdStudent && a.IdUser == userId))
|
||||
PermissionService.IsAllowed(role, EntityType.Student, PermissionAction.Read, assignments.Any(a => a.IdStudent == s.StudentId && a.IdUser == userId))
|
||||
);
|
||||
|
||||
return myStudents;
|
||||
}
|
||||
|
||||
public async Task<dbStudent?> GetByIdAsync(Guid idStudent)
|
||||
public async Task<StudentResponse?> GetByIdAsync(Guid idStudent)
|
||||
{
|
||||
using var db = Connection;
|
||||
return await db.QuerySingleOrDefaultAsync<dbStudent>(
|
||||
return await db.QuerySingleOrDefaultAsync<StudentResponse>(
|
||||
"sp_Student_GetById",
|
||||
new { p_id_student = idStudent.ToString() },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
|
||||
public async Task<dbStudent?> InsertAsync(CreateStudentDto dto, Guid newStudentGuid, Guid programId, Guid userId)
|
||||
public async Task<StudentResponse?> InsertAsync(CreateStudentDto dto, Guid newStudentGuid, Guid programId, Guid userId)
|
||||
{
|
||||
using var db = Connection;
|
||||
return await db.QuerySingleOrDefaultAsync<dbStudent>(
|
||||
await db.ExecuteAsync(
|
||||
"sp_Student_Insert",
|
||||
new
|
||||
{
|
||||
@@ -53,6 +53,8 @@ public class StudentRepository
|
||||
p_expected_grad = dto.ExpectedGrad
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return await GetByIdAsync(newStudentGuid);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(Guid idStudent, UpdateStudentDto dto)
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
using WinStudentGoalTracker.DataAccess;
|
||||
|
||||
namespace WinStudentGoalTracker.Models;
|
||||
|
||||
public class StudentResponse
|
||||
{
|
||||
public Guid IdStudent { get; set; }
|
||||
public Guid? IdProgram { get; set; }
|
||||
public Guid StudentId { get; set; }
|
||||
public string? Identifier { get; set; }
|
||||
public int? ProgramYear { get; set; }
|
||||
public DateTime? EnrollmentDate { get; set; }
|
||||
public DateTime? ExpectedGrad { get; set; }
|
||||
public DateTime? CreatedAt { get; set; }
|
||||
|
||||
public static StudentResponse FromDatabaseModel(dbStudent student)
|
||||
{
|
||||
return new StudentResponse
|
||||
{
|
||||
IdStudent = student.IdStudent,
|
||||
IdProgram = student.IdProgram,
|
||||
Identifier = student.Identifier,
|
||||
ProgramYear = student.ProgramYear,
|
||||
EnrollmentDate = student.EnrollmentDate,
|
||||
ExpectedGrad = student.ExpectedGrad,
|
||||
CreatedAt = student.CreatedAt
|
||||
};
|
||||
}
|
||||
public DateTime? ExpectedGradDate { get; set; }
|
||||
public DateTime? LastEntryDate { get; set; }
|
||||
public int GoalCount { get; set; }
|
||||
public int ProgressEventCount { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user