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

Create Controller for UserAssessment #9

Open
Musoye opened this issue Oct 18, 2023 · 0 comments · May be fixed by #26
Open

Create Controller for UserAssessment #9

Musoye opened this issue Oct 18, 2023 · 0 comments · May be fixed by #26

Comments

@Musoye
Copy link
Collaborator

Musoye commented Oct 18, 2023

User Assessment Controller README

Schema for user_assessment table:

  • user_id (ID of the user)
  • assessment_id (ID of the assessment)
  • score (the score achieved in the assessment)

Create User Assessment Controller

  1. Create a User Assessment

    Create a new controller named userAssessment.js to manage user assessments. Implement a function createUserAssessment that allows the creation of a new user assessment. This function should accept the request object. Ensure that all required fields, including user_id, assessment_id, and score, are present; otherwise, return a response with a status code of 400 indicating the missing object. If everything is in order, create the new user assessment with a new ID (user_assessment_id) and return a response with a status code of 201 along with the details of the newly created user assessment.

  2. Get All User Assessments

    Create a function getAllUserAssessments that retrieves all user assessments from the database and returns a response with a status code of 200, along with the list of user assessments.

  3. Get User Assessment by ID

    Implement a function getUserAssessmentById that retrieves a user assessment with a specific user_assessment_id. The user_assessment_id will be part of the URL parameters. If the user assessment is not found, return a response with a status code of 404 and an error message indicating "User assessment not found." If the user assessment exists, return it with a status code of 200.

  4. Update User Assessment

    Create a function updateUserAssessment that allows the modification of a user assessment with a specific user_assessment_id. The user_assessment_id will be part of the URL parameters. If the user assessment is not found, return a response with a status code of 404 and an error message indicating "User assessment not found." If the user assessment is found, take the request object and update the user assessment accordingly, and return the updated record with a status code of 200.

  5. Delete User Assessment

    Implement a function deleteUserAssessment to delete a user assessment with a specific user_assessment_id. The user_assessment_id will be part of the URL parameters. If the user assessment is not found, return a response with a status code of 404 and an error message indicating "User assessment not found." After successfully deleting the user assessment, return a response with a status code of 200, along with details of the deleted user assessment.

HTTP Methods for Endpoints:

  • POST: For createUserAssessment and updateUserAssessment.
  • GET: For getAllUserAssessments and getUserAssessmentById.
  • DELETE: For deleteUserAssessment.

Routes:

  • /user_assessments: For createUserAssessment (POST) and getAllUserAssessments (GET).
  • /user_assessments/:user_assessment_id: For getUserAssessmentById (GET), updateUserAssessment (POST), and deleteUserAssessment (DELETE).

Please follow these guidelines to create the userAssessment controller, routes, and integrate them into your server.js. Additionally, consider implementing automated tests to verify the functionality of each endpoint.

@Arun-cn Arun-cn linked a pull request Oct 31, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant