diff --git a/app/controllers/api/v1/members_controller.rb b/app/controllers/api/v1/members_controller.rb index a6a5bfd..63a5e47 100644 --- a/app/controllers/api/v1/members_controller.rb +++ b/app/controllers/api/v1/members_controller.rb @@ -1,7 +1,11 @@ class Api::V1::MembersController < Api::V1::BaseController before_action :authenticate! - def create; end + def create + team = current_user.teams.find(params[:team_id]) + user = User.find(params[:user][:id]) + member = Member.create(team: team, user: user) + end def destroy; end end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 44cfe59..8c25d13 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,5 +1,5 @@ class Api::V1::UsersController < Api::V1::BaseController - before_action :authenticate!, only: %i[me] + before_action :authenticate!, only: %i[me search] def create user_params = { @@ -21,6 +21,16 @@ def me render json: json_str end + def search + if user = User.where(email: params[:user][:email]).first + json_str = UserResource.new(user).serialize + render json: json_str + else + json_str = '{"user":{}}' + render json: json_str + end + end + private def form_authenticity_token; end diff --git a/config/routes.rb b/config/routes.rb index 6988931..1aaca27 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ resource :users do collection do get 'me' + post 'search' end end resource :authentication, only: %i[create]