diff --git a/app/controllers/api/v1/groups_controller.rb b/app/controllers/api/v1/groups_controller.rb index 6b022d0..4fed5be 100755 --- a/app/controllers/api/v1/groups_controller.rb +++ b/app/controllers/api/v1/groups_controller.rb @@ -59,7 +59,9 @@ def remove_user end def list_admins - group = Group.find(params[:id]) + group = Group.find_by_id(params[:id]) + return head :not_found unless group.present? + users = group.group_admins.joins(:user). select('users.id, users.email, users.name, users.active, group_admins.created_at as join_date'). where('users.active = ?', true) @@ -67,7 +69,9 @@ def list_admins end def associated_vpns - group = Group.find(params[:id]) + group = Group.find_by_id(params[:id]) + return head :not_found unless group.present? + vpns = group.vpns render json: vpns, status: :ok end diff --git a/app/controllers/api/v1/vpns_controller.rb b/app/controllers/api/v1/vpns_controller.rb index 4e98803..0cae428 100755 --- a/app/controllers/api/v1/vpns_controller.rb +++ b/app/controllers/api/v1/vpns_controller.rb @@ -3,12 +3,16 @@ class ::Api::V1::VpnsController < ::Api::V1::BaseController def index vpns = Vpn.order(:id).page(params[:page]).per(params[:per_page]) + vpns = vpns.where("name LIKE ?", "%#{params[:q]}%") if params[:q].present? render json: vpns, status: :ok end def associated_groups - vpn = Vpn.find(params[:id]) + vpn = Vpn.find_by_id(params[:id]) + return head :not_found unless vpn.present? + groups = vpn.groups + groups = groups.where("name LIKE ?", "%#{params[:q]}%") if params[:q].present? render json: groups, status: :ok end