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

Data to csv #1900

Merged
merged 25 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
73fd907
Data Export To CSV for user : backend apis
Oct 10, 2020
7b9d389
Merge branch 'main' of github.com:ifmeorg/ifme into main
Oct 10, 2020
e7b8fe5
rubocop
Oct 11, 2020
28d1c90
Merge branch 'main' of github.com:ifmeorg/ifme into data_to_csv
Oct 11, 2020
3c0195b
Delete reports.scss
akp2603 Oct 15, 2020
f88ab4a
changed variable name
Oct 15, 2020
68034c4
Merge branch 'data_to_csv' of github.com:ifmeorg/ifme into data_to_csv
Oct 15, 2020
aebe22b
request spec added
Oct 16, 2020
38cd98b
Delete delete_stale_data_worker_spec.rb
akp2603 Oct 17, 2020
e3546db
Delete process_data_request_worker_spec.rb
akp2603 Oct 17, 2020
12c1a64
Delete reports_helper_spec.rb
akp2603 Oct 17, 2020
1967ff8
data request model specs added
Oct 17, 2020
ac9fdea
Merge branch 'data_to_csv' of github.com:ifmeorg/ifme into data_to_csv
Oct 17, 2020
aa369ed
rubocop fixes
Oct 17, 2020
9b2fa1f
refactoring
Oct 17, 2020
47b0af0
refactoring
Oct 17, 2020
79085ff
Delete delete_stale_data_worker_spec.rb
akp2603 Oct 17, 2020
27a6b7d
Delete process_data_request_worker_spec.rb
akp2603 Oct 17, 2020
cbf22e1
added test.example.env
Oct 17, 2020
342e0d3
Merge branch 'data_to_csv' of github.com:ifmeorg/ifme into data_to_csv
Oct 17, 2020
9e04274
Setup Redis in Circle CI config
julianguyen Oct 17, 2020
b1502a6
Update config.yml
akp2603 Oct 17, 2020
ba3c682
review changes
Oct 18, 2020
31f18b2
Merge branch 'data_to_csv' of github.com:ifmeorg/ifme into data_to_csv
Oct 18, 2020
f92ba10
Merge branch 'main' of github.com:ifmeorg/ifme into data_to_csv
Oct 23, 2020
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
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ gem 'selenium-webdriver', '~> 3.142.3'

gem 'rubyzip', '~> 1.3.0'

gem 'sidekiq', '5.0.5'
# Uniqueness in sidekiq jobs
Copy link
Member

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!

gem 'sidekiq-middleware'
# Keep track of failed jobs in sidekiq
gem 'sidekiq-failures'
#corn job for sidekiq
gem "sidekiq-cron", "~> 1.1"

group :development, :test do
gem 'bundler-audit'
gem 'dotenv-rails', '~> 2.7.2'
Expand Down
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,18 @@ GEM
faraday (>= 0.7.6, < 1.0)
shoulda-matchers (4.4.1)
activesupport (>= 4.2.0)
sidekiq (5.0.5)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.4, < 5)
sidekiq-cron (1.2.0)
fugit (~> 1.1)
sidekiq (>= 4.2.1)
sidekiq-failures (1.0.0)
sidekiq (>= 4.0.0)
sidekiq-middleware (0.3.0)
sidekiq (>= 2.12.4)
signet (0.14.0)
addressable (~> 2.3)
faraday (>= 0.17.3, < 2.0)
Expand Down Expand Up @@ -583,6 +595,10 @@ DEPENDENCIES
selenium-webdriver (~> 3.142.3)
sentry-raven
shoulda-matchers
sidekiq (= 5.0.5)
sidekiq-cron (~> 1.1)
sidekiq-failures
sidekiq-middleware
simplecov (= 0.16.1)
spring
turbolinks (~> 5.2.0)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users/reports.scss
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.
Copy link
Member

Choose a reason for hiding this comment

The 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/
25 changes: 25 additions & 0 deletions app/controllers/users/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Users::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
25 changes: 25 additions & 0 deletions app/helpers/users/reports_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Users::ReportsHelper

def submit_request_helper(user)
begin
return 200, {request_id: user.generate_data_request()}
rescue => e
return 422, {error: e.message}
end
end

def fetch_request_status_helper(user, request_id)
return 400, {error: "Request id can be blank."} if request_id.blank?
data_request = user.data_requests.find_by(request_id: request_id)
return 404, {error: "No such request exists for current user."} if data_request.blank?
return 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?
data_request = user.data_requests.find_by(request_id: request_id, status_id: Users::DataRequest::STATUS[:success])
return 404, {error: "Requested csv not found."} if (data_request.blank? || !File.exist?("#{data_request.file_path}"))
return 200, data_request.file_path
end

