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
Conversation
…ate method into response model
Gemfile.lock
Outdated
There was a problem hiding this comment.
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.
Expertiza.postman_collection.json
Outdated
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
app/models/response.rb
Outdated
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) |
There was a problem hiding this comment.
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?
app/models/response.rb
Outdated
count += 1 | ||
total += response.aggregate_questionnaire_score.to_f / response.maximum_score | ||
end | ||
has_many :scores, class_name: 'Answer' |
There was a problem hiding this comment.
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.
app/helpers/response_helper.rb
Outdated
# 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| |
There was a problem hiding this comment.
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?
app/helpers/response_helper.rb
Outdated
score.update_attribute('comments', v[:comments]) | ||
end | ||
end | ||
def get_questions(response) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
app/mailers/email_object.rb
Outdated
attr_accessor :subject, :body, :from, :to | ||
|
||
def initialize(to = nil, from = nil, subject = nil, body = nil) | ||
@subject = subject |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove file from PR
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