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

E2415. Reimplement response[s]_controller.rb #81

Closed
wants to merge 47 commits into from

Conversation

dlfranks
Copy link

@dlfranks dlfranks commented Mar 8, 2024

I refactored the code to streamline the controller, resulting in a more concise and maintainable structure for the API application.

Added classes: ResponseDto, ResponseHandler, ResponseService

@dlfranks dlfranks changed the title Refactored response model, response helper, and response controller E2415. Reimplement response[s]_controller.rb Mar 8, 2024
@dlfranks dlfranks changed the title E2415. Reimplement response[s]_controller.rb E2415. Reimplement response[s]_controller.rb (Refactored the code) Mar 8, 2024
@dlfranks dlfranks closed this Mar 9, 2024
@dlfranks dlfranks reopened this Mar 9, 2024
Gemfile.lock Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file from the pull request.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not needed in the pull request, you can remove this file.

class Api::V1::ResponsesController < ApplicationController
include ResponseHelper
def index
@responses = Response.all
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use instance variables if needed across different methods in the controller; if not, you can consider making it a local variable instead.

question = Question.find(s.question_id)
# For quiz responses, the weights will be 1 or 0, depending on if correct
sum += s.answer * question.weight unless s.answer.nil? || !question.scorable?
def set_content(params, action)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the action parameter needed?

count += 1
total += response.aggregate_questionnaire_score.to_f / response.maximum_score
end
has_many :scores, class_name: 'Answer'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the dependent destroy, foriegn_key and inverse_of attributes as it was present previously.

# only count the scorable questions, only when the answer is not nil
# we accept nil as answer for scorable questions, and they will not be counted towards the total score
sum = 0
response.scores.each do |s|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a meaningful variable name instead of s?

score.update_attribute('comments', v[:comments])
end
end
def get_questions(response)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide proper spaces between methods, here and many other places. You can use linters/other tools to format code.

questionnaire = get_questionnaire(response)
questionnaire.questions
end
def get_answers(response, questions)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment for every method; make sure to add comments before every method.

attr_accessor :subject, :body, :from, :to

def initialize(to = nil, from = nil, subject = nil, body = nil)
@subject = subject
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need instance variables here?

db/seeds.rb Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove file from PR

@dlfranks dlfranks changed the title E2415. Reimplement response[s]_controller.rb (Refactored the code) E2415. Reimplement response[s]_controller.rb Mar 21, 2024
@dlfranks dlfranks closed this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants