Move Collections API to v1 namespace (#39210)

This commit is contained in:
David Roetzel 2026-05-29 10:39:51 +02:00 committed by GitHub
parent f89ba969c2
commit 6d3182a6eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 30 deletions

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Api::V1Alpha::CollectionItemsController < Api::BaseController
class Api::V1::CollectionItemsController < Api::BaseController
include Authorization
before_action :check_feature_enabled

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Api::V1Alpha::CollectionsController < Api::BaseController
class Api::V1::CollectionsController < Api::BaseController
include Authorization
DEFAULT_COLLECTIONS_LIMIT = 40
@ -98,13 +98,13 @@ class Api::V1Alpha::CollectionsController < Api::BaseController
def next_path
return unless records_continue?
api_v1_alpha_account_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT)))
api_v1_account_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT)))
end
def prev_path
return if offset_param.zero?
api_v1_alpha_account_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT)))
api_v1_account_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT)))
end
def records_continue?

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Api::V1Alpha::InCollectionsController < Api::BaseController
class Api::V1::InCollectionsController < Api::BaseController
include Authorization
DEFAULT_COLLECTIONS_LIMIT = 40
@ -44,13 +44,13 @@ class Api::V1Alpha::InCollectionsController < Api::BaseController
def next_path
return unless records_continue?
api_v1_alpha_account_in_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT)))
api_v1_account_in_collections_url(@account, pagination_params(offset: offset_param + limit_param(DEFAULT_COLLECTIONS_LIMIT)))
end
def prev_path
return if offset_param.zero?
api_v1_alpha_account_in_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT)))
api_v1_account_in_collections_url(@account, pagination_params(offset: offset_param - limit_param(DEFAULT_COLLECTIONS_LIMIT)))
end
def records_continue?

View File

@ -6,13 +6,16 @@ namespace :api, format: false do
# Experimental JSON / REST API
namespace :v1_alpha do
resources :async_refreshes, only: :show
end
# TODO: Remove once apps switch over to v1
scope :v1_alpha, as: :v1_alpha, module: :v1 do
resources :accounts, only: [] do
resources :collections, only: [:index]
resources :in_collections, only: [:index]
end
resources :async_refreshes, only: :show
resources :collections, only: [:show, :create, :update, :destroy] do
resources :items, only: [:create, :destroy], controller: 'collection_items' do
member do
@ -221,6 +224,9 @@ namespace :api, format: false do
resources :email_subscriptions, only: :create
end
resources :collections, only: [:index]
resources :in_collections, only: [:index]
member do
post :follow
post :unfollow
@ -327,6 +333,14 @@ namespace :api, format: false do
resources :tags, only: [:index, :show, :update]
end
resources :collections, only: [:show, :create, :update, :destroy] do
resources :items, only: [:create, :destroy], controller: 'collection_items' do
member do
post :revoke
end
end
end
end
namespace :v2 do

View File

@ -45,7 +45,7 @@ module Mastodon
def api_versions
{
mastodon: 9,
mastodon: 10,
}
end

View File

@ -2,12 +2,12 @@
require 'rails_helper'
RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
RSpec.describe 'Api::V1::Collections', feature: :collections do
include_context 'with API authentication', oauth_scopes: 'read:collections write:collections'
describe 'GET /api/v1_alpha/accounts/:account_id/collections' do
describe 'GET /api/v1/accounts/:account_id/collections' do
subject do
get "/api/v1_alpha/accounts/#{account.id}/collections", headers: headers, params: params
get "/api/v1/accounts/#{account.id}/collections", headers: headers, params: params
end
let(:params) { {} }
@ -34,7 +34,7 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
expect(response)
.to include_pagination_headers(
next: api_v1_alpha_account_collections_url(account, limit: 1, offset: 1)
next: api_v1_account_collections_url(account, limit: 1, offset: 1)
)
end
end
@ -50,8 +50,8 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
expect(response)
.to include_pagination_headers(
prev: api_v1_alpha_account_collections_url(account, limit: 1, offset: 0),
next: api_v1_alpha_account_collections_url(account, limit: 1, offset: 2)
prev: api_v1_account_collections_url(account, limit: 1, offset: 0),
next: api_v1_account_collections_url(account, limit: 1, offset: 2)
)
end
end
@ -96,9 +96,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
end
end
describe 'GET /api/v1_alpha/collections/:id' do
describe 'GET /api/v1/collections/:id' do
subject do
get "/api/v1_alpha/collections/#{collection.id}", headers: headers
get "/api/v1/collections/#{collection.id}", headers: headers
end
let(:collection) { Fabricate(:collection) }
@ -140,9 +140,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
end
end
describe 'POST /api/v1_alpha/collections' do
describe 'POST /api/v1/collections' do
subject do
post '/api/v1_alpha/collections', headers: headers, params: params
post '/api/v1/collections', headers: headers, params: params
end
let(:params) { {} }
@ -187,9 +187,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
end
end
describe 'PATCH /api/v1_alpha/collections/:id' do
describe 'PATCH /api/v1/collections/:id' do
subject do
patch "/api/v1_alpha/collections/#{collection.id}", headers: headers, params: params
patch "/api/v1/collections/#{collection.id}", headers: headers, params: params
end
let(:collection) { Fabricate(:collection) }
@ -256,9 +256,9 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
end
end
describe 'DELETE /api/v1_alpha/collections/:id' do
describe 'DELETE /api/v1/collections/:id' do
subject do
delete "/api/v1_alpha/collections/#{collection.id}", headers: headers
delete "/api/v1/collections/#{collection.id}", headers: headers
end
let(:collection) { Fabricate(:collection) }

View File

@ -2,12 +2,12 @@
require 'rails_helper'
RSpec.describe 'Api::V1Alpha::InCollections', feature: :collections do
RSpec.describe 'Api::V1::InCollections', feature: :collections do
include_context 'with API authentication', oauth_scopes: 'read:collections write:collections'
describe 'GET /api/v1_alpha/in_collections' do
describe 'GET /api/v1/in_collections' do
subject do
get "/api/v1_alpha/accounts/#{account.id}/in_collections", headers: headers, params: params
get "/api/v1/accounts/#{account.id}/in_collections", headers: headers, params: params
end
let(:params) { {} }
@ -33,7 +33,7 @@ RSpec.describe 'Api::V1Alpha::InCollections', feature: :collections do
expect(response)
.to include_pagination_headers(
next: api_v1_alpha_account_in_collections_url(account, limit: 1, offset: 1)
next: api_v1_account_in_collections_url(account, limit: 1, offset: 1)
)
end
end
@ -49,8 +49,8 @@ RSpec.describe 'Api::V1Alpha::InCollections', feature: :collections do
expect(response)
.to include_pagination_headers(
prev: api_v1_alpha_account_in_collections_url(account, limit: 1, offset: 0),
next: api_v1_alpha_account_in_collections_url(account, limit: 1, offset: 2)
prev: api_v1_account_in_collections_url(account, limit: 1, offset: 0),
next: api_v1_account_in_collections_url(account, limit: 1, offset: 2)
)
end
end