diff --git a/apiary.apib b/apiary.apib index d6258cb5..65aa5894 100644 --- a/apiary.apib +++ b/apiary.apib @@ -210,6 +210,30 @@ API endpoints that Operation Code's Rails backend makes available to its React f errors: "Some error message" } +## Slack User | Invite [/api/v1/slack_users] + +### Invite a User to Slack [POST] + ++ Request (application/json) + + + Headers + + Authorization: Bearer Access-Token + ++ Response 200 (application/json) + + + Body + + { + status: 200 + } + ++ Response 422 (application/json) + + { + errors: "Some error message" + } + ## Tag | Collection [/api/v1/tags] ### List All Tags [GET] diff --git a/app/controllers/api/v1/slack_users_controller.rb b/app/controllers/api/v1/slack_users_controller.rb new file mode 100644 index 00000000..d1484d05 --- /dev/null +++ b/app/controllers/api/v1/slack_users_controller.rb @@ -0,0 +1,17 @@ +module Api + module V1 + class SlackUsersController < ApplicationController + before_action :authenticate_user! + + def create + raise "User id #{current_user.id} does not have a saved email address." unless current_user.email.present? + + SlackJobs::InviterJob.perform_now current_user.email + + render json: { status: :ok } + rescue StandardError => e + render json: { errors: e.message }, status: :unprocessable_entity + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index c09a2e2a..1ed0302f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,8 +8,8 @@ get '/status', to: 'status#all' get '/status/protected', to: 'status#protected' - post '/users/profile/verify', to: 'users#verify' get '/users/by_location', to: 'users#by_location' + post '/users/profile/verify', to: 'users#verify' resources :code_schools, only: :index resources :events, only: :index @@ -19,6 +19,7 @@ resources :votes, only: [:create, :destroy] end resources :services, only: :index + resources :slack_users, only: :create resources :squads, only: [:index, :create, :show] do member do post 'join'