Updated GroupsController, groups reducer to work with browsing by category, tag

• Updated:
- GroupsController, groups reducer to work with browsing by category, tag
This commit is contained in:
mgabdev
2020-09-24 16:21:16 -05:00
parent ada8b123d6
commit 65c5ee56f9
2 changed files with 15 additions and 0 deletions

View File

@@ -39,7 +39,15 @@ class Api::V1::GroupsController < Api::BaseController
render json: { error: 'This method requires an authenticated user' }, status: 422
end
@groupCategory = nil
if !params[:category].empty?
@groupCategory = GroupCategories.where("text ILIKE ?", "%#{params[:category]}%")
end
@groups = []
if !@groupCategory.nil?
@groups = Group.where(is_archived: false, group_categories: @groupCategory).all
end
render json: @groups, each_serializer: REST::GroupSerializer
end
@@ -50,6 +58,9 @@ class Api::V1::GroupsController < Api::BaseController
end
@groups = []
if !params[:tag].empty?
@groups = Group.where(is_archived: false).where("array_to_string(tags, '||') ILIKE :tag", tag: "%#{params[:tag]}%").all
end
render json: @groups, each_serializer: REST::GroupSerializer
end