Updated account, groups relationships routes to post data instead of get

• Updated:
- account, groups relationships routes to post data instead of get
This commit is contained in:
mgabdev 2021-01-13 23:51:44 -05:00
parent 1ed29ddd53
commit fb75f33b12
5 changed files with 24 additions and 14 deletions

View File

@ -4,21 +4,22 @@ class Api::V1::Accounts::RelationshipsController < Api::BaseController
before_action -> { doorkeeper_authorize! :read, :'read:follows' }
before_action :require_user!
def index
def relationships
accounts = Account.where(id: account_ids).select('id')
# .where doesn't guarantee that our results are in the same order
# we requested them, so return the "right" order to the requestor.
@accounts = accounts.index_by(&:id).values_at(*account_ids).compact
render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: relationships
render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: get_relationships
end
private
def relationships
def get_relationships
AccountRelationshipsPresenter.new(@accounts, current_user.account_id)
end
def account_ids
Array(params[:id]).map(&:to_i)
the_take = current_user.staff? ? 100 : 25
params[:accountIds].map(&:to_i).take(the_take)
end
end

View File

@ -1,24 +1,25 @@
# frozen_string_literal: true
class Api::V1::Groups::RelationshipsController < Api::BaseController
class Api::V1::GroupRelationshipsController < Api::BaseController
before_action -> { doorkeeper_authorize! :read, :'read:groups' }
before_action :require_user!
def index
def relationships
groups = Group.where(id: group_ids, is_archived: false).select('id')
# .where doesn't guarantee that our results are in the same order
# we requested them, so return the "right" order to the requestor.
@groups = groups.index_by(&:id).values_at(*group_ids).compact
render json: @groups, each_serializer: REST::GroupRelationshipSerializer, relationships: relationships
render json: @groups, each_serializer: REST::GroupRelationshipSerializer, relationships: get_relationships
end
private
def relationships
def get_relationships
GroupRelationshipsPresenter.new(@groups, current_user.account_id)
end
def group_ids
Array(params[:id]).map(&:to_i)
the_take = current_user.staff? ? 100 : 25
params[:groupIds].map(&:to_i).take(the_take)
end
end

View File

@ -542,7 +542,9 @@ export const fetchRelationships = (accountIds) => (dispatch, getState) => {
dispatch(fetchRelationshipsRequest(newAccountIds))
api(getState).get(`/api/v1/accounts/relationships?${newAccountIds.map(id => `id[]=${id}`).join('&')}`).then((response) => {
api(getState).post('/api/v1/accounts/relationships', {
accountIds: newAccountIds,
}).then((response) => {
dispatch(fetchRelationshipsSuccess(response.data))
}).catch((error) => {
dispatch(fetchRelationshipsFail(error))

View File

@ -182,13 +182,18 @@ export const fetchGroupRelationships = (groupIds) => (dispatch, getState) => {
if (!me || !Array.isArray(groupIds)) return
const loadedRelationships = getState().get('group_relationships')
const newGroupIds = groupIds.filter((id) => loadedRelationships.get(id, null) === null)
let newGroupIds = groupIds.filter((id) => loadedRelationships.get(id, null) === null)
if (newGroupIds.length === 0) return
// Unique
newGroupIds = Array.from(new Set(newGroupIds))
dispatch(fetchGroupRelationshipsRequest(newGroupIds))
api(getState).get(`/api/v1/groups/${newGroupIds[0]}/relationships?${newGroupIds.map(id => `id[]=${id}`).join('&')}`).then((response) => {
api(getState).post('/api/v1/group_relationships', {
groupIds: newGroupIds,
}).then((response) => {
dispatch(fetchGroupRelationshipsSuccess(response.data))
}).catch((error) => {
dispatch(fetchGroupRelationshipsFail(error))

View File

@ -320,7 +320,7 @@ Rails.application.routes.draw do
patch :update_credentials, to: 'credentials#update'
post :resend_email_confirmation, to: 'credentials#resend_email_confirmation'
resource :search, only: :show, controller: :search
resources :relationships, only: :index
post :relationships, to: 'relationships#relationships'
end
resources :accounts, only: [:create, :show] do
@ -355,7 +355,6 @@ Rails.application.routes.draw do
get '/category/:category', to: 'groups#by_category'
get '/tag/:tag', to: 'groups#by_tag'
resources :relationships, only: :index, controller: 'groups/relationships'
resource :accounts, only: [:show, :create, :update, :destroy], controller: 'groups/accounts'
resource :removed_accounts, only: [:show, :create, :destroy], controller: 'groups/removed_accounts'
resource :password, only: [:create], controller: 'groups/password'
@ -367,6 +366,8 @@ Rails.application.routes.draw do
post :unpin, to: 'groups/pins#destroy'
end
post :group_relationships, to: 'group_relationships#relationships'
resources :polls, only: [:create, :show] do
resources :votes, only: :create, controller: 'polls/votes'
end