This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Table for waiting List (#640)
* add waiting list model * change update_waiting_list method * add Env variable * remove waiting_list_position from competing lane * run rubocop * get waiting_list_position in the admin route * create WaitingList if it doesn't exist * fix validate_waiting_list_position! * bring back competing_waiting_list_position * remove unnecessary line in update_waiting_list * remove waitinglist caching tests * create waiting_list earlier if it doesn't exist yet * add FactoryBot.create(:waiting_list) in the before * rubocop fixes * adding tests in progress * finished basic tests * rubocop * waiting list controller tests * rubocop * remove waiting list leader validation * removed accept leader functionality * removed comment * removed list_waiting and added list_admin tests * rubocop * Removed logger line * move lesser used tables to PAY_PER_REQUEST and scale GSIs in prod * add Waiting list table * fix Waiting List not being created in dev * log error why update/create was rejected * allow admins to change waiting list positions * save a call to waiting_list * save another call to waiting list * saved the last call to waiting_list * run rubocop * use FactoryBot for each competition info test * give correct arguments to update_competing_lane! * fix tests now that we create it on competition info and certain methods need it * run rubocop * add waiting list position if registration.competing_status == 'waiting_list' * allow admins to move people to waiting list if User edits are not allowed * fix tests after merge * only initialize waiting_list once accessed --------- Co-authored-by: Duncan <[email protected]> Co-authored-by: Duncan <[email protected]>
- Loading branch information
1 parent
275380d
commit 3f7c7e8
Showing
27 changed files
with
660 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class WaitingList | ||
include Dynamoid::Document | ||
|
||
# We autoscale dynamodb | ||
table name: EnvConfig.WAITING_LIST_DYNAMO_TABLE, capacity_mode: nil, key: :id | ||
|
||
field :entries, :array, of: :integer | ||
|
||
def remove(user_id) | ||
update_attributes!(entries: entries - [user_id]) | ||
end | ||
|
||
def add(user_id) | ||
if entries.nil? | ||
update_attributes!(entries: [user_id]) | ||
else | ||
update_attributes!(entries: entries + [user_id]) | ||
end | ||
end | ||
|
||
def move_to_position(user_id, new_position) | ||
raise ArgumentError.new('Target position out of waiting list range') if new_position > entries.length || new_position < 1 | ||
|
||
old_index = entries.find_index(user_id) | ||
return if old_index == new_position-1 | ||
|
||
update_attributes!(entries: entries.insert(new_position-1, entries.delete_at(old_index))) | ||
end | ||
|
||
def self.find_or_create!(id) | ||
WaitingList.find(id) | ||
rescue Dynamoid::Errors::RecordNotFound | ||
WaitingList.create(id: id, entries: []) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.