CSC/ECE 517 Fall 2023 - E2370. Reimplement join team requests controller: Difference between revisions
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
==New Files== | ==New Files== | ||
#app/controllers/join_team_requests_controller.rb | '''#app/controllers/join_team_requests_controller.rb''' <br> | ||
#app/models/join_team_requests.rb | |||
#spec/requests/api/v1/join_team_requests_spec.rb | The original code has variables like 'P', 'D' and 'A' which lead to ambiguity and they had to be changed to <br> | ||
<pre> | |||
class Api::V1::JoinTeamRequestsController < ApplicationController | |||
# Constants used to indicate status for the request | |||
# The datatype for status is string | |||
PENDING = 'P' | |||
DECLINED = 'D' | |||
ACCEPTED = 'A' | |||
</pre> | |||
We also added new methods to the controller for Create, Read, Update and Delete functionality.<br> | |||
For example <br> | |||
<pre> | |||
def update | |||
if @join_team_request.update(join_team_request_params) | |||
render json: { message: 'JoinTeamRequest was successfully updated' }, status: :ok | |||
else | |||
render json: { errors: @join_team_request.errors.full_messages }, status: :unprocessable_entity | |||
end | |||
end | |||
</pre> | |||
Apart from this, we added the 'accept' and 'decline' methods to handle accept/decline requests | |||
<pre> | |||
def accept | |||
@join_team_request.status = ACCEPTED | |||
if @join_team_request.save | |||
render json: { message: 'JoinTeamRequest accepted successfully' }, status: :ok | |||
else | |||
render json: { errors: @join_team_request.errors.full_messages }, status: :unprocessable_entity | |||
end | |||
end | |||
</pre> | |||
<pre> | |||
def decline | |||
@join_team_request.status = DECLINED | |||
if @join_team_request.save | |||
render json: { message: 'JoinTeamRequest declined successfully' }, status: :ok | |||
else | |||
render json: { errors: @join_team_request.errors.full_messages }, status: :unprocessable_entity | |||
end | |||
end | |||
</pre> | |||
'''#app/models/join_team_requests.rb'''<br> | |||
We have added the model file to handle join team requests coming from one student to the other. | |||
'''#spec/requests/api/v1/join_team_requests_spec.rb'''<br> | |||
This spec file was added to handle the testing for our controller. More information about testing is given in the testing section. | |||
==File Changes== | ==File Changes== | ||
Line 64: | Line 115: | ||
== Testing == | == Testing == | ||
We have thoroughly tested our code using Postman and the controller works flawlessly. <br> | We have thoroughly tested our code using Postman and the controller works flawlessly as shown below. <br> | ||
Here is the video which shows testing the controller using Postman -<br> | |||
https://drive.google.com/file/d/1hS8vjWwHznWks9Qj7S-YIWdCfqqcsyhe/view?usp=sharing | |||
Following is a link to the Swagger test file - <br> | Following is a link to the Swagger test file - <br> | ||
https://github.com/manoj-ayyappan/csc517_program3_E2370/blob/main/swagger/v1/swagger.yaml | https://github.com/manoj-ayyappan/csc517_program3_E2370/blob/main/swagger/v1/swagger.yaml <br> | ||
Revision as of 20:12, 2 November 2023
Expertiza
Expertiza is a Ruby on Rails based open source project. Instructors have the ability to add new projects, assignments, etc., as well as edit existing ones. Later on, they can view student submissions and grade them. Students can also use Expertiza to organize into teams to work on different projects and assignments and submit their work. They can also review other students' submissions.
Problem Statement
The controller join_team_requests_controller.rb contains functions to create, list, update, delete, and decline requests to join teams. This is a fairly straightforward controller with basic functionalities which is easily tested using Postman. The objective of this project was to change the operation of this controller to suit our API.
New Files
#app/controllers/join_team_requests_controller.rb
The original code has variables like 'P', 'D' and 'A' which lead to ambiguity and they had to be changed to
class Api::V1::JoinTeamRequestsController < ApplicationController # Constants used to indicate status for the request # The datatype for status is string PENDING = 'P' DECLINED = 'D' ACCEPTED = 'A'
We also added new methods to the controller for Create, Read, Update and Delete functionality.
For example
def update if @join_team_request.update(join_team_request_params) render json: { message: 'JoinTeamRequest was successfully updated' }, status: :ok else render json: { errors: @join_team_request.errors.full_messages }, status: :unprocessable_entity end end
Apart from this, we added the 'accept' and 'decline' methods to handle accept/decline requests
def accept @join_team_request.status = ACCEPTED if @join_team_request.save render json: { message: 'JoinTeamRequest accepted successfully' }, status: :ok else render json: { errors: @join_team_request.errors.full_messages }, status: :unprocessable_entity end end
def decline @join_team_request.status = DECLINED if @join_team_request.save render json: { message: 'JoinTeamRequest declined successfully' }, status: :ok else render json: { errors: @join_team_request.errors.full_messages }, status: :unprocessable_entity end end
#app/models/join_team_requests.rb
We have added the model file to handle join team requests coming from one student to the other.
#spec/requests/api/v1/join_team_requests_spec.rb
This spec file was added to handle the testing for our controller. More information about testing is given in the testing section.
File Changes
#app/models/participant.rb
Original code
class Participant < ApplicationRecord belongs_to :user belongs_to :assignment, foreign_key: 'assignment_id', inverse_of: false
Modified code
class Participant < ApplicationRecord belongs_to :user belongs_to :assignment, foreign_key: 'assignment_id', inverse_of: false has_many :join_team_requests, dependent: :destroy
#config/routes.rb
Original code
Rails.application.routes.draw do mount Rswag::Api::Engine => 'api-docs' mount Rswag::Ui::Engine => 'api-docs' # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html post '/sign_up_student', to: 'signed_up_teams#sign_up_student' end end
Modified code
Rails.application.routes.draw do mount Rswag::Api::Engine => 'api-docs' mount Rswag::Ui::Engine => 'api-docs' # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html post '/sign_up_student', to: 'signed_up_teams#sign_up_student' end end resources :join_team_requests do collection do post 'decline/:id', to:'join_team_requests#decline' post 'accept/:id', to:'join_team_requests#accept' end end
Testing
We have thoroughly tested our code using Postman and the controller works flawlessly as shown below.
Here is the video which shows testing the controller using Postman -
https://drive.google.com/file/d/1hS8vjWwHznWks9Qj7S-YIWdCfqqcsyhe/view?usp=sharing
Following is a link to the Swagger test file -
https://github.com/manoj-ayyappan/csc517_program3_E2370/blob/main/swagger/v1/swagger.yaml
Modifications
- Created new methods for the Join Team Requests Controller to support CRUD functionality.
- Added an accept and decline method.
- Modified the status to use constants such as 'PENDING', 'ACCEPTED', and 'DECLINED' instead of 'P', 'D', 'A'.
Results
We've successfully reimplemented the Join Teams Request Controller, achieving a more comprehensive feature set by introducing new methods for CRUD functionality, facilitating the acceptance and rejection of join requests, and adopting meaningful status constants like 'PENDING,' 'ACCEPTED,' and 'DECLINED' in place of less intuitive single-character codes. These improvements not only expand the controller's capabilities but also enhance its readability and maintainability,
Team
Mentor
Renji Joseph Sabu <rsabu@ncsu.edu>
Students
Manoj Ayyappan <mayyapp@ncsu.edu>
Pradeep Patil <papatil@ncsu.edu>
Maya Patel <mdpatel2@ncsu.edu>
Pull Request
Changes for this project are under Expertiza Pull Request https://github.com/expertiza/reimplementation-back-end/pull/50