CSC/ECE 517 Spring 2023 - E2321. Reimplement QuestionnairesController and QuestionsController: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Update Implementation)
No edit summary
Line 39: Line 39:
##destroy: This is a DELETE endpoint that accepts a questionnaire ID and deletes that questionnaire.
##destroy: This is a DELETE endpoint that accepts a questionnaire ID and deletes that questionnaire.
##update: This is a PUT endpoint that accepts a questionnaire ID and parameters, and, updates that questionnaire with the given parameters.
##update: This is a PUT endpoint that accepts a questionnaire ID and parameters, and, updates that questionnaire with the given parameters.
##copy: This is a POST endpoint that accepts a questionnaire ID and creates a new questionnaire (copy) with the same attributes of that questionnaire.


==Testing Methodology==
==Testing Methodology==

Revision as of 02:38, 23 March 2023

E2321. Reimplement QuestionnairesController and QuestionsController

Problem Statement

The questionnaire is the superclass for all kinds of questionnaires and rubrics. Rubrics are used for evaluating submissions and teammate contributions, as well as taking quizzes and surveys, and all of these are subclasses of the Questionnaire class. In Expertiza, various types of questionnaires can be created, such as the Survey Questionnaire, Author Feedback Questionnaire, Bookmark Rating Questionnaire, Metareview Questionnaire, Quiz Questionnaire, Review Questionnaire, and Teammate Review Questionnaire. Each of these questionnaires can have zero or more questions, which are represented by the Question class. Typically, a questionnaire is associated with an assignment using the Assignment class.

The Questionnaire Controller is responsible for performing CRUD (Create, Read, Update, Delete) operations, such as copying and viewing questionnaires. On the other hand, the Questions Controller is responsible for creating, modifying, and deleting individual questions within a questionnaire. Questions can come in various types, such as checkboxes, multiple choice, text boxes, and more. However, each question object will always belong to a particular questionnaire. However, the current implementation suffers from several issues, such as mixing the responsibilities of the two controllers, using methods with identical names for different functionalities, and unclear or unused functionalities. Therefore, to improve the code quality and functionality, the two controllers should be implemented separately and adhere to the CRUD operations as much as possible. Additionally, the code needs to be refactored and optimized for better performance, and unused or unclear methods should be discarded. Finally, comprehensive tests should be written to ensure that the code is functioning correctly and free of code smells.


Goals of this Project

The goals of this Project are:

  1. Separating the responsibilities of the QuestionnairesController and QuestionsController
  2. Fix bugs in the existing functionality
  3. Implementing CRUD operations for each controller
  4. Discarding unused or unclear functionality
  5. Writing tests for the two controllers

By achieving these goals, both the controllers can have their basic CRUD functionalities as well as it will also ensure that the code readability and functionality of the code for the two controllers is increased. It will also help in resolving the existing bugs which will increase correctness of the code.

Implementation

A considerable amount of time and effort was necessary to review, understand, and re-implement the previous implementation of QuestionsController and QuestionnairesController. The team started with understanding how the Questionnaires and Questions module work by playing around with the Expertiza website. Once we had understanding of the flow, we started understanding the existing code written in the controllers. At first glance, it was visible that the QuestionnairesController was handling all the CRUD operations of Questions as well. We identified what functionalities did not belong in the QuestionnairesController and which redundant code had to be removed. The issues that we have addressed in our reimplementation project are listed as follows.

  1. Separating the responsibilities of the QuestionnairesController and QuestionsController: Initially the add_new_questions method present in questionnaire controller was responsible for adding a new question for the given questionnaire. As questions controller is responsible for creating a question, we defined a create method in questions controller which is responsible for the adding a new question for a given questionnaire. Since, to link a question to a questionnaire, we passed questionnaire_id using params and linked a new question created with the help of create method in questions controller to the required questionnaire and thus separated their responsibilities.
  2. Minor Bug fixes in the existing code: The following bugs in the existing code needed to be fixed.
    1. User was not able to delete Questionnaire: After careful debugging, we found that a path for delete questionnaire was not defined in the routes.rb file.
    2. Nil Class Error while saving empty questionnaire: We kept a check in the save_all_questions method to handle the error and allow the questionnaire to be saved empty.
  3. Fix the update method in QuestionnairesController: The original implementation of the method could not update the attributes of the questionnaire and it was used only to update the questions of that questionnaire. We reimplemented the method to update both the questionnaire attributes and each question if a change was made to them.
  4. Reimplement CRUD functionality and create JSON endpoints in QuestionsController: We reimplemented the following methods to create the required endpoints.
    1. index: This is a GET endpoint that responds with a list of all questions with their attributes.
    2. show: This is a GET endpoint that accepts a question id and responds with the attributes of that question if it exists.
    3. create: This is a POST endpoint that accepts the question parameters and creates a new question.
    4. destroy: This is a DELETE endpoint that accepts a question ID and deletes that question.
    5. update: This is a PUT endpoint that accepts a question ID and parameters, and, updates that question with the given parameters.
  5. Reimplement CRUD functionality and create JSON endpoints in QuestionnairesController: We reimplemented the following methods to create the required endpoints.
    1. index: This is a GET endpoint that responds with a list of all questionnaires with their attributes.
    2. show: This is a GET endpoint that accepts a questionnaire id and responds with the attributes of that questionnaire if it exists.
    3. create: This is a POST endpoint that accepts the questionnaire parameters and creates a new questionnaire.
    4. destroy: This is a DELETE endpoint that accepts a questionnaire ID and deletes that questionnaire.
    5. update: This is a PUT endpoint that accepts a questionnaire ID and parameters, and, updates that questionnaire with the given parameters.
    6. copy: This is a POST endpoint that accepts a questionnaire ID and creates a new questionnaire (copy) with the same attributes of that questionnaire.

Testing Methodology

Our work was to reimplement the QuestionsController.rb and QuestionnairesController.rb and create JSON endpoints for each CRUD operation. Since all the operations had dependencies on other Models and Helper functions which are not included in the reimplementation-back-end, it is not possible for us to use RSpec as the testing tool. To test each endpoint, we have used Postman to send a request to each endpoint. The video with the testing is available at https://bit.ly/E2321

Relevant Links

Contributors

This feature was created as part of Dr. Edward Gehringer's "CSC/ECE 517: Object-Oriented Design and Development" class, Spring 2023. The contributors were: Vineet Vimal Chheda, Rohan Jigarbhai Shah, and Aditya Srivastava. Our project mentor was Ankur Mundra (amundra@ncsu.edu)