From 7457643c87ee12e8b7fce43a128b0bd207fabcef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 05:32:05 +0000 Subject: [PATCH 1/2] Initial plan From 36e10f4d35dc9e795ce917b3354c0afce2c37b5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 05:41:47 +0000 Subject: [PATCH 2/2] Improve variable and function names for better code readability Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com> Agent-Logs-Url: https://github.com/CanarysPlayground/CourseApplication/sessions/51a2a9d1-9c0b-440f-84e0-b50b5ed61265 --- .../Middleware/ExceptionHandlingMiddleware.cs | 8 ++--- .../Services/CertificateService.cs | 16 ++++----- .../Repositories/CourseRepository.cs | 18 +++++----- frontend/script.js | 34 +++++++++---------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/api/CourseRegistration.API/Middleware/ExceptionHandlingMiddleware.cs b/api/CourseRegistration.API/Middleware/ExceptionHandlingMiddleware.cs index 8ab2c90..dc5eac0 100644 --- a/api/CourseRegistration.API/Middleware/ExceptionHandlingMiddleware.cs +++ b/api/CourseRegistration.API/Middleware/ExceptionHandlingMiddleware.cs @@ -56,16 +56,16 @@ private async Task HandleExceptionAsync(HttpContext context, Exception exception switch (exception) { - case ArgumentException argEx: + case ArgumentException argumentException: response.StatusCode = (int)HttpStatusCode.BadRequest; errorResponse.Message = "Invalid argument provided"; - errorResponse.Errors = new[] { argEx.Message }; + errorResponse.Errors = new[] { argumentException.Message }; break; - case InvalidOperationException invOpEx: + case InvalidOperationException invalidOperationException: response.StatusCode = (int)HttpStatusCode.BadRequest; errorResponse.Message = "Invalid operation"; - errorResponse.Errors = new[] { invOpEx.Message }; + errorResponse.Errors = new[] { invalidOperationException.Message }; break; case UnauthorizedAccessException: diff --git a/api/CourseRegistration.Application/Services/CertificateService.cs b/api/CourseRegistration.Application/Services/CertificateService.cs index 01e20a5..9e3e578 100644 --- a/api/CourseRegistration.Application/Services/CertificateService.cs +++ b/api/CourseRegistration.Application/Services/CertificateService.cs @@ -92,7 +92,7 @@ public async Task> GetCertificatesByStudentIdAsync(G await Task.CompletedTask; // Simulate async operation var certificates = _certificates.Where(c => c.StudentId == studentId); - return certificates.Select(MapToDto); + return certificates.Select(MapCertificateToDto); } public async Task GetCertificateByIdAsync(Guid certificateId) @@ -100,7 +100,7 @@ public async Task> GetCertificatesByStudentIdAsync(G await Task.CompletedTask; // Simulate async operation var certificate = _certificates.FirstOrDefault(c => c.CertificateId == certificateId); - return certificate != null ? MapToDto(certificate) : null; + return certificate != null ? MapCertificateToDto(certificate) : null; } public async Task> GetCertificatesByStudentNameAsync(string studentName) @@ -118,7 +118,7 @@ public async Task> GetCertificatesByStudentNameAsync certificates.AddRange(_certificates.Where(c => c.StudentId == student.StudentId)); } - return certificates.Select(MapToDto); + return certificates.Select(MapCertificateToDto); } public async Task CreateCertificateAsync(CreateCertificateDto createCertificateDto) @@ -138,17 +138,17 @@ public async Task CreateCertificateAsync(CreateCertificateDto cr }; _certificates.Add(certificate); - return MapToDto(certificate); + return MapCertificateToDto(certificate); } public string GenerateCertificateNumber() { - var year = DateTime.Now.Year; - var sequence = _certificates.Count + 1; - return $"CERT-{year}-{sequence:D3}"; + var issuanceYear = DateTime.UtcNow.Year; + var certificateSequenceNumber = _certificates.Count + 1; + return $"CERT-{issuanceYear}-{certificateSequenceNumber:D3}"; } - private CertificateDto MapToDto(Certificate certificate) + private CertificateDto MapCertificateToDto(Certificate certificate) { var student = _students.FirstOrDefault(s => s.StudentId == certificate.StudentId); var course = _courses.FirstOrDefault(c => c.CourseId == certificate.CourseId); diff --git a/api/CourseRegistration.Infrastructure/Repositories/CourseRepository.cs b/api/CourseRegistration.Infrastructure/Repositories/CourseRepository.cs index 985a879..1ae8bf6 100644 --- a/api/CourseRegistration.Infrastructure/Repositories/CourseRepository.cs +++ b/api/CourseRegistration.Infrastructure/Repositories/CourseRepository.cs @@ -39,16 +39,16 @@ public async Task> SearchCoursesAsync(string? searchTerm, st if (!string.IsNullOrWhiteSpace(searchTerm)) { - var lowerSearchTerm = searchTerm.ToLower(); + var normalizedSearchTerm = searchTerm.ToLower(); query = query.Where(c => - c.CourseName.ToLower().Contains(lowerSearchTerm) || - (c.Description != null && c.Description.ToLower().Contains(lowerSearchTerm))); + c.CourseName.ToLower().Contains(normalizedSearchTerm) || + (c.Description != null && c.Description.ToLower().Contains(normalizedSearchTerm))); } if (!string.IsNullOrWhiteSpace(instructor)) { - var lowerInstructor = instructor.ToLower(); - query = query.Where(c => c.InstructorName.ToLower().Contains(lowerInstructor)); + var normalizedInstructorName = instructor.ToLower(); + query = query.Where(c => c.InstructorName.ToLower().Contains(normalizedInstructorName)); } return await query @@ -72,11 +72,11 @@ public async Task> GetActiveCoursesAsync() /// public async Task> GetAvailableCoursesAsync() { - var currentDate = DateTime.UtcNow; + var currentUtcDateTime = DateTime.UtcNow; return await _dbSet .Include(c => c.Registrations) - .Where(c => c.IsActive && c.StartDate > currentDate) + .Where(c => c.IsActive && c.StartDate > currentUtcDateTime) .OrderBy(c => c.StartDate) .ThenBy(c => c.CourseName) .ToListAsync(); @@ -90,9 +90,9 @@ public async Task> GetCoursesByInstructorAsync(string instru if (string.IsNullOrWhiteSpace(instructorName)) return Enumerable.Empty(); - var lowerInstructorName = instructorName.ToLower(); + var normalizedInstructorName = instructorName.ToLower(); return await _dbSet - .Where(c => c.IsActive && c.InstructorName.ToLower().Contains(lowerInstructorName)) + .Where(c => c.IsActive && c.InstructorName.ToLower().Contains(normalizedInstructorName)) .OrderBy(c => c.CourseName) .ToListAsync(); } diff --git a/frontend/script.js b/frontend/script.js index 174617a..be88619 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -61,12 +61,12 @@ function initializeForm() { addCourseForm.addEventListener('submit', handleFormSubmit); // Instructor name validation (letters, spaces, periods only) - document.getElementById('instructorName').addEventListener('input', function(e) { - const value = e.target.value; + document.getElementById('instructorName').addEventListener('input', function(event) { + const value = event.target.value; const validPattern = /^[a-zA-Z\s.]*$/; if (!validPattern.test(value)) { - e.target.value = value.replace(/[^a-zA-Z\s.]/g, ''); + event.target.value = value.replace(/[^a-zA-Z\s.]/g, ''); } }); @@ -80,8 +80,8 @@ function initializeForm() { } // Form Submission Handler -async function handleFormSubmit(e) { - e.preventDefault(); +async function handleFormSubmit(event) { + event.preventDefault(); if (!validateForm()) { return; @@ -252,8 +252,8 @@ function clearAllErrors() { const errorElements = document.querySelectorAll('.error-message'); const inputElements = document.querySelectorAll('.form-input, .form-textarea'); - errorElements.forEach(el => el.textContent = ''); - inputElements.forEach(el => el.classList.remove('error')); + errorElements.forEach(errorElement => errorElement.textContent = ''); + inputElements.forEach(inputElement => inputElement.classList.remove('error')); } function displayValidationErrors(errors) { @@ -284,19 +284,19 @@ function mapFieldName(apiFieldName) { } // UI State Functions -function setSubmitButton(loading, text) { - submitBtn.disabled = loading; - submitText.textContent = text; +function setSubmitButton(isLoading, buttonText) { + submitBtn.disabled = isLoading; + submitText.textContent = buttonText; - if (loading) { - submitBtn.innerHTML = ` ${text}`; + if (isLoading) { + submitBtn.innerHTML = ` ${buttonText}`; } else { - submitBtn.innerHTML = ` ${text}`; + submitBtn.innerHTML = ` ${buttonText}`; } } -function showLoading(show) { - loadingOverlay.classList.toggle('hidden', !show); +function showLoading(isVisible) { + loadingOverlay.classList.toggle('hidden', !isVisible); } // Modal Functions @@ -863,8 +863,8 @@ function applyFilters() { let filteredRegistrations = allRegistrations; if (statusFilter !== '') { - filteredRegistrations = filteredRegistrations.filter(reg => - reg.status.toString() === statusFilter + filteredRegistrations = filteredRegistrations.filter(registration => + registration.status.toString() === statusFilter ); }