From d38c56ab1600d2e2c0166af905d7c5bb5683409a Mon Sep 17 00:00:00 2001 From: fef Date: Thu, 1 Dec 2022 02:24:08 +0000 Subject: [PATCH] change reaction api to match other interactions Status reactions had an API similar to that of announcement reactions, using PUT and DELETE at a single endpoint. I believe that for statuses, it makes more sense to follow the convention of the other interactions and use separate POST endpoints for create and destroy respectively. --- app/controllers/api/v1/statuses/reactions_controller.rb | 2 +- app/javascript/flavours/glitch/actions/interactions.js | 4 ++-- app/javascript/mastodon/actions/interactions.js | 4 ++-- config/routes.rb | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/statuses/reactions_controller.rb b/app/controllers/api/v1/statuses/reactions_controller.rb index 9542d491c8..333054f2a0 100644 --- a/app/controllers/api/v1/statuses/reactions_controller.rb +++ b/app/controllers/api/v1/statuses/reactions_controller.rb @@ -7,7 +7,7 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController before_action :require_user! before_action :set_status - def update + def create ReactService.new.call(current_account, @status, params[:id]) render_empty end diff --git a/app/javascript/flavours/glitch/actions/interactions.js b/app/javascript/flavours/glitch/actions/interactions.js index 7cce76d0c7..f2c8c47334 100644 --- a/app/javascript/flavours/glitch/actions/interactions.js +++ b/app/javascript/flavours/glitch/actions/interactions.js @@ -416,7 +416,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => { dispatch(addReactionRequest(statusId, name, alreadyAdded)); } - api(getState).put(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => { + api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => { dispatch(addReactionSuccess(statusId, name, alreadyAdded)); }).catch(err => { if (!alreadyAdded) { @@ -450,7 +450,7 @@ export const addReactionFail = (statusId, name, error) => ({ export const removeReaction = (statusId, name) => (dispatch, getState) => { dispatch(removeReactionRequest(statusId, name)); - api(getState).delete(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => { + api(getState).post(`/api/v1/statuses/${statusId}/unreact/${name}`).then(() => { dispatch(removeReactionSuccess(statusId, name)); }).catch(err => { dispatch(removeReactionFail(statusId, name, err)); diff --git a/app/javascript/mastodon/actions/interactions.js b/app/javascript/mastodon/actions/interactions.js index 86607368ee..8619232a5b 100644 --- a/app/javascript/mastodon/actions/interactions.js +++ b/app/javascript/mastodon/actions/interactions.js @@ -436,7 +436,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => { dispatch(addReactionRequest(statusId, name, alreadyAdded)); } - api(getState).put(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => { + api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => { dispatch(addReactionSuccess(statusId, name, alreadyAdded)); }).catch(err => { if (!alreadyAdded) { @@ -470,7 +470,7 @@ export const addReactionFail = (statusId, name, error) => ({ export const removeReaction = (statusId, name) => (dispatch, getState) => { dispatch(removeReactionRequest(statusId, name)); - api(getState).delete(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => { + api(getState).post(`/api/v1/statuses/${statusId}/unreact/${name}`).then(() => { dispatch(removeReactionSuccess(statusId, name)); }).catch(err => { dispatch(removeReactionFail(statusId, name, err)); diff --git a/config/routes.rb b/config/routes.rb index 1b79aed896..e097c2baad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -451,6 +451,9 @@ Rails.application.routes.draw do resource :favourite, only: :create post :unfavourite, to: 'favourites#destroy' + post '/react/:id', to: 'reactions#create' + post '/unreact/:id', to: 'reactions#destroy' + resource :bookmark, only: :create post :unbookmark, to: 'bookmarks#destroy' @@ -462,7 +465,6 @@ Rails.application.routes.draw do resource :history, only: :show resource :source, only: :show - resources :reactions, only: [:update, :destroy] post :translate, to: 'translations#create' end