CSC/ECE 517 Fall 2023 - E2371. Reimplement quiz questionnaires controller: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 49: Line 49:
We have reimplemented the `Api::V1::QuizQuestionnairesController` in Ruby on Rails by making several key changes to improve code readability, maintainability, and error handling. Below are the main modifications made to the code:
We have reimplemented the `Api::V1::QuizQuestionnairesController` in Ruby on Rails by making several key changes to improve code readability, maintainability, and error handling. Below are the main modifications made to the code:


1. **Changed Function Names**: The function names have been chosen to be more concise and descriptive. For example, the method originally named 'copy' is used to create a copy of a questionnaire, and this change makes the code more intuitive.
1. Changed Function Names: The function names have been chosen to be more concise and descriptive. For example, the method originally named 'copy' is used to create a copy of a questionnaire, and this change makes the code more intuitive.


2. **Improved Code Comments**: Detailed comments have been added to each action method, explaining the purpose of the method and the expected parameters. This documentation is invaluable for both developers working on the code and anyone looking to understand how the API functions.
2. Improved Code Comments: Detailed comments have been added to each action method, explaining the purpose of the method and the expected parameters. This documentation is invaluable for both developers working on the code and anyone looking to understand how the API functions.


3. **Improved Error Handling**: The code has been enhanced to handle exceptions more specifically, such as catching `ActiveRecord::RecordNotFound` and `ActiveRecord::RecordInvalid` exceptions. This results in more informative error messages, which is beneficial for debugging and communication with clients.
3. Improved Error Handling: The code has been enhanced to handle exceptions more specifically, such as catching `ActiveRecord::RecordNotFound` and `ActiveRecord::RecordInvalid` exceptions. This results in more informative error messages, which is beneficial for debugging and communication with clients.


4. **Refactored Create Method**: The `create` method has been refactored to improve clarity and robustness. It now first checks user privileges using the `check_privilege` method. If the user has the required permissions, it proceeds to create a new `QuizQuestionnaire` based on the provided parameters. This refactoring helps separate concerns and makes the code more organized.
4. Refactored Create Method: The `create` method has been refactored to improve clarity and robustness. It now first checks user privileges using the `check_privilege` method. If the user has the required permissions, it proceeds to create a new `QuizQuestionnaire` based on the provided parameters. This refactoring helps separate concerns and makes the code more organized.


5. **Consistent Status Codes**: The code now consistently uses HTTP status codes to indicate the result of API requests. For instance, it uses `status: :not_found` when a requested resource is not found, which aligns with common HTTP conventions. This consistency in status codes improves the predictability of API responses.
5. Consistent Status Codes: The code now consistently uses HTTP status codes to indicate the result of API requests. For instance, it uses `status: :not_found` when a requested resource is not found, which aligns with common HTTP conventions. This consistency in status codes improves the predictability of API responses.


6. **Consistent JSON Response Format**: The JSON responses have been structured consistently to follow a standardized format. Keys like "model_object" and "participants" are used to make it easier for client applications to consume the API. This consistency simplifies the parsing of responses on the client side.
6. Consistent JSON Response Format: The JSON responses have been structured consistently to follow a standardized format. Keys like "model_object" and "participants" are used to make it easier for client applications to consume the API. This consistency simplifies the parsing of responses on the client side.


These changes enhance the overall quality of the code, making it more accessible for developers, improving the API's reliability, and providing a consistent and user-friendly experience for clients interacting with the API.
These changes enhance the overall quality of the code, making it more accessible for developers, improving the API's reliability, and providing a consistent and user-friendly experience for clients interacting with the API.

Revision as of 23:30, 30 October 2023

This wiki page is for the description of changes made under E2371 OSS assignment for Fall 2023, CSC/ECE 517

Introduction

Expertiza is a prominent open-source project founded on the Ruby on Rails framework, serving as a collaborative effort between the faculty and students of NC State. This web application facilitates instructors in generating customized assignments, including both new and existing tasks. Additionally, instructors can establish a roster of topics for student enrollment. Within Expertiza, students have the ability to form teams for collaborative work on various projects and assignments. An integral aspect of the platform is the provision for students to conduct peer reviews of their peers' submissions.

Distinguished by its support for a diverse array of document types, Expertiza enables submission of various formats such as URLs and wiki pages. Serving as an open-source learning management system developed using Ruby on Rails, Expertiza embodies an extensive suite of functionalities that empower students to submit and engage in peer review processes encompassing various learning objects like articles, codes, and websites. Instructors wield the capability to oversee and assess the submissions made by students through the platform. Expertiza is instrumental in facilitating instructors and teaching assistants in managing assignments for the courses they administer.


Overview of the Classes

participants_controller.rb:

The ParticipantsController is responsible for managing participants in an application. Participants can be associated with either "Course" or "Assignment" models. It handles actions related to creating, updating, retrieving, and deleting participants. Inherit copies existing participants from a course down to its assignment while bequeath copies existing participants from an assignment up to its course. It has two private methods namely copy_participants_from_source_to_target which copies participants from source to target and participant_params.

assignment_participant.rb:

The assignment_participant.rb is a model class that has many associations including ‘assignment’. This association signifies that an AssignmentParticipant belongs to a specific assignment. The AssignmentParticipant class includes several attributes such as avg_vol_per_round, overall_avg_vol and handle that are vital for its functionality. There are many methods present which collectively facilitate various actions and operations related to managing participants in assignments, including reviewing, copying, importing, and handling file paths and deadlines. They include review_file_path, current_stage, stage_deadline, current_user_is_reviewer, reviews, dir_path, etc. There are also a couple of methods that use digital signatures such as assign_copyright and verify_digital_signature.

course_participant.rb:

The course_participant model has a class named CourseParticipant that inherits from a class called Participant. It is used to manage participants in courses, allowing for copying participants to assignments and importing new participants into a course. It consists of three methods namely copy, import and path. Copy creates a copy of a course participant for an assignment. Path method returns the path of the course participant while self.import method is used for importing course participants by taking row_hash, session, and id as parameters.


Background of the Project

The Expertiza project involves the reimplementing of the participants_controller.rb and participants.rb files, along with their respective child classes. The previous iteration of the participant model and controller underwent reimplementations in prior semesters, resulting in tests that relied extensively on mocks and stubs due to missing components.

The participants_controller.rb file encapsulates various methods and functionalities vital to managing participants within the system. This includes actions like adding, updating, and deleting participants, inheriting participants from courses to assignments, bequeathing participants from assignments to courses, changing participant handles, viewing copyright grants, and more. The controller makes use of helper functions, associations, and delegate methods to streamline participant operations.

Meanwhile, the course_participants.rb file extends the functionality of the base participant class, focusing on operations specific to course participants. This includes copying participants to assignments, importing course participants, and defining paths for course participants within the project.

The base participant.rb file defines the fundamental structure and behavior for all participants in the system, including shared associations, delegate methods, and validations. The file incorporates methods related to participant handling, user information retrieval, email functionalities, authorization, sorting, and export functionality.

The project's primary objective revolves around enhancing the reliability and functionality of the participant-related components, thereby fortifying the overall system's capabilities and improving the testing process to ensure robustness and stability within the Expertiza platform.

The reimplementation must make sense; when reviewing the original model, we discovered that certain functions were unnecessary for the controller class and model in question and needed to be implemented in a different model. The majority of the adjustments were made to separate methods with a single capability pertinent to certain classes by deleting, combining, and replacing methods.To improve readability, notes are provided to every technique. The discussion of the reimplementations continues below with further details.


Design Decisions

quiz_questionnaire_controller.rb:

We have reimplemented the `Api::V1::QuizQuestionnairesController` in Ruby on Rails by making several key changes to improve code readability, maintainability, and error handling. Below are the main modifications made to the code:

1. Changed Function Names: The function names have been chosen to be more concise and descriptive. For example, the method originally named 'copy' is used to create a copy of a questionnaire, and this change makes the code more intuitive.

2. Improved Code Comments: Detailed comments have been added to each action method, explaining the purpose of the method and the expected parameters. This documentation is invaluable for both developers working on the code and anyone looking to understand how the API functions.

3. Improved Error Handling: The code has been enhanced to handle exceptions more specifically, such as catching `ActiveRecord::RecordNotFound` and `ActiveRecord::RecordInvalid` exceptions. This results in more informative error messages, which is beneficial for debugging and communication with clients.

4. Refactored Create Method: The `create` method has been refactored to improve clarity and robustness. It now first checks user privileges using the `check_privilege` method. If the user has the required permissions, it proceeds to create a new `QuizQuestionnaire` based on the provided parameters. This refactoring helps separate concerns and makes the code more organized.

5. Consistent Status Codes: The code now consistently uses HTTP status codes to indicate the result of API requests. For instance, it uses `status: :not_found` when a requested resource is not found, which aligns with common HTTP conventions. This consistency in status codes improves the predictability of API responses.

6. Consistent JSON Response Format: The JSON responses have been structured consistently to follow a standardized format. Keys like "model_object" and "participants" are used to make it easier for client applications to consume the API. This consistency simplifies the parsing of responses on the client side.

These changes enhance the overall quality of the code, making it more accessible for developers, improving the API's reliability, and providing a consistent and user-friendly experience for clients interacting with the API.

assignment_participant.rb:

This is the reimplemented AssignmentParticipant class. It is a subclass of the Participant class and includes additional functionalities and methods specific to participants assigned to an assignment in the system.

In the `assignment_participant.rb` class, several changes and improvements have been made to enhance the readability and maintainability of the code. Here are the specific modifications made:


1. Removed certain comments and obsolete code for better readability and clarity.

2. Introduced the safe navigation operator (`&.`) in several places to avoid nil errors, particularly in cases where object references may be nil.

3. Simplified certain methods, such as `reviewers` and `feedback`, for cleaner and more readable code.

4. Improved string formatting for directory paths and file paths to enhance readability.

5. Enhanced error handling in the `import` method to provide more informative error messages and handle exceptional cases more gracefully.

These changes aim to make the code more maintainable and concise while ensuring that the functionality and integrity of the `AssignmentParticipant` class remain intact.

course_participant.rb:

The following changes were reimplemented in the course_participant.rb

In the CourseParticipant class, several changes and improvements have been made to enhance the readability and maintainability of the code. Here are the specific modifications made:

1] The copy method has been simplified using the find_or_create_by method, which helps to find an existing record or create a new one if it doesn't exist.

2] In the import method, the find_or_create_by method has been used to both find or create a user and find or create a course participant. This helps to streamline the process and handle the cases where the records may or may not exist.

3] The path method has been refactored to use the safe navigation operator (&.) to avoid potential nil errors during the construction of the path. This ensures that the code is more robust and handles potential null references gracefully.

These changes aim to make the code more concise and readable, without compromising the functionality or integrity of the CourseParticipant class.


Relevant Links

Github repository: https://github.com/krishna5701/reimplementation-back-end

Pull request: https://github.com/expertiza/reimplementation-back-end/pull/49


Team

Mentor

Muhammad Ali Qureshi

Student Team

1] Raj Madhu (rmadhu@ncsu.edu)

2] Jinil Shukla (jshukla@ncsu.edu)

3] Dhyey Shah (dshah22@ncsu.edu)