Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Add internal route to create a registration (#688)
Browse files Browse the repository at this point in the history
* add internal route to create registrations

* add it to routes

* fix rubcop
  • Loading branch information
FinnIckler authored Sep 14, 2024
1 parent ff0d6ee commit 738f176
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/controllers/internal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@ def registrations_for_user
render json: registrations
end

def create
user_id = params.require(:user_id)
competition_id = params.require(:competition_id)
event_ids = params.require(:event_ids)
current_user = params.require(:current_user)
status = params.require(:competing_status)
comment = params[:comment] || ''

begin
Registration.find("#{competition_id}-#{user_id}")
render_error(400, ErrorCodes::COMPETITOR_ALREADY_REGISTERED)
rescue Dynamoid::Errors::RecordNotFound
initial_history = History.new({ 'changed_attributes' =>
{ event_ids: event_ids, status: status, comment: comment },
'actor_type' => 'user',
'actor_id' => current_user,
'action' => 'Organizer added',
'timestamp' => Time.now.utc })
RegistrationHistory.create(attendee_id: "#{competition_id}-#{user_id}", entries: [initial_history])
Registration.create(attendee_id: "#{competition_id}-#{user_id}",
competition_id: competition_id,
user_id: user_id,
created_at: Time.now.utc,
lanes: [LaneFactory.competing_lane(event_ids: event_ids,
comment: comment,
registration_status: status)])
render json: { status: 'ok' }
end
end

def show_registration
attendee_id = params.require(:attendee_id)
registration = Registration.find(attendee_id)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get '/healthcheck', to: 'healthcheck#index'
post '/api/internal/v1/update_payment', to: 'internal#update_payment_status'
get '/api/internal/v1/:competition_id/registrations', to: 'internal#list_registrations'
post '/api/internal/v1/:competition_id/add', to: 'internal#create'
get '/api/internal/v1/:attendee_id', to: 'internal#show_registration'
get '/api/internal/v1/users/:user_id/registrations', to: 'internal#registrations_for_user'
get '/api/v1/register', to: 'registration#show'
Expand Down
1 change: 1 addition & 0 deletions lib/error_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module ErrorCodes
# Registration errors
REGISTRATION_NOT_FOUND = -3000
ALREADY_REGISTERED_IN_SERIES = -3001
COMPETITOR_ALREADY_REGISTERED = -3002

# Request errors
INVALID_REQUEST_DATA = -4000
Expand Down

0 comments on commit 738f176

Please sign in to comment.