-
Notifications
You must be signed in to change notification settings - Fork 750
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
Data to csv #1900
Data to csv #1900
Changes from 4 commits
73fd907
7b9d389
e7b8fe5
28d1c90
3c0195b
f88ab4a
68034c4
aebe22b
38cd98b
e3546db
12c1a64
1967ff8
ac9fdea
aa369ed
9b2fa1f
47b0af0
79085ff
27a6b7d
cbf22e1
342e0d3
9e04274
b1502a6
ba3c682
31f18b2
f92ba10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Users::Reports controller here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's delete this file since it's unused! |
||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
module Users | ||
class ReportsController < ApplicationController | ||
before_action :authenticate_user! | ||
include Users::ReportsHelper | ||
|
||
def submit_request | ||
status, response = submit_request_helper(current_user) | ||
render json: response, status: status | ||
end | ||
|
||
def fetch_request_status | ||
status, response = fetch_request_status_helper(current_user, | ||
params[:request_id]) | ||
render json: response, status: status | ||
end | ||
|
||
def download_data | ||
status, response = download_data_helper(current_user, | ||
params[:request_id]) | ||
if status != 200 | ||
render json: response, status: status | ||
else | ||
send_file(response, status: 200) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
module Users | ||
module ReportsHelper | ||
def submit_request_helper(user) | ||
[200, { request_id: user.generate_data_request }] | ||
rescue StandardError => e | ||
[422, { error: e.message }] | ||
end | ||
|
||
def fetch_request_status_helper(user, request_id) | ||
return 400, { error: 'Request id can be blank.' } if request_id.blank? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be "Request id can't be blank" instead? |
||
|
||
data_request = user.data_requests.find_by(request_id: request_id) | ||
if data_request.blank? | ||
return 404, { error: 'No such request exists for current user.' } | ||
end | ||
|
||
[200, { current_status: data_request.status_id }] | ||
end | ||
|
||
def download_data_helper(user, request_id) | ||
return 400, { error: 'Request id can be blank.' } if request_id.blank? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above. |
||
|
||
data_request = user.data_requests.find_by( | ||
request_id: request_id, | ||
status_id: Users::DataRequest::STATUS[:success] | ||
) | ||
if data_request.blank? || !File.exist?(data_request.file_path.to_s) | ||
return 404, { error: 'Requested csv not found.' } | ||
end | ||
|
||
[200, data_request.file_path] | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,14 @@ | |
# | ||
|
||
class Allyship < ApplicationRecord | ||
DISPLAY_ATTRIBUTES = %w[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename this to something like |
||
id | ||
created_at | ||
updated_at | ||
ally_id | ||
status | ||
].map!(&:freeze).freeze | ||
|
||
enum status: { accepted: 0, pending_from_user: 1, pending_from_ally: 2 } | ||
|
||
validate :different_users | ||
|
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.
Thanks for adding comments but I don't think they're absolutely necessary!