<commit_before>enable :sessions

get '/surveys' do
  @surveys = Survey.all
  erb :'/all_surveys'
end

get '/surveys/create' do
  erb :'/make-survey/make-survey'
end

post '/surveys/:id' do |id|
  "New Response"
end

post '/surveys/create' do
  title = params[:title]
  @survey = Survey.create(title: title, user_id: session[:user_id])
  redirect "/surveys/#{@survey.id}/question"
end

get '/surveys/user/:id' do |id|
  @user = User.find(id)
  @surveys = @user.surveys
  "List of #{@user.name}'s surveys"
end

get '/surveys/:id/results' do |id|
  @survey = Survey.find(id)
  "Results of #{@survey.title}"
end

#If owner: edit/delete/view results
#If logged in: take/view results if already taken
#If not logged in: redirect to signup/signin
get '/surveys/:id' do |id|
  @survey = Survey.find(id)
  @questions = @survey.questions
  erb :'/take-survey/take-survey'
end

# should redirect to users survey page
delete '/surveys/:id/delete' do |id|
  survey = survey.find(id)
  questions = survey.questions
  answers = questions.answers
  survey.destroy
  answers.each do |answer|
    answer.destroy
  end
  questions.each do |question|
    question.destroy
  end
  redirect '/'
end

<commit_msg>Add parsing of params hash to survey take submission<commit_after>enable :sessions

get '/surveys' do
  @surveys = Survey.all
  erb :'/all_surveys'
end

get '/surveys/create' do
  erb :'/make-survey/make-survey'
end

post '/surveys/:id' do |id|
  params["question"].each_pair do |question, answer|
    this_question = Question.where(question_desc: question)
    this_answer = Answer.where(answer_text: answer)
    #TODO:Create a response belonging to the current user and current answer.
  end
end

post '/surveys/create' do
  title = params[:title]
  @survey = Survey.create(title: title, user_id: session[:user_id])
  redirect "/surveys/#{@survey.id}/question"
end

get '/surveys/user/:id' do |id|
  @user = User.find(id)
  @surveys = @user.surveys
  "List of #{@user.name}'s surveys"
end

get '/surveys/:id/results' do |id|
  @survey = Survey.find(id)
  "Results of #{@survey.title}"
end

#If owner: edit/delete/view results
#If logged in: take/view results if already taken
#If not logged in: redirect to signup/signin
get '/surveys/:id' do |id|
  @survey = Survey.find(id)
  @questions = @survey.questions
  erb :'/take-survey/take-survey'
end

# should redirect to users survey page
delete '/surveys/:id/delete' do |id|
  survey = survey.find(id)
  questions = survey.questions
  answers = questions.answers
  survey.destroy
  answers.each do |answer|
    answer.destroy
  end
  questions.each do |question|
    question.destroy
  end
  redirect '/'
end


{'fraction_non_alphanumeric': 0.13542059600150885, 'fraction_numerical': 0.0, 'mean_word_length': 3.8482632541133457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2940528', 'n_tokens_mistral': 976, 'n_tokens_neox': 977, 'n_words': 264}