Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/split create update answers #98

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a4580aa
Seed data added
Feb 28, 2024
c7a7ca9
Updated
Feb 29, 2024
1641720
Added minimum required seed data
Mar 1, 2024
f8851f2
Addingadditional seed data
Mar 1, 2024
45c3dae
Added many to many relationships for assignment_questionnaire
Mar 2, 2024
b39d354
Updated seed data
Mar 2, 2024
00fa4df
Added assignment_id to response_map
Mar 2, 2024
b4e5cb8
Seed data went through
Mar 2, 2024
4ee0bbc
Added responses service.
Mar 3, 2024
1946f65
Added response-dto.rb, response-dto-handler.rb and response-service.rb
Mar 4, 2024
cff3fad
Added additional columns for the teams table
Mar 5, 2024
83623f2
Created teams_users table
Mar 5, 2024
0b88548
Added teams_users table and try to cover all response sub classes. It…
Mar 5, 2024
4daf86a
Added create, edit, and update method
Mar 8, 2024
6c7bb01
Changed response_service to response_helper, and Added enum_response_map
Mar 8, 2024
027c0f2
Updated the new, edit, show, create, and update method to run
Mar 9, 2024
a691e2d
Inatlled active_model_serializers
Mar 11, 2024
17bc708
Removed dto and used Active_Model_serializer instead
Mar 12, 2024
880cbd8
Updated show, new, create, edit, and update methods
Mar 12, 2024
2a3ef7a
Fixed bugs in new and create methods.
Mar 12, 2024
3b35c32
Added columns to Participants
Mar 13, 2024
752824a
Create teams_users table.
Mar 13, 2024
850e122
Created sign_up_topic table
Mar 13, 2024
a0dfcb0
Created signed_up_team table
Mar 13, 2024
1b6174b
Added associations to TeamsUser, SignUpTopic, and SignedUpTeam
Mar 13, 2024
daf8291
Refactored notify_instructor_on_difference method and relevant methods.
Mar 13, 2024
b2325ef
Updated questionnaire_by_answer method in response_helper.rb
Mar 14, 2024
84db93a
Added assignment_questionnaire_id to respons_map
Mar 15, 2024
6b887a1
Updated new and create method and create the locks table
Mar 15, 2024
45b086a
Fixed bugs and updated methods in the Response controller
Mar 15, 2024
11a5b5a
Removed active_model_serializer.
Mar 15, 2024
34d979c
Added topic_id to assignment_questionnaires table
Mar 15, 2024
c10414a
Fixed bugs and added postman collection
Mar 16, 2024
d3c91b7
Integrated ResponseHandler and Response model.
Mar 16, 2024
97622e9
Revised the code based on the changes of adding set_content and vali…
Mar 16, 2024
e0a802a
Added RSpec tests for response model and controller.
Mar 19, 2024
3876fd5
Removed Genfile.lock and seed.rb
Mar 21, 2024
7449699
Linted code and rolled back associations in response model
Mar 21, 2024
bd6434e
Completed commenting methods
Mar 21, 2024
22c47c6
Changed error_msg to response.errors in responses_controller
Mar 21, 2024
1ca2dd4
Removed instance variables in the EmailObject.
Mar 21, 2024
dbb8ffb
Changed question to item and fixed bugs.
Mar 23, 2024
1362fc6
Roll back the swagger schema to the original one and updated gitignore
Mar 24, 2024
674001d
Cleaned up response_spec.rb
Mar 24, 2024
cef2608
Uncommented get_questionnairein response_helper
Mar 24, 2024
be33f33
Added Responses Swagger endpoints
Mar 24, 2024
4c4d7f5
Added Security property into swagger.yaml
Mar 24, 2024
312117c
Fixed swagger.yaml issues and bugs
Mar 24, 2024
ca6b869
Revised response routes and delete response_controller_spec.rb
Mar 25, 2024
5dde80d
Updated swagger default host.
Mar 25, 2024
0efd2d2
Removed create_response_map that was created temperally.
Mar 31, 2024
c597633
Split create_update_answers method in create_answers and update_answers
Apr 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
/config/master.key
coverage/
rsa_keys.yml
/db/seeds.rb
11 changes: 3 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.2-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.2-x64-mingw-ucrt)
nokogiri (1.15.2-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
Expand Down Expand Up @@ -231,17 +229,14 @@ GEM
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2023.3)
tzinfo (>= 1.0.0)
unicode-display_width (2.4.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.11)

PLATFORMS
aarch64-linux
x64-mingw-ucrt
x86_64-linux

DEPENDENCIES
bcrypt (~> 3.1.7)
Expand Down Expand Up @@ -269,4 +264,4 @@ RUBY VERSION
ruby 3.2.1p31

BUNDLED WITH
2.4.14
2.5.6
13 changes: 7 additions & 6 deletions app/controllers/api/v1/account_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Api::V1::AccountRequestsController < ApplicationController

# GET /account_requests/pending
def pending_requests
@account_requests = AccountRequest.where(status: 'Under Review').order('created_at DESC')
Expand Down Expand Up @@ -62,7 +61,7 @@ def destroy
@account_request.destroy
render json: { message: 'Account Request deleted' }, status: :no_content
rescue ActiveRecord::RecordNotFound => e
render json: { error: e.message }, status: :not_found
render json: { error: e.message }, status: :not_found
end

private
Expand All @@ -73,17 +72,19 @@ def account_request_params
if params[:account_request][:status].nil?
params[:account_request][:status] = 'Under Review'
# For Approval or Rejection of an existing request, raise error if user sends a status other than Approved or Rejected
elsif !['Approved', 'Rejected'].include?(params[:account_request][:status])
elsif !%w[Approved Rejected].include?(params[:account_request][:status])
raise StandardError, 'Status can only be Approved or Rejected'
end
params.require(:account_request).permit(:username, :full_name, :email, :status, :introduction, :role_id, :institution_id)
params.require(:account_request).permit(:username, :full_name, :email, :status, :introduction, :role_id,
:institution_id)
end

# Create a new user if account request is approved
def create_approved_user
@new_user = User.new(name: @account_request.username, role_id: @account_request.role_id, institution_id: @account_request.institution_id, fullname: @account_request.full_name, email: @account_request.email, password: 'password')
@new_user = User.new(name: @account_request.username, role_id: @account_request.role_id,
institution_id: @account_request.institution_id, fullname: @account_request.full_name, email: @account_request.email, password: 'password')
if @new_user.save
render json: { success: 'Account Request Approved and User successfully created.', user: @new_user}, status: :ok
render json: { success: 'Account Request Approved and User successfully created.', user: @new_user }, status: :ok
else
render json: @new_user.errors, status: :unprocessable_entity
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def destroy
def assignment_params
params.require(:assignment).permit(:title, :description)
end
end
end
10 changes: 5 additions & 5 deletions app/controllers/api/v1/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Api::V1::CoursesController < ApplicationController
before_action :set_course, only: %i[ show update destroy add_ta view_tas remove_ta copy ]
before_action :set_course, only: %i[show update destroy add_ta view_tas remove_ta copy]
rescue_from ActiveRecord::RecordNotFound, with: :course_not_found
rescue_from ActionController::ParameterMissing, with: :parameter_missing

Expand Down Expand Up @@ -51,7 +51,7 @@ def add_ta
if result[:success]
render json: result[:data], status: :created
else
render json: { status: "error", message: result[:message] }, status: :bad_request
render json: { status: 'error', message: result[:message] }, status: :bad_request
end
end

Expand All @@ -67,7 +67,7 @@ def remove_ta
if result[:success]
render json: { message: "The TA #{result[:ta_name]} has been removed." }, status: :ok
else
render json: { status: "error", message: result[:message] }, status: :not_found
render json: { status: 'error', message: result[:message] }, status: :not_found
end
end

Expand All @@ -78,7 +78,7 @@ def copy
if success
render json: { message: "The course #{@course.name} has been successfully copied" }, status: :ok
else
render json: { message: "The course was not able to be copied" }, status: :unprocessable_entity
render json: { message: 'The course was not able to be copied' }, status: :unprocessable_entity
end
end

Expand All @@ -99,6 +99,6 @@ def course_not_found
end

def parameter_missing
render json: { error: "Parameter missing" }, status: :unprocessable_entity
render json: { error: 'Parameter missing' }, status: :unprocessable_entity
end
end
2 changes: 1 addition & 1 deletion app/controllers/api/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def institution_params
def institution_not_found
render json: { error: 'Institution not found' }, status: :not_found
end
end
end
2 changes: 0 additions & 2 deletions app/controllers/api/v1/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def update
else
render json: @invitation.errors, status: :unprocessable_entity
end

end

# DELETE /api/v1/invitations/:id
Expand Down Expand Up @@ -83,5 +82,4 @@ def invite_params
def invite_not_found
render json: { error: "Invitation with id #{params[:id]} not found" }, status: :not_found
end

end
85 changes: 38 additions & 47 deletions app/controllers/api/v1/questionnaires_controller.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
class Api::V1::QuestionnairesController < ApplicationController

# Index method returns the list of JSON objects of the questionnaire
# GET on /questionnaires
def index
@questionnaires = Questionnaire.order(:id)
render json: @questionnaires, status: :ok and return
end

# Show method returns the JSON object of questionnaire with id = {:id}
# GET on /questionnaires/:id
def show
begin
@questionnaire = Questionnaire.find(params[:id])
render json: @questionnaire, status: :ok and return
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found and return
end
@questionnaire = Questionnaire.find(params[:id])
render json: @questionnaire, status: :ok and return
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found and return
end

# Create method creates a questionnaire and returns the JSON object of the created questionnaire
# POST on /questionnaires
# Instructor Id statically defined since implementation of Instructor model is out of scope of E2345.
def create
begin
@questionnaire = Questionnaire.new(questionnaire_params)
@questionnaire.display_type = sanitize_display_type(@questionnaire.questionnaire_type)
@questionnaire.save!
render json: @questionnaire, status: :created and return
rescue ActiveRecord::RecordInvalid
render json: $ERROR_INFO.to_s, status: :unprocessable_entity
end
@questionnaire = Questionnaire.new(questionnaire_params)
@questionnaire.display_type = sanitize_display_type(@questionnaire.questionnaire_type)
@questionnaire.save!
render json: @questionnaire, status: :created and return
rescue ActiveRecord::RecordInvalid
render json: $ERROR_INFO.to_s, status: :unprocessable_entity
end

# Destroy method deletes the questionnaire object with id- {:id}
# DELETE on /questionnaires/:id
def destroy
begin
@questionnaire = Questionnaire.find(params[:id])
@questionnaire.delete
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found and return
end
@questionnaire = Questionnaire.find(params[:id])
@questionnaire.delete
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found and return
end

# Update method updates the questionnaire object with id - {:id} and returns the updated questionnaire JSON object
Expand All @@ -54,48 +47,46 @@ def update
render json: @questionnaire.errors.full_messages, status: :unprocessable_entity
end
end

# Copy method creates a copy of questionnaire with id - {:id} and return its JSON object
# POST on /questionnaires/copy/:id
def copy
begin
@questionnaire = Questionnaire.copy_questionnaire_details(params)
render json: @questionnaire, status: :ok and return
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found and return
rescue ActiveRecord::RecordInvalid
render json: $ERROR_INFO.to_s, status: :unprocessable_entity
end
@questionnaire = Questionnaire.copy_questionnaire_details(params)
render json: @questionnaire, status: :ok and return
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found and return
rescue ActiveRecord::RecordInvalid
render json: $ERROR_INFO.to_s, status: :unprocessable_entity
end

# Toggle access method toggles the private variable of the questionnaire with id - {:id} and return its JSON object
# GET on /questionnaires/toggle_access/:id

def toggle_access
begin
@questionnaire = Questionnaire.find(params[:id])
@questionnaire.toggle!(:private)
@access = @questionnaire.private ? 'private' : 'public'
render json: "The questionnaire \"#{@questionnaire.name}\" has been successfully made #{@access}. ",
status: :ok
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found
rescue ActiveRecord::RecordInvalid
render json: $ERROR_INFO.to_s, status: :unprocessable_entity
end
@questionnaire = Questionnaire.find(params[:id])
@questionnaire.toggle!(:private)
@access = @questionnaire.private ? 'private' : 'public'
render json: "The questionnaire \"#{@questionnaire.name}\" has been successfully made #{@access}. ",
status: :ok
rescue ActiveRecord::RecordNotFound
render json: $ERROR_INFO.to_s, status: :not_found
rescue ActiveRecord::RecordInvalid
render json: $ERROR_INFO.to_s, status: :unprocessable_entity
end

private

def questionnaire_params
params.require(:questionnaire).permit(:name, :questionnaire_type, :private, :min_question_score, :max_question_score, :instructor_id)
params.require(:questionnaire).permit(:name, :questionnaire_type, :private, :min_question_score,
:max_question_score, :instructor_id)
end

def sanitize_display_type(type)
display_type = type.split('Questionnaire')[0]
if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey BookmarkRating].include?(display_type)
display_type = (display_type.split(/(?=[A-Z])/)).join('%')
if %w[AuthorFeedback CourseSurvey TeammateReview GlobalSurvey AssignmentSurvey
BookmarkRating].include?(display_type)
display_type = display_type.split(/(?=[A-Z])/).join('%')
end
display_type
end

end
end
Loading