WIP create invites via API
This commit is contained in:
parent
582b1423c8
commit
48822cc0b1
18
app/controllers/api/v1/invites_controller.rb
Normal file
18
app/controllers/api/v1/invites_controller.rb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Api::V1::InvitesController < Api::BaseController
|
||||||
|
|
||||||
|
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }
|
||||||
|
before_action :require_user!
|
||||||
|
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
|
def create
|
||||||
|
@invite = Invite.new(max_uses: 1)
|
||||||
|
@invite.user = current_user
|
||||||
|
@invite.save!
|
||||||
|
|
||||||
|
render json: @invite, serializer: REST::InviteSerializer
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
21
app/serializers/rest/invite_serializer.rb
Normal file
21
app/serializers/rest/invite_serializer.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class REST::InviteSerializer < ActiveModel::Serializer
|
||||||
|
attributes :id, :code, :expires_at, :max_uses
|
||||||
|
|
||||||
|
def id
|
||||||
|
object.id.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def code
|
||||||
|
object.code
|
||||||
|
end
|
||||||
|
|
||||||
|
def expires_at
|
||||||
|
object.expires_at
|
||||||
|
end
|
||||||
|
|
||||||
|
def max_uses
|
||||||
|
object.max_uses
|
||||||
|
end
|
||||||
|
end
|
@ -297,6 +297,7 @@ Rails.application.routes.draw do
|
|||||||
resources :reports, only: [:create]
|
resources :reports, only: [:create]
|
||||||
resources :filters, only: [:index, :create, :show, :update, :destroy]
|
resources :filters, only: [:index, :create, :show, :update, :destroy]
|
||||||
resources :endorsements, only: [:index]
|
resources :endorsements, only: [:index]
|
||||||
|
resources :invites, only: [:create]
|
||||||
|
|
||||||
namespace :apps do
|
namespace :apps do
|
||||||
get :verify_credentials, to: 'credentials#show'
|
get :verify_credentials, to: 'credentials#show'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user