CSC/ECE 517 Spring 2024 - E2417. Reimplement submitted content controller.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:
* Show method for Submitted Content
* Show method for Submitted Content
* Create method to Submit Content
* Create method to Submit Content
* Signed Up Topic Model
* SignedUpTopic Model
* Signed Up Team Model
* SignedUpTeam Model
* Submission Record Model
* SubmissionRecord Model
* Duty Model
* Duty Model
* Late Policy Model
* Late Policy Model
Line 58: Line 58:
The SignedUpTeam model represents the association between a topic and a team in the Expertiza project. Each instance of SignedUpTeam signifies that a particular team has signed up for a specific topic. This model facilitates the management and validation of these associations. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.
The SignedUpTeam model represents the association between a topic and a team in the Expertiza project. Each instance of SignedUpTeam signifies that a particular team has signed up for a specific topic. This model facilitates the management and validation of these associations. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.


== SignedUTopic Model ==
== SignedUpTopic Model ==
The SignUpTopic model in the Expertiza project manages topics that users can sign up for within specific assignments. It provides functionalities for topic creation, modification, and retrieval. Additionally, it handles the association between topics and various other entities such as teams, due dates, bids, and assignment questionnaires. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.  
The SignUpTopic model in the Expertiza project manages topics that users can sign up for within specific assignments. It provides functionalities for topic creation, modification, and retrieval. Additionally, it handles the association between topics and various other entities such as teams, due dates, bids, and assignment questionnaires. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.  



Revision as of 00:14, 25 March 2024

E2417. Reimplement Submitted Content Controller

This page provides a description of the Expertiza based OSS Project E2417. Reimplement the SubmittedContentController

About Expertiza

Expertiza is an open-source web application facilitating peer feedback and assessment in educational courses. It enables students to submit work, review peers' submissions, and receive feedback. The platform supports anonymous peer reviews, grading rubrics, and discussion forums. Its goal is to enhance collaborative learning and improve the quality of student work through constructive criticism.

Objective

A submitted content controller should have the functionalities to manage the submitted content, for eg, the CRUD operations for submissions, different types of submissions, etc. The goal here is to implement this controller via API's and use principles of Object-Oriented Programming such as SOLID.

Problem Description

The reimplementation of SubmittedContentController in Expertiza needs to be done to enhance its functionality and maintainability. It should handle various tasks like file submissions and uploads, hyperlink submissions, and downloads, but the controller suffers from code redundancy and mixed responsibilities within methods. The reimplementation aims to ensure participants receive appropriate messages and HTTP status codes for actions like uploading files and deleting them, while also using SOLID principles, refactoring DRY code and minimizing excessive use of instance variables. The goal is to optimize the controller's design, adhering to best practices in readability and modularity.

Improvements in New Code

Index, show and create operations have been performed for the submission content controller.

  • Index method for Submitted Content
  • Show method for Submitted Content
  • Create method to Submit Content
  • SignedUpTopic Model
  • SignedUpTeam Model
  • SubmissionRecord Model
  • Duty Model
  • Late Policy Model
  • Submitted Content Helper

Index method for Submitted Content

 def index
   @submission_record = SubmissionRecord.all
   render json: @submission_record, status: :ok
 end

The index function is responsible for retrieving the data for the users. This function serves to fetch all submission records from the database using the `SubmissionRecord` model and assigns them to an instance variable `@submission_record`. The status: :ok parameter ensures that the HTTP response status is set to 200, indicating a successful request. This function operates on the HTTP GET method, allowing clients to request information from the server. The rendered JSON response includes the submission records, providing comprehensive data to clients.

Show method for Submitted Content

 def show
   @submission_record = SubmissionRecord.find(params[:id])
   render json: @submission_record, status: :ok
 rescue ActiveRecord::RecordNotFound => e
   render json: { error: e.message }, status: :not_found
 end

The show function enables clients to retrieve detailed information about specific submission records stored in the backend database and operates on HTTP GET method. The function retrieves the submission record associated with the provided ID using the SubmissionRecord.find(params[:id]) query. If the record is found, it is serialized into JSON format using the render method. If the record is not found, it renders a JSON response containing an error message conveying the exception's details, alongside an appropriate HTTP status code of :not_found (404).

Create method to Submit Content

 def create
   @submission_record = SubmissionRecord.create(submitted_content_params)
   if @submission_record.save
     render json: @submission_record, status: :created
   else
     render json: @submission_record.errors, status: :unprocessable_entity
   end
 end

The create function facilitates the creation of new submission records using HTTP POST method. The function initializes a new SubmissionRecord instance by passing the submitted content parameters obtained from the client to the SubmissionRecord.create method. If the record is successfully saved, indicating that the submission was processed without errors, the function renders a JSON response containing the newly created submission record along with an HTTP status code of :created (201), signifying successful record creation. If not, it renders a JSON response containing the errors encountered during the submission attempt, along with an appropriate HTTP status code of :unprocessable_entity (422), indicating that it cannot process it due to validation errors.

SignedUpTeam Model

The SignedUpTeam model represents the association between a topic and a team in the Expertiza project. Each instance of SignedUpTeam signifies that a particular team has signed up for a specific topic. This model facilitates the management and validation of these associations. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.

SignedUpTopic Model

The SignUpTopic model in the Expertiza project manages topics that users can sign up for within specific assignments. It provides functionalities for topic creation, modification, and retrieval. Additionally, it handles the association between topics and various other entities such as teams, due dates, bids, and assignment questionnaires. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.

SubmissionRecord Model

The SubmissionRecord model in the Expertiza project manages records of submissions made by users for specific assignments. It ensures that essential attributes related to the submission, such as content, operation, team ID, user, and assignment ID, are present through validations. This model is used by the Submitted Content Control so a skeleton for the same was implemented in this phase of the project.

Duty Model

The Duty model in the Expertiza project manages duties assigned to teams within assignments. It validates the attributes of duties, including their names and maximum member counts, and provides a method for determining whether a duty can be assigned to a particular team. The Submitted Content Controller has an indirect dependency on this model. This model will be implemented in the next phase of the project.

Late Policy Model

The LatePolicy model in the Expertiza project manages late submission policies. It associates late policies with users (presumably instructors) and assignments. The model provides validations for policy attributes and methods for checking policy names and updating penalty objects when policies are modified. The Submitted Content Controller has an indirect dependency on this model. This model will be implemented in the next phase of the project.

Submitted Content Helper

The SubmittedContentHelper module facilitates the unzipping of files, aiding in the management of uploaded content within web applications. Its unzip_file method efficiently extracts the contents of a zip file to a specified directory, with robust error handling to ensure reliability. By leveraging the RubyZip gem, this module helps in the process of handling zip files, enhancing the backend's functionality. In the previous code, to extract files, it was tightly coupled with the unzip_files method, making it less reusable and harder to maintain. After refactoring the code, a separate private method is formed to unzip the file. By separating the extract_entry function into its own module or file, each component now has a single responsibility: the extract_entry function is responsible solely for extracting a single entry from a zip file. Single Responsibility Principle is followed.

Deployment Link

http://152.7.177.13:3000/api-docs

  • Credentials:
   Username: admin 
   Password: admin

Github Repo

https://github.com/Neel317/reimplementation-back-end

PR Link

https://github.com/expertiza/reimplementation-back-end/pull/78/files

Future Scope (Phase 2 of Project)

Links

  1. Github Repo
  2. Pull request

References

  1. Expertiza on GitHub
  2. The live Expertiza website
  3. Expertiza project documentation wiki
  4. Rspec Documentation