CSC/ECE 517 Spring 2023 E2342: Reimplement Participants Model and Controller

From Expertiza_Wiki
Jump to navigation Jump to search

Background

In expertiza, there are two different models: Course and Assignment. Although an Assignment is a part of a Course, students can participate in a Course or an Assignment independently.

The ParticipantsController provides functionalities for listing the participants of a course or an assignment, adding a participant to a course or an assignment, updating the authorizations of a participant (can_submit, can_review, can_take_quiz), updating the handle of a participant for an assignment, inheriting course participants to its assignment, bequeathing assignment participants to its course and deleting a participant from a course or an assignment.

Project Purpose

The aim of our project is to integrate the reimplemented versions of Participants Model and Participants Controller while maintaining the existing functionality of the feature. We plan on restricting all the business logic to the model, which will also handle all of the interactions with the database. The controller, on the other hand, will be responsible only for accepting appropriate input and returning the results in a JSON format. The controller will also query the database but write operations would only be done in the model. The test suite will also be updated to reflect the above-mentioned development plan as we develop a comprehensive test plan for both the model as well as the controller.

Project Design

High-level Design Diagram

The architecture diagram shown below serves the purpose of our high-level design diagram. As seen in the figure, the user interacts with the web client i.e. browser which sends an HTTP request to the web server available in the back-end. The web server is responsible for handling the rails routes corresponding to the RESTful endpoints of the APIs that we have developed. The endpoints then route to the corresponding method in the participants controller where the intended functionality is carried out. For certain APIs, such as inherit, this involves interacting with the participants model and the database to update the state of the system. For other simpler features, such as index, the controller method handles all the processing. The method responds with a JSON structure which is sent back as an HTTP response to the front-end and then returned back to the client.
The diagram lays out the general workflow of a user interacting with the system and helps the viewer understand the responsibilities of the model, controller, and view in our system. Models are responsible for dealing with the business logic of the features and interact with the database for all data operations. Controllers are responsible for taking appropriate input and returning JSON-formatted output without changing any data or the state of the system. Lastly, views are responsible for rendering the output in a user-friendly interface for the client.

Use Case Diagram

The following Use Case Diagram demonstrates the primary functionality relevant to participants for different types of users in the system. We've highlighted three primary users of our system who might use the participants features - instructors/TAs, participants (who are expected to be students), and admins.

Implementation

This project has been split up in two phases, with phase 1 being the re-implementation of the participants model and controller. The second phase of the project focuses on the integration of the newly implemented versions of participants model and controller.
During the first phase, the controller employed an API-first approach while maintaining all the existing functionality in an efficient, robust and simple manner. Specifically for the participants controller, we added seven different API endpoints to extend the current functionalities while modifying the code to support these APIs. For the participants model, we removed all unnecessary functionality and retained only the core business logic for participants. The details for the model changes and new endpoints have been discussed later in this section.
For the second phase, we plan on maintaining the ideology of restricting business logic to the model and API logic to the controller. We will fill in the missing gaps and modify the code after re-implementation to enable integration of the new code. The proposed changes for this phase have been discussed later in this section.

Assumptions

  1. The CourseParticipant and AssignmentParticipant models implement the copy method which copies participants from the course to assignment and vice-versa. This functionality is used in the inherit and bequeath methods.

Phase 1a: Reimplementation of Participants Model

The participants model file participant.rb was re-implemented to include only the necessary business logic and remove unnecessary functionality.
Note: More details on this can be found here.

Task Status Testing
Replaced force_delete method with leave_team method Implemented Completed
mail_assigned_reviewers method was removed Implemented N/A
able_to_review method was eliminated Implemented N/A
email method was removed Implemented N/A

Merged export and export_fields Methods
We didn't implement this task as merging two functions became a hassle for debugging and testing and fixing errors present in the code. Instead, it is generally considered good programming practice to break down large functions into smaller, more manageable ones. This principle is commonly known as the "Single Responsibility Principle," which states that a function or module should have only one reason to change. By breaking down a large function into smaller functions, made our code more modular and easier to read, understand, and maintain.


Phase 1b: Reimplementation of Participants Controller

The endpoints implemented as part of this phase have been summarized here. The code for these can be found in the participants_controller.rb file.
Note: Detailed API documentation and other details for these can be found here.

 #  Method Endpoint Description
1 index GET /participants/index/:model/:id returns a list of participants of an assignment or a course
2 create POST /participants/:model/:id creates a participant in an assignment or a course
3 update_handle PATCH /participants/change_handle/:id updates the participant's handle for an assignment
4 update_authorizations PATCH /participants/update_authorizations/:id updates the participant's permissions for an assignment or a course depending on the role
5 delete DELETE /participants/:id deletes a participant from an assignment or a course
6 inherit GET /participants/inherit/:id copies existing participants from a course down to its assignment
7 bequeath GET /participants/bequeath/:id copies existing participants from an assignment up to its course

Current Work

Task Notes
Move business logic from controller to model The business logic in the create method in participants_controller was moved to the Participant model
Modify the team method in Participants model The team method uses TeamsParticipant instead of TeamsUser based on E2304
Replace sort_by_name method with sort_participants method in Participants model sort_participants can either sort by id of the participants or name of the corresponding user depending on the parameter passed
Modify destroy in participants_controller The destroy method uses the delete method from the Participants model to check if the participant is on a team or assigned as a reviewer or reviewee before destroying
Fill testing gaps Tests were updated after the integration of Participant model with participants_controller
Add comments Clear and concise comments to explain what each section of the code is doing, why it is doing it, and how it fits into the overall task

Test Plan

So far we've written individual tests for the model and controller files of the participants functionality. With the goal of this project being the integration of the two, we will look to add some tests which facilitate the combined working of the two files. This might include modifying existing test scenarios as well as writing new ones. We expect the number of tests to go up as well as the overall code coverage to improve after this project. The existing test suites for the model and controller can be found below.

Model test suite

The testing framework used here is RSpec. The participants.rb contains many methods and associations with other models. Hence, to test the methods in participants, the other dependent methods have to be stubbed. To deal with the models, dummy models/dummy app can be created which will act as the associated classes. We have created all the required dummy classes by scaffolding them.

To create test fixtures and to build the required models, Factory Bot has been used. Two separate files, factories.rb and factory_bot.rb was created to build the factories. Four participants and other required fields were created as fixtures after which the tests were written.

To run the tests:
1. git clone https://github.com/amarthyasa/reimplementation-back-end/tree/testing_files
2. cd reimplementation-back-end/
3. bundle install
4. bundle exec rspec spec/models/participants_spec.rb

More details on the individual tests can be found here

Controller test suite

The testing framework used here is RSpec. The participants_controller.rb has dependencies on models and methods which are yet to be implemented. In the meantime, to test the API, we have used stubs and mocks. We have created some new models and added some associations in them which were required for stubbing.

To run the tests:
1. git clone https://github.com/devashish-vachhani/reimplementation-back-end
2. cd reimplementation-back-end/
3. bundle install
4. bundle exec rspec spec/requests/api/v1/participants_spec.rb

More details on the individual tests can be found here

Contributors

  1. Saksham Pandey (spandey5@ncsu.edu)
  2. Devashish Vachhani (dvachha@ncsu.edu)
  3. Karthik K Jayakumar (kkunnum@ncsu.edu)

Mentor: Rucha Kolekar (rbkoleka@ncsu.edu)

Thanks to participants model re-implementation team

Relevant Links