CSC/ECE 517 Fall 2025 - E2551. Reimplementing SubmittedContentController

From Expertiza_Wiki
Revision as of 23:46, 28 October 2025 by Agaudan (talk | contribs)
Jump to navigation Jump to search

Introduction

About Expertiza

Expertiza is an open-source web application facilitating peer feedback and assessment in educational contexts. It enables students to submit work, review peer 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, as per the CRUD operations for submissions, different types of submissions, and their interactions. The goal is to implement new controller API styles and principles of Object-Oriented Programming such as SOLID.

Problem Description

The previously implemented SubmittedContentController in Expertiza needs to be refactored to enhance its functionality and maintainability. It handled various actions like file submissions and uploads, hyperlink submissions, and downloads, but the controller suffered 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 design, adhering to modularity and reusability standards.

Improvements in New Code

  • Index method for Submitted Content
  • Show method for Submitted Content
  • Create method for Submitted Content
  • SignedUpTeam Model
  • SignedUpTeam Model Test
  • SubmittedContent Model
  • SubmittedContent Model Test
  • Controller RSpec Tests
  • API Testing

Index method for Submitted Content

def index
  @submission_records = SubmittedContent.all
  render json: @submission_records, status: :ok
end

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

Show method for Submitted Content

def show
  submission_record = SubmittedContent.find(params[:id])
  render json: submission_record, status: :ok
rescue ActiveRecord::RecordNotFound
  render json: { error: "Submission not found" }, status: :not_found
end

The show function enables clients to retrieve 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 `SubmittedContent.find(params[:id])` query. If the record is found, it renders a JSON-formatted string via the `render` method. If the record is not found, it returns a JSON response containing an error message conveying the exception details, alongside an appropriate HTTP status code of `:not_found` (404).

Create method for Submitted Content

def create
  submission_record = SubmittedContent.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 method facilitates the creation of new submission records using HTTP POST requests. Data is validated via a `SubmittedRecord` instance by passing the submitted content parameters obtained from the client to the `SubmittedRecord.create` method. If the record is successfully saved, it returns a JSON response containing the newly created submission record along with an HTTP status code of `:created` (201), signifying a successful record creation. If not, it renders a JSON response containing the errors encountered during the submission attempt, along with an HTTP status code of `:unprocessable_entity`.

SignedUpTeam Model

The SignedUpTeam model represents a team signed up for a topic in Expertiza projects. Each instance of SignedUpTeam signifies the particular team signed up for a specific topic. The model facilitates the management and validation of these associations. This model is used by the Submitted Content Controller as a backbone for some implemented methods in this phase of the project.

class SignedUpTeam < ApplicationRecord
  belongs_to :team
  belongs_to :topic

  validates :team_id, presence: true
  validates :topic_id, presence: true
end

Improvements Summary

  • Enhanced clarity by separating controller responsibilities.
  • Refactored large methods into smaller, reusable methods.
  • Implemented proper HTTP response handling.
  • Increased code readability and modularity.
  • Improved test coverage through RSpec.

Testing and Validation

Testing was performed using RSpec and controller-specific tests to verify all CRUD operations for submitted content. JSON responses and status codes were validated to ensure consistency with API design principles. Edge cases like missing parameters, invalid records, and non-existent IDs were also tested.

Future Work

  • Introduce pagination for large submission datasets.
  • Add error logging for better debugging and maintenance.
  • Enhance test cases for performance and concurrency.
  • Improve model-level validations for file size and type.