Commit 65c5ee56 authored by mgabdev's avatar mgabdev

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

• Updated:
- GroupsController, groups reducer to work with browsing by category, tag
parent ada8b123
......@@ -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
......
......@@ -2,6 +2,8 @@ import {
GROUP_FETCH_SUCCESS,
GROUP_FETCH_FAIL,
GROUPS_FETCH_SUCCESS,
GROUPS_BY_CATEGORY_FETCH_SUCCESS,
GROUPS_BY_TAG_FETCH_SUCCESS,
} from '../actions/groups'
import { GROUP_UPDATE_SUCCESS } from '../actions/group_editor'
import { Map as ImmutableMap, fromJS } from 'immutable'
......@@ -23,6 +25,8 @@ export default function groups(state = initialState, action) {
case GROUP_FETCH_SUCCESS:
case GROUP_UPDATE_SUCCESS:
return normalizeGroup(state, action.group)
case GROUPS_BY_CATEGORY_FETCH_SUCCESS:
case GROUPS_BY_TAG_FETCH_SUCCESS:
case GROUPS_FETCH_SUCCESS:
return normalizeGroups(state, action.groups)
case GROUP_FETCH_FAIL:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment