Skip to content
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

Merged
merged 35 commits into from
Jan 25, 2025

Conversation

TKanX
Copy link
Owner

@TKanX TKanX commented Jan 24, 2025

Summary:

Implemented a comprehensive grade data management system with the following features:

  • Semester-level Hierarchical Data Management: Manage terms, courses, categories, and tasks.
  • Basic Academic Data Calculations: Calculate total scores and GPA.
  • Import/Export Functionality: Import and export academic data easily.
  • User Settings Integration: Seamless integration with user settings for efficient data management.

Changes:

  1. Added Backend API Endpoints:

    • Create Semester:
      • POST /grades: Create a new semester with basic details.
    • Get All Semesters:
      • GET /grades: Fetch a list of semesters with basic details.
    • Get Semester Details:
      • GET /grades/:id: Fetch detailed data for a specific semester, including nested courses, categories, and tasks.
    • Update Semester Data:
      • PUT /grades/:id: Replace all data for a specific semester, including courses, categories, and tasks.
    • Partial Update of Semester Data:
      • PATCH /grades/:id: Apply JSON Patch updates to specific elements within a semester.
    • Delete Semester:
      • DELETE /grades/:id: Delete a specific semester by ID.
    • Export Specific Semester Data:
      • GET /grades/:id/export: Export detailed data of a specific semester as a JSON file.
    • Export All Semesters Data:
      • GET /grades/export: Export all semesters' data as a JSON file.
    • Import Semester Data:
      • POST /grades/import: Bulk import multiple semesters with nested data (courses, categories, tasks).
  2. Model and Schema Changes:

    • Added a Grade schema to the MongoDB database for managing semester-level data.
    • Added indexes for startDate and endDate in the Grade schema.
    • Enhanced the Grade schema to include timestamps and an optional extraCredit field.
    • Added optional goal fields to the Grade and Course schemas, and a goals field to the User schema with GPA and weight goals.
    • Set default values for roles and locked fields, and ensured proper indexing for query performance.
  3. Utility Enhancements:

    • Added validation functions for grade name, username, and school name maximum length.
    • Added validation functions for start and end dates.
    • Improved GPA goal validation to ensure non-negative values.
  4. Documentation Updates:

    • Updated API.md to include detailed descriptions and example requests/responses for all new grade endpoints.
    • Updated the README to include customizable grade modes and grade management functionality.
  5. Frontend Enhancements:

    • Added GPA goals input fields and updated settings components to handle GPA goals.

TKanX added 30 commits January 12, 2025 22:09
- 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.
TKanX added 2 commits January 20, 2025 21:06
…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`.
@TKanX TKanX added documentation 📖 Improvements or additions to documentation enhancement ✨ New feature or request labels Jan 24, 2025
@TKanX TKanX self-assigned this Jan 24, 2025
@Copilot Copilot bot review requested due to automatic review settings January 24, 2025 10:02
@TKanX TKanX linked an issue Jan 24, 2025 that may be closed by this pull request
17 tasks
Copy link
Contributor

@Copilot Copilot AI left a 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

backend/src/models/gradeSchema.js Show resolved Hide resolved
backend/src/models/gradeSchema.js Outdated Show resolved Hide resolved
backend/src/services/gradeService.js Show resolved Hide resolved
backend/src/utils/validationUtils.js Outdated Show resolved Hide resolved
TKanX and others added 3 commits January 24, 2025 09:53
…otype properties in path

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@TKanX TKanX requested a review from Copilot January 25, 2025 00:29

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, },
@TKanX TKanX merged commit a7d3940 into main Jan 25, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 📖 Improvements or additions to documentation enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Grade Data Management Functionality
1 participant