Skip to content

Commit

Permalink
[WIP] Handle item id dups
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Aug 29, 2016
1 parent 6016664 commit 2b72f24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AllCops:
- 'test/spec_helper.rb'
# - 'spec/teaspoon_env.rb'
- 'vendor/**/*'
- 'lib/tasks/display-coverage.rake'

Metrics/LineLength:
Max: 120
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/change_item_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ def create
@change_item_type = ChangeItemType.new(params[:change_item_type])
if @change_item_type.valid?
array_of_item_ids = @change_item_type.parse_uploaded_file
logger.debug "ARRAY_OF_ITEM_IDS is #{array_of_item_ids}"
filtered_item_ids = UniUpdates.filter_duplicates(array_of_item_ids)
logger.debug "FILTERED_ITEM_IDS are #{filtered_item_ids}"
logger.debug "UNIQUES ARE #{filtered_item_ids[0]}"
logger.debug "DUPLICATES ARE #{filtered_item_ids[1]}"
u = filtered_item_ids[0]
d = filtered_item_ids[1]
logger.debut "??????????"
logger.debug "U are #{u}"
logger.debug "D are #{d}"
# filter the dups, create uniques, make dups an instance var
# send instance var to view and mailer
# send correct count to UUB creation
@uni_updates_batch = UniUpdatesBatch.create_item_type_batch(params, array_of_item_ids.count)
UniUpdates.create_for_batch(array_of_item_ids, @uni_updates_batch)
WebformsMailer.batch_upload_email(@uni_updates_batch).deliver_now
Expand Down
12 changes: 12 additions & 0 deletions app/models/uni_updates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ def self.create_for_batch(array_of_item_ids, uni_updates_batch)
UniUpdates.create(hashes_for_updates)
end
# rubocop:enable Metrics/MethodLength
def self.filter_duplicates(item_ids)
uniques = []
duplicates = []
item_ids.each do |item_id|
if UniUpdates.where(item_id: item_id) == 0
uniques << item_id
else
duplicates << item_id
end
end
[uniques, duplicates]
end
end

0 comments on commit 2b72f24

Please sign in to comment.