end
9 changes: 9 additions & 0 deletions app/models/allyship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#

class Allyship < ApplicationRecord

DISPLAY_ATTRIBUTES = %w{
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
Expand Down
13 changes: 13 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

def self.build_csv_rows(objects)
return [] if objects.blank?
klass = objects.klass
data = [["#{klass.name.underscore}_info"]]
diplay_attributes = klass.const_defined?("DISPLAY_ATTRIBUTES") ? klass.const_get("DISPLAY_ATTRIBUTES") : klass.column_names
data << diplay_attributes
objects.each do |object|
data << diplay_attributes.map { |attribute| object.send(attribute.to_sym) }
end
return data
end

end
9 changes: 9 additions & 0 deletions app/models/care_plan_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#

class CarePlanContact < ApplicationRecord

DISPLAY_ATTRIBUTES = %w{
id
name
phone
created_at
updated_at
}.map!(&:freeze).freeze

validates :user_id, :name, presence: true
belongs_to :user
end
11 changes: 11 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ class Category < ApplicationRecord
has_many :moments_categories, dependent: :destroy
has_many :strategies_categories, dependent: :destroy
validates :visible, inclusion: [true, false]

DISPLAY_ATTRIBUTES = %w{
id
name
description
created_at
updated_at
slug
visible
}.map!(&:freeze).freeze

end
9 changes: 9 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class Group < ApplicationRecord
through: :group_members, source: :user
after_destroy :destroy_notifications

DISPLAY_ATTRIBUTES = %w{
id
name
created_at
updated_at
description
slug
}.map!(&:freeze).freeze

def led_by?(user)
leaders.include? user
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/group_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#

class GroupMember < ApplicationRecord

DISPLAY_ATTRIBUTES = %w{
id
group_id
leader
created_at
updated_at
}.map!(&:freeze).freeze

after_destroy :destroy_meeting_memberships

validates :group_id, :user_id, presence: true
Expand Down
23 changes: 21 additions & 2 deletions app/models/medication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@
# comments :text
# slug :string
# add_to_google_cal :boolean default(FALSE)
# weekly_dosage :integer
# default(["0", "1", "2", "3", "4", "5", "6"]), is an Array
# weekly_dosage :integer default(["0", "1", "2", "3", "4", "5", "6"]), is an Array
#

class Medication < ApplicationRecord
# dosage: amount of medication taken at one time
# total: total quantity of medication
# strength: strength of medication

DISPLAY_ATTRIBUTES = %w{
id
name
dosage
refill
created_at
updated_at
user_id
total
strength
strength_unit
dosage_unit
total_unit
comments
slug
add_to_google_cal
weekly_dosage
}.map!(&:freeze).freeze

extend FriendlyId
friendly_id :name
belongs_to :user, foreign_key: :user_id
Expand Down
10 changes: 10 additions & 0 deletions app/models/meeting_member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
#

class MeetingMember < ApplicationRecord

DISPLAY_ATTRIBUTES = %w{
id
meeting_id
leader
created_at
updated_at
google_cal_event_id
}.map!(&:freeze).freeze

validates :meeting_id, :user_id, presence: true
validates :leader, inclusion: [true, false]

Expand Down
17 changes: 17 additions & 0 deletions app/models/moment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ class Moment < ApplicationRecord
include CommonMethods
extend FriendlyId

DISPLAY_ATTRIBUTES = %w{
id
name
why
fix
created_at
updated_at
viewers
comment
slug
secret_share_identifier
secret_share_expires_at
published_at
bookmarked
resource_recommendations
}.map!(&:freeze).freeze

friendly_id :name
serialize :viewers, Array

Expand Down
11 changes: 11 additions & 0 deletions app/models/mood.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
#

class Mood < ApplicationRecord

DISPLAY_ATTRIBUTES = %w{
id
name
description
created_at
updated_at
slug
visible
}.map!(&:freeze).freeze

extend FriendlyId
friendly_id :name
validates :user_id, :name, presence: true
Expand Down
9 changes: 9 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#

class Notification < ApplicationRecord

DISPLAY_ATTRIBUTES = %w{
id
uniqueid
data
created_at
updated_at
}.map!(&:freeze).freeze

validates :user_id, :uniqueid, :data, presence: true
belongs_to :user, foreign_key: :user_id

Expand Down
14 changes: 14 additions & 0 deletions app/models/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ class Strategy < ApplicationRecord
include CommonMethods
extend FriendlyId

DISPLAY_ATTRIBUTES = %w{
id
description
viewers
comment
created_at
updated_at
name
slug
published_at
visible
bookmarked
}.map!(&:freeze).freeze

friendly_id :name
serialize :viewers, Array

Expand Down
Loading