mirror of
https://github.com/opelly27/WinStudentGoalTracker.git
synced 2026-05-20 08:47:42 +00:00
latest
This commit is contained in:
@@ -27,13 +27,12 @@ public class StudentController : BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
||||||
var response = students.Select(StudentResponse.FromDatabaseModel);
|
|
||||||
|
|
||||||
return Ok(new ResponseResult<IEnumerable<StudentResponse>>
|
return Ok(new ResponseResult<IEnumerable<StudentResponse>>
|
||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
Message = "Students retrieved successfully.",
|
Message = "Students retrieved successfully.",
|
||||||
Data = response
|
Data = students
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,13 +54,12 @@ public class StudentController : BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
var students = await _studentRepository.GetMyStudentsAsync(userId, idProgram, role);
|
var students = await _studentRepository.GetMyStudentsAsync(userId, idProgram, role);
|
||||||
var response = students.Select(StudentResponse.FromDatabaseModel);
|
|
||||||
|
|
||||||
return Ok(new ResponseResult<IEnumerable<StudentResponse>>
|
return Ok(new ResponseResult<IEnumerable<StudentResponse>>
|
||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
Message = "Students retrieved successfully.",
|
Message = "Students retrieved successfully.",
|
||||||
Data = response
|
Data = students
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +78,7 @@ public class StudentController : BaseController
|
|||||||
|
|
||||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
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>
|
return NotFound(new ResponseResult<StudentResponse>
|
||||||
{
|
{
|
||||||
@@ -89,13 +87,13 @@ public class StudentController : BaseController
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var student = students.Single(s => s.IdStudent == idStudent);
|
var student = students.Single(s => s.StudentId == idStudent);
|
||||||
|
|
||||||
return Ok(new ResponseResult<StudentResponse>
|
return Ok(new ResponseResult<StudentResponse>
|
||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
Message = "Student retrieved successfully.",
|
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 = created.StudentId }, new ResponseResult<StudentResponse>
|
||||||
return CreatedAtAction(nameof(GetById), new { idStudent = response.IdStudent }, new ResponseResult<StudentResponse>
|
|
||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
Message = "Student created successfully.",
|
Message = "Student created successfully.",
|
||||||
Data = response
|
Data = created
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +152,7 @@ public class StudentController : BaseController
|
|||||||
|
|
||||||
var students = await _studentRepository.GetMyStudentsAsync(userId, programId, role);
|
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>
|
return NotFound(new ResponseResult<StudentResponse>
|
||||||
{
|
{
|
||||||
@@ -179,7 +176,7 @@ public class StudentController : BaseController
|
|||||||
{
|
{
|
||||||
Success = true,
|
Success = true,
|
||||||
Message = updated ? "Changes applied successfully." : "No changes were applied.",
|
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);
|
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>
|
return NotFound(new ResponseResult<StudentResponse>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class StudentRepository
|
|||||||
{
|
{
|
||||||
private IDbConnection Connection => new MySqlConnection(DatabaseManager.ConnectionString);
|
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 db = Connection;
|
||||||
using var multi = await db.QueryMultipleAsync(
|
using var multi = await db.QueryMultipleAsync(
|
||||||
@@ -18,29 +18,29 @@ public class StudentRepository
|
|||||||
new { p_id_program = programId.ToString(), p_id_user = userId.ToString() },
|
new { p_id_program = programId.ToString(), p_id_user = userId.ToString() },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
var students = await multi.ReadAsync<dbStudent>();
|
var students = await multi.ReadAsync<StudentResponse>();
|
||||||
var assignments = await multi.ReadAsync<dbUserStudent>();
|
var assignments = await multi.ReadAsync<dbUserStudent>();
|
||||||
|
|
||||||
var myStudents = students.Where(s =>
|
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;
|
return myStudents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<dbStudent?> GetByIdAsync(Guid idStudent)
|
public async Task<StudentResponse?> GetByIdAsync(Guid idStudent)
|
||||||
{
|
{
|
||||||
using var db = Connection;
|
using var db = Connection;
|
||||||
return await db.QuerySingleOrDefaultAsync<dbStudent>(
|
return await db.QuerySingleOrDefaultAsync<StudentResponse>(
|
||||||
"sp_Student_GetById",
|
"sp_Student_GetById",
|
||||||
new { p_id_student = idStudent.ToString() },
|
new { p_id_student = idStudent.ToString() },
|
||||||
commandType: CommandType.StoredProcedure);
|
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;
|
using var db = Connection;
|
||||||
return await db.QuerySingleOrDefaultAsync<dbStudent>(
|
await db.ExecuteAsync(
|
||||||
"sp_Student_Insert",
|
"sp_Student_Insert",
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
@@ -53,6 +53,8 @@ public class StudentRepository
|
|||||||
p_expected_grad = dto.ExpectedGrad
|
p_expected_grad = dto.ExpectedGrad
|
||||||
},
|
},
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return await GetByIdAsync(newStudentGuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> UpdateAsync(Guid idStudent, UpdateStudentDto dto)
|
public async Task<bool> UpdateAsync(Guid idStudent, UpdateStudentDto dto)
|
||||||
|
|||||||
@@ -1,28 +1,11 @@
|
|||||||
using WinStudentGoalTracker.DataAccess;
|
|
||||||
|
|
||||||
namespace WinStudentGoalTracker.Models;
|
namespace WinStudentGoalTracker.Models;
|
||||||
|
|
||||||
public class StudentResponse
|
public class StudentResponse
|
||||||
{
|
{
|
||||||
public Guid IdStudent { get; set; }
|
public Guid StudentId { get; set; }
|
||||||
public Guid? IdProgram { get; set; }
|
|
||||||
public string? Identifier { get; set; }
|
public string? Identifier { get; set; }
|
||||||
public int? ProgramYear { get; set; }
|
public DateTime? ExpectedGradDate { get; set; }
|
||||||
public DateTime? EnrollmentDate { get; set; }
|
public DateTime? LastEntryDate { get; set; }
|
||||||
public DateTime? ExpectedGrad { get; set; }
|
public int GoalCount { get; set; }
|
||||||
public DateTime? CreatedAt { get; set; }
|
public int ProgressEventCount { 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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
<h2 class="identifier">🎓 {{ student().identifier }}</h2>
|
||||||
|
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
<span class="badge">Age: {{ student().age }}</span>
|
<span class="badge">Grad Date: {{ student().expectedGradDate }}</span>
|
||||||
<span class="last-entry">
|
<span class="last-entry">
|
||||||
@if (student().lastEntryDate) {
|
@if (student().lastEntryDate) {
|
||||||
Last entry: {{ student().lastEntryDate | date:'M/d/yy' }}
|
Last entry: {{ student().lastEntryDate | date:'M/d/yy' }}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="card" (click)="onCardClick()">
|
<div class="card" (click)="onCardClick()">
|
||||||
<h2 class="identifier">{{ student().identifier }}</h2>
|
<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">
|
<div class="stats">
|
||||||
<span class="stat">{{ student().goalCount }} goals</span>
|
<span class="stat">{{ student().goalCount }} goals</span>
|
||||||
<span class="stat">{{ student().progressEventCount }} events</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.
|
// Loads the list of students assigned to the current user.
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
private loadStudents() {
|
private loadStudents() {
|
||||||
this.studentService.getDummyStudentsForUser().then(data => {
|
this.studentService.getStudentsForUser().then(data => {
|
||||||
|
|
||||||
if (!data.success)
|
if (!data.success)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
export interface StudentCardDto {
|
export interface StudentCardDto {
|
||||||
studentId: string;
|
studentId: string;
|
||||||
identifier: string;
|
identifier: string;
|
||||||
age: number;
|
expectedGradDate: Date;
|
||||||
lastEntryDate: string | null;
|
lastEntryDate: Date | null;
|
||||||
goalCount: number;
|
goalCount: number;
|
||||||
progressEventCount: number;
|
progressEventCount: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,23 +25,23 @@ export class StudentService {
|
|||||||
{
|
{
|
||||||
studentId: '1',
|
studentId: '1',
|
||||||
identifier: 'J.B',
|
identifier: 'J.B',
|
||||||
age: 21,
|
expectedGradDate: new Date('2027-02-27'),
|
||||||
lastEntryDate: '2026-02-21',
|
lastEntryDate: new Date('2026-02-21'),
|
||||||
goalCount: 3,
|
goalCount: 3,
|
||||||
progressEventCount: 5,
|
progressEventCount: 5,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
studentId: '2',
|
studentId: '2',
|
||||||
identifier: 'M.K',
|
identifier: 'M.K',
|
||||||
age: 19,
|
expectedGradDate: new Date('2027-02-27'),
|
||||||
lastEntryDate: '2026-02-25',
|
lastEntryDate: new Date('2026-02-25'),
|
||||||
goalCount: 4,
|
goalCount: 4,
|
||||||
progressEventCount: 8,
|
progressEventCount: 8,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
studentId: '3',
|
studentId: '3',
|
||||||
identifier: 'A.R',
|
identifier: 'A.R',
|
||||||
age: 22,
|
expectedGradDate: new Date('2027-02-27'),
|
||||||
lastEntryDate: null,
|
lastEntryDate: null,
|
||||||
goalCount: 2,
|
goalCount: 2,
|
||||||
progressEventCount: 0,
|
progressEventCount: 0,
|
||||||
@@ -57,13 +57,13 @@ export class StudentService {
|
|||||||
// Returns students assigned to the current user with their
|
// Returns students assigned to the current user with their
|
||||||
// identifier, age, goal count, and progress event count.
|
// identifier, age, goal count, and progress event count.
|
||||||
// *****************************************************************
|
// *****************************************************************
|
||||||
async getDummyStudentsForUser(): Promise<ApiResult<StudentCardDto[]>> {
|
async getStudentsForUser(): Promise<ApiResult<StudentCardDto[]>> {
|
||||||
var payload = [
|
var payload = [
|
||||||
{ studentId: '1', identifier: 'J.B', age: 21, lastEntryDate: '2026-02-21', goalCount: 3, progressEventCount: 5 },
|
{ 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', age: 19, lastEntryDate: '2026-02-25', goalCount: 4, progressEventCount: 8 },
|
{ 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', age: 22, lastEntryDate: null, goalCount: 2, progressEventCount: 0 },
|
{ studentId: '3', identifier: 'A.R', expectedGradDate: new Date('2027-02-27'), lastEntryDate: null, goalCount: 2, progressEventCount: 0 },
|
||||||
{ studentId: '4', identifier: 'T.W', age: 20, lastEntryDate: '2026-02-18', goalCount: 5, progressEventCount: 12 },
|
{ 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', age: 18, lastEntryDate: '2026-02-27', goalCount: 1, progressEventCount: 2 },
|
{ 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);
|
return ApiResult.ok(payload);
|
||||||
|
|||||||
Reference in New Issue
Block a user