-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(backend): Implement Grade Data Management API Endpoints #8
feat(backend): Implement Grade Data Management API Endpoints #8
Conversation
- Defined `testSchema` to store individual test details including name, score, and total. - Defined `categorySchema` to store categories of tests with their weights and tasks. - Defined `courseSchema` to store course details including name, credits, type, and categories. - Defined `gradeSchema` to store overall grade details including user ID, name, start and end dates, courses, grading mode, and grade range. - Indexed the `userId` field for efficient querying. - Created and exported the `Grade` model for use in other modules.
…schema - Added indexes for `startDate` and `endDate` fields in `gradeSchema` to improve query performance. - Ensured the `userId` field is indexed for efficient querying. - Created and exported the `Grade` model for use in other modules.
…ade range features - Added descriptions for customizable grade mode and grade range features. - Highlighted support for discrete and continuous grading scales. - Emphasized the flexibility to fit different academic systems and course requirements.
- Renamed `testSchema` to `taskSchema` in `gradeSchema.js` for consistency. - Updated all references to `testSchema` to use `taskSchema`. - Ensured the schema structure and functionality remain unchanged.
- Added `timestamps` option to `taskSchema`, `categorySchema`, and `courseSchema` to automatically manage `createdAt` and `updatedAt` fields. - Ensured `gradeSchema` already includes timestamps for `createdAt` and `updatedAt`. - Updated the schema definitions to reflect the changes.
- Added `createGrade` function to create a new grade (semester/quarter) in the database. - Implemented `getGrades` function to retrieve all grades for a user with basic details. - Implemented `getDetailedGrades` function to retrieve all grades for a user with full details. - Added `getGradeById` function to retrieve a specific grade by its ID. - Implemented `updateGradeById` function to update a grade by its ID. - Added `updateGradeFieldById` function to update a specific field of a grade by its ID. - Implemented `deleteGradeById` function to delete a grade by its ID. - Exported all functions for use in other modules.
…ation - Added `/grades` endpoint in `gradeRoutes.js` to handle requests for retrieving grades. - Implemented `getGrades` controller in `gradeControllers.js` to fetch grades from the database. - Supported query parameter `detailed` to return detailed grade information if set to `true`. - Updated `API.md` to include documentation for the `getGrades` endpoint. - Included request parameters, query parameters, and response examples for the new endpoint.
- Added `validateGradeName` function in `validationUtils.js` to validate grade names. - Ensured the grade name matches the regex pattern and is not empty. - Exported the `validateGradeName` function for use in other modules.
- Added `MAX_USERNAME_LENGTH` and `MAX_SCHOOL_LENGTH` constants to define maximum lengths for username and school name. - Updated `validateUsername` function to check against `MAX_USERNAME_LENGTH`. - Updated `validateSchool` function to check against `MAX_SCHOOL_LENGTH`. - Ensured validation functions enforce maximum length constraints for username and school name.
- Added `validateStartDate` function in `validationUtils.js` to validate start dates. - Added `validateEndDate` function in `validationUtils.js` to validate end dates. - Ensured both functions check for valid date formats and non-empty values. - Exported the `validateStartDate` and `validateEndDate` functions for use in other modules.
…ntation - Added `/grades` endpoint in `gradeRoutes.js` to handle requests for creating a new grade. - Implemented `createGrade` controller in `gradeControllers.js` to validate input and create a new grade in the database. - Updated `API.md` to include documentation for the `createGrade` endpoint. - Included request body and response examples for the new endpoint.
…tion - Added `/grades/:id` endpoint in `gradeRoutes.js` to handle requests for retrieving a specific grade by ID. - Implemented `getGrade` controller in `gradeControllers.js` to fetch a grade from the database by its ID. - Updated `API.md` to include documentation for the `getGrade` endpoint. - Included request parameters and response examples for the new endpoint.
- Added `extraCredit` field to `taskSchema` in `gradeSchema.js` to indicate if a task is for extra credit. - Ensured the `extraCredit` field is a boolean with a default value of `false`. - Updated the schema definitions to reflect the changes.
… documentation - Added `/grades/:id` endpoint in `gradeRoutes.js` to handle requests for updating specific fields of a grade using JSON Patch. - Implemented `updateGradeFields` controller in `gradeControllers.js` to validate and apply JSON Patch operations to the grade. - Updated `API.md` to include documentation for the `updateGradeFields` endpoint. - Included request parameters, request body, and response examples for the new endpoint.
- Updated `updateGradeFields` controller in `gradeControllers.js` to use `slice` instead of `splice` for string manipulation. - Ensured the path manipulation logic correctly handles string operations. - Fixed the error caused by incorrect usage of `splice` on strings.
…ntation - Added `/grades/:id` endpoint in `gradeRoutes.js` to handle requests for deleting a specific grade by ID. - Implemented `deleteGrade` controller in `gradeControllers.js` to delete a grade from the database by its ID. - Updated `API.md` to include documentation for the `deleteGrade` endpoint. - Included request parameters and response examples for the new endpoint.
…ntation - Added `/grades/:id/export` endpoint in `gradeRoutes.js` to handle requests for exporting a specific grade by ID. - Implemented `exportGrade` controller in `gradeControllers.js` to export a grade as a JSON file. - Updated `API.md` to include documentation for the `exportGrade` endpoint. - Included request parameters and response examples for the new endpoint.
…I documentation - Added `/grades/export` endpoint in `gradeRoutes.js` to handle requests for exporting all grades for a user. - Implemented `exportGrades` controller in `gradeControllers.js` to export all grades as a JSON file. - Updated `API.md` to include documentation for the `exportGrades` endpoint. - Included request parameters and response examples for the new endpoint.
…om a file - Added `importGrades` function in `gradeService.js` to import grades from a file. - Implemented logic to map and insert grades into the database, excluding specific fields. - Ensured the imported grades are associated with the correct user ID. - Exported the `importGrades` function for use in other modules.
…entation - Added `/grades/import` endpoint in `gradeRoutes.js` to handle requests for importing grades from a file. - Implemented `importGrades` controller in `gradeControllers.js` to process and import grades into the database. - Updated `API.md` to include documentation for the `importGrades` endpoint. - Included request body and response examples for the new endpoint.
…hemas - Added `goal` field to `categorySchema` to store optional goals for categories. - Added `goal` field to `courseSchema` to store optional goals for courses. - Added `goals` field to `gradeSchema` to store optional GPA and weighted GPA goals for grades. - Ensured the new fields are optional and have appropriate default values.
…ghted GPA - Added `goals` field to `settingsSchema` in `userSchema.js` to store user goals for GPA and weighted GPA. - Ensured the `goals` field includes `gpa` and `weightedGPA` with default values. - Updated the schema definitions to reflect the changes.
…values to null for percentage and score fields
…in settings and validation errors for GPA fields
…gs handling - Added input fields for GPA goals and weighted GPA goals in `settings.ejs`. - Implemented logic to fetch and display current GPA goals from user settings. - Updated settings save functionality to include GPA goals. - Ensured the settings page correctly handles and updates GPA goals.
…ly handle non-numeric values
…nsure non-negative values - Updated `goals` fields in `settingsSchema` of `userSchema.js` to include minimum value validation for `gpa` and `weightedGPA`. - Ensured `goals` fields in `gradeSchema.js` have minimum value validation for `gpa` and `weightedGPA`. - Added minimum value validation for `GPA`, `honorsGPA`, and `advancedGPA` fields in `gradeRange` of `gradeSchema.js`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 7 out of 12 changed files in this pull request and generated 4 comments.
Files not reviewed (5)
- frontend/src/views/pages/user/settings.ejs: Language not supported
- README.md: Evaluated as low risk
- backend/src/controllers/authControllers.js: Evaluated as low risk
- backend/src/routes/index.js: Evaluated as low risk
- backend/src/controllers/userControllers.js: Evaluated as low risk
…otype properties in path Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…t default total to 0
… at least 1 character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 7 out of 12 changed files in this pull request and generated no comments.
Files not reviewed (5)
- frontend/src/views/pages/user/settings.ejs: Language not supported
- backend/src/services/gradeService.js: Evaluated as low risk
- README.md: Evaluated as low risk
- backend/src/routes/index.js: Evaluated as low risk
- backend/src/controllers/authControllers.js: Evaluated as low risk
Comments suppressed due to low confidence (5)
backend/src/models/gradeSchema.js:149
- The 'percentage' field should have a validation to ensure it falls within a valid range (e.g., 0 to 100).
percentage: { type: Number, required: true, },
backend/src/models/gradeSchema.js:154
- The 'letter' field should have a validation to ensure it matches valid letter grades (e.g., A, B, C, etc.).
letter: { type: String, required: true, },
backend/src/models/gradeSchema.js:158
- The 'GPA' field should have a maximum value validation (e.g., 4.0 for standard GPA).
GPA: { type: Number, required: true, min: 0, },
backend/src/models/gradeSchema.js:163
- The 'honorsGPA' field should have a maximum value validation.
honorsGPA: { type: Number, required: true, min: 0, },
backend/src/models/gradeSchema.js:168
- The 'advancedGPA' field should have a maximum value validation.
advancedGPA: { type: Number, required: true, min: 0, },
Summary:
Implemented a comprehensive grade data management system with the following features:
Changes:
Added Backend API Endpoints:
POST /grades
: Create a new semester with basic details.GET /grades
: Fetch a list of semesters with basic details.GET /grades/:id
: Fetch detailed data for a specific semester, including nested courses, categories, and tasks.PUT /grades/:id
: Replace all data for a specific semester, including courses, categories, and tasks.PATCH /grades/:id
: Apply JSON Patch updates to specific elements within a semester.DELETE /grades/:id
: Delete a specific semester by ID.GET /grades/:id/export
: Export detailed data of a specific semester as a JSON file.GET /grades/export
: Export all semesters' data as a JSON file.POST /grades/import
: Bulk import multiple semesters with nested data (courses, categories, tasks).Model and Schema Changes:
startDate
andendDate
in the Grade schema.extraCredit
field.goal
fields to the Grade and Course schemas, and agoals
field to the User schema with GPA and weight goals.roles
andlocked
fields, and ensured proper indexing for query performance.Utility Enhancements:
Documentation Updates:
API.md
to include detailed descriptions and example requests/responses for all new grade endpoints.Frontend Enhancements: