CSC/ECE 517 Fall 2023 - E2369. Reimplement duties controller.rb and badges controller.rb

From Expertiza_Wiki
Revision as of 01:42, 31 October 2023 by Avarma4 (talk | contribs)
Jump to navigation Jump to search

Topic Overview & Prior Work

Background

duties_controller.rb

The actions defined by this duties_controller include create, update, and remove. The new duty is saved to the database using the create action. The update action is used to update the duty in the database, while the edit action renders the form for editing an existing duty. Lastly, a duty can be removed from the database by using the delete action. All things considered, Expertiza's Duties module aids in the management of duties.

badges_controller.rb

A new Badge instance is created by the controller using the user-supplied parameters through the use of the create action. If an image file is attached, it additionally saves it and modifies the badge instance's image_name attribute.

Previous Work

The prior implementation of the duties and badges controllers was based on a Rails MVC application rather than strictly as an API built on Rails. The handling of requests and responses did not align with the API architecture, thus needing adjustments to ensure a more suitable API-style communication. Furthermore, the previous implementation lacked comprehensive testing, a crucial aspect that needs attention in the reimplementation.

Planned Work

Functions to implement

Functionalities for Duties

  • Create Action: Implement the functionality to add and persist new duties to the database.
  • Edit Action: Develop the mechanism to modify existing duties, providing a form for editing duties.
  • Update Action: Enhance the capability to update existing duties already stored in the database.

Functionalities for Badges

  • Create Action: Implement the creation process for new badges, utilizing user-provided parameters.
  • Image Handling: Develop a mechanism to handle attached image files, ensuring their storage.
  • Update Action: Enhance the functionality to update the image_name attribute associated with a badge instance, especially when an image is attached.

Notes for Reimplementation

  • Ensure that all interactions with the controllers adhere to API conventions, returning data in JSON format.
  • Thoroughly test all REST endpoints for both duties and badges, covering various scenarios to validate their functionality. Comprehensive testing should encompass both success and failure scenarios.

Implementation

Duties Controller

class Api::V1::DutiesController < ApplicationController
 before_action :set_duty, only: %i[ show update destroy ]

index Method: Function: Retrieves all duties. HTTP Verb: GET URL Endpoint: /duties Description: Fetches all duties from the database using the Duty.all method and renders a JSON response containing all duties.

 # GET /duties
 def index
   @duties = Duty.all
   render json: @duties, status: :ok
 end

show Method: Function: Retrieves a specific duty. HTTP Verb: GET URL Endpoint: /duties/:id Description: Finds a duty by its ID and renders a JSON response containing the specific duty

 # GET /duties/1
 def show
   render json: @duty, status: :ok
 end
 # POST /duties
 def create
   @duty = Duty.new(duty_params)
   if @duty.save
     render json: @duty, status: :created, location: @duty
   else
     render json: @duty.errors, status: :unprocessable_entity
   end
 end
 # PATCH/PUT /duties/1
 def update
   if @duty.update(duty_params)
     render json: @duty
   else
     render json: @duty.errors, status: :unprocessable_entity
   end
 end
 # DELETE /duties/1
 def destroy
   @duty.destroy
   render json: { message: "Duty was successfully destroyed." }, status: :ok
 end
 private
   # Use callbacks to share common setup or constraints between actions.
   def set_duty
     @duty = Duty.find(params[:id])
   end
   # Only allow a list of trusted parameters through.
   def duty_params
     params.require(:duty).permit(:name, :assignment_id, :max_members_for_duties)
   end
end

Testing Methodology

Conclusion

In conclusion, the reimplementation project for the Duties and Badges modules within Expertiza holds significant importance in aligning the existing functionalities with API standards and rectifying the deficiencies identified in the previous implementation.

The Duties module, managed by the duties_controller.rb, plays a pivotal role in handling duties' creation, editing, and deletion within the system. Likewise, the Badges module, governed by the badges_controller.rb, oversees the creation and management of badges, including the handling of image files.

The prior implementation's primary shortcomings revolved around treating the system as a traditional Rails MVC application rather than as a Rails API. This resulted in non-compliance with API standards in handling requests and responses, which this reimplementation aims to rectify. Additionally, the inadequacy of testing procedures highlighted the necessity for a comprehensive testing suite covering various scenarios to ensure the robustness and reliability of the system.

The planned work includes adhering strictly to API-style interactions, returning data in JSON format, and implementing thorough testing for all REST endpoints, ensuring the functionalities for both Duties and Badges are rigorously verified across success and failure scenarios.

By addressing these issues and meticulously implementing the planned functionalities, this reimplementation aims to enhance the system's efficiency, robustness, and adherence to API conventions, ensuring a more reliable and scalable platform for managing duties and badges within Expertiza.

Useful Links

Contributors

Group members:

Siddhi Mule

Rishabh Muzhangathu

Aditi Gulabchand Varma

Mentor:

Renji Joseph Sabu