mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 01:47: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; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
CREATE OR REPLACE VIEW `v_student_card` AS
|
||||
SELECT
|
||||
s.`id_student` AS `studentId`,
|
||||
s.`identifier` AS `identifier`,
|
||||
s.`expected_grad` AS `expectedGradDate`,
|
||||
MAX(pe.`created_at`) AS `lastEntryDate`,
|
||||
COUNT(DISTINCT g.`id_goal`) AS `goalCount`,
|
||||
COUNT(DISTINCT pe.`id_progress_event`) AS `progressEventCount`
|
||||
FROM `student` s
|
||||
LEFT JOIN `goal` g
|
||||
ON g.`id_student` = s.`id_student`
|
||||
LEFT JOIN `progress_event` pe
|
||||
ON pe.`id_student` = s.`id_student`
|
||||
GROUP BY
|
||||
s.`id_student`,
|
||||
s.`identifier`,
|
||||
s.`expected_grad`;
|
||||
@@ -2,7 +2,7 @@
|
||||
<h2 class="identifier">🎓 {{ student().identifier }}</h2>
|
||||
|
||||
<div class="meta">
|
||||
<span class="badge">Age: {{ student().age }}</span>
|
||||
<span class="badge">Grad Date: {{ student().expectedGradDate }}</span>
|
||||
<span class="last-entry">
|
||||
@if (student().lastEntryDate) {
|
||||
Last entry: {{ student().lastEntryDate | date:'M/d/yy' }}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="card" (click)="onCardClick()">
|
||||
<h2 class="identifier">{{ student().identifier }}</h2>
|
||||
<span class="age-badge">Age: {{ student().age }}</span>
|
||||
<span class="age-badge">Grad Date: {{ student().expectedGradDate }}</span>
|
||||
<div class="stats">
|
||||
<span class="stat">{{ student().goalCount }} goals</span>
|
||||
<span class="stat">{{ student().progressEventCount }} events</span>
|
||||
|
||||
@@ -36,7 +36,7 @@ export class Students {
|
||||
// Loads the list of students assigned to the current user.
|
||||
// *****************************************************************
|
||||
private loadStudents() {
|
||||
this.studentService.getDummyStudentsForUser().then(data => {
|
||||
this.studentService.getStudentsForUser().then(data => {
|
||||
|
||||
if (!data.success)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export interface StudentCardDto {
|
||||
studentId: string;
|
||||
identifier: string;
|
||||
age: number;
|
||||
lastEntryDate: string | null;
|
||||
expectedGradDate: Date;
|
||||
lastEntryDate: Date | null;
|
||||
goalCount: number;
|
||||
progressEventCount: number;
|
||||
}
|
||||
|
||||
@@ -25,23 +25,23 @@ export class StudentService {
|
||||
{
|
||||
studentId: '1',
|
||||
identifier: 'J.B',
|
||||
age: 21,
|
||||
lastEntryDate: '2026-02-21',
|
||||
expectedGradDate: new Date('2027-02-27'),
|
||||
lastEntryDate: new Date('2026-02-21'),
|
||||
goalCount: 3,
|
||||
progressEventCount: 5,
|
||||
},
|
||||
{
|
||||
studentId: '2',
|
||||
identifier: 'M.K',
|
||||
age: 19,
|
||||
lastEntryDate: '2026-02-25',
|
||||
expectedGradDate: new Date('2027-02-27'),
|
||||
lastEntryDate: new Date('2026-02-25'),
|
||||
goalCount: 4,
|
||||
progressEventCount: 8,
|
||||
},
|
||||
{
|
||||
studentId: '3',
|
||||
identifier: 'A.R',
|
||||
age: 22,
|
||||
expectedGradDate: new Date('2027-02-27'),
|
||||
lastEntryDate: null,
|
||||
goalCount: 2,
|
||||
progressEventCount: 0,
|
||||
@@ -57,13 +57,13 @@ export class StudentService {
|
||||
// Returns students assigned to the current user with their
|
||||
// identifier, age, goal count, and progress event count.
|
||||
// *****************************************************************
|
||||
async getDummyStudentsForUser(): Promise<ApiResult<StudentCardDto[]>> {
|
||||
async getStudentsForUser(): Promise<ApiResult<StudentCardDto[]>> {
|
||||
var payload = [
|
||||
{ studentId: '1', identifier: 'J.B', age: 21, lastEntryDate: '2026-02-21', goalCount: 3, progressEventCount: 5 },
|
||||
{ studentId: '2', identifier: 'M.K', age: 19, lastEntryDate: '2026-02-25', goalCount: 4, progressEventCount: 8 },
|
||||
{ studentId: '3', identifier: 'A.R', age: 22, lastEntryDate: null, goalCount: 2, progressEventCount: 0 },
|
||||
{ studentId: '4', identifier: 'T.W', age: 20, lastEntryDate: '2026-02-18', goalCount: 5, progressEventCount: 12 },
|
||||
{ studentId: '5', identifier: 'L.C', age: 18, lastEntryDate: '2026-02-27', goalCount: 1, progressEventCount: 2 },
|
||||
{ studentId: '1', identifier: 'J.B', expectedGradDate: new Date('2027-02-27'), lastEntryDate: new Date('2026-02-21'), goalCount: 3, progressEventCount: 5 },
|
||||
{ studentId: '2', identifier: 'M.K', expectedGradDate: new Date('2027-02-27'), lastEntryDate: new Date('2026-02-25'), goalCount: 4, progressEventCount: 8 },
|
||||
{ studentId: '3', identifier: 'A.R', expectedGradDate: new Date('2027-02-27'), lastEntryDate: null, goalCount: 2, progressEventCount: 0 },
|
||||
{ studentId: '4', identifier: 'T.W', expectedGradDate: new Date('2027-02-27'), lastEntryDate: new Date('2026-02-18'), goalCount: 5, progressEventCount: 12 },
|
||||
{ studentId: '5', identifier: 'L.C', expectedGradDate: new Date('2027-02-27'), lastEntryDate: new Date('2026-02-27'), goalCount: 1, progressEventCount: 2 },
|
||||
];
|
||||
|
||||
return ApiResult.ok(payload);
|
||||
|
||||
Reference in New Issue
Block a user