mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
(api) OpenAPI plans endpoints
index and show endpoints
This commit is contained in:
parent
4c3aa59bc0
commit
657723bc22
@ -1,6 +1,7 @@
|
||||
# Changelog Fab-manager
|
||||
|
||||
- OpenAPI spaces endpoints (index/show)
|
||||
- OpenAPI plans endpoints (index/show)
|
||||
- Improved automated test on statistics generation
|
||||
- Refactored statistics generation
|
||||
- Refactored test helpers
|
||||
|
21
app/controllers/open_api/v1/plans_controller.rb
Normal file
21
app/controllers/open_api/v1/plans_controller.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# authorized 3rd party softwares can fetch data about plans through the OpenAPI
|
||||
class OpenAPI::V1::PlansController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
expose_doc
|
||||
|
||||
before_action :set_plan, only: %i[show]
|
||||
|
||||
def index
|
||||
@plans = Plan.order(:created_at)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
private
|
||||
|
||||
def set_plan
|
||||
@plan = Plan.friendly.find(params[:id])
|
||||
end
|
||||
end
|
96
app/doc/open_api/v1/plans_doc.rb
Normal file
96
app/doc/open_api/v1/plans_doc.rb
Normal file
@ -0,0 +1,96 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# openAPI documentation for plans endpoint
|
||||
class OpenAPI::V1::PlansDoc < OpenAPI::V1::BaseDoc
|
||||
resource_description do
|
||||
short 'Plans'
|
||||
desc 'Subscription plans of Fab-manager'
|
||||
formats FORMATS
|
||||
api_version API_VERSION
|
||||
end
|
||||
|
||||
doc_for :index do
|
||||
api :GET, "/#{API_VERSION}/plans", 'Plans index'
|
||||
description 'Plans index. Order by *created_at* ascendant.'
|
||||
example <<-PLANS
|
||||
# /open_api/v1/plans
|
||||
{
|
||||
"plans": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "One month - standard",
|
||||
"slug": "one-month-standard",
|
||||
"amount": 3000
|
||||
"interval": month,
|
||||
"interval_count": 1,
|
||||
"group_id": 1
|
||||
"disabled": null,
|
||||
"ui_weight": 3,
|
||||
"monthly_payment": false,
|
||||
"updated_at": "2001-01-01 15:15:19.860064000 Z",
|
||||
"created_at": "2001-01-01 15:19:28.367161000 Z"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "One month - students",
|
||||
"slug": "one-month-students",
|
||||
"amount": 2000
|
||||
"interval": month,
|
||||
"interval_count": 1,
|
||||
"group_id": 2
|
||||
"disabled": null,
|
||||
"ui_weight": 0,
|
||||
"monthly_payment": false,
|
||||
"updated_at": "2016-04-04 15:18:27.734657000 Z",
|
||||
"created_at": "2016-04-04 15:18:27.734657000 Z"
|
||||
},
|
||||
#
|
||||
# ....
|
||||
#
|
||||
{
|
||||
"id": 9,
|
||||
"name": "One year - corporations",
|
||||
"slug": "one-month-corporations",
|
||||
"amount": 36000
|
||||
"interval": year,
|
||||
"interval_count": 1,
|
||||
"group_id": 3
|
||||
"disabled": null,
|
||||
"ui_weight": 9,
|
||||
"monthly_payment": true,
|
||||
"updated_at": "2020-12-14 14:10:11.056241000 Z",
|
||||
"created_at": "2020-12-14 14:10:11.056241000 Z"
|
||||
},
|
||||
]
|
||||
}
|
||||
PLANS
|
||||
end
|
||||
|
||||
doc_for :show do
|
||||
api :GET, "/#{API_VERSION}/plans/:id", 'Shows a plan'
|
||||
description 'Show all details of a single plan.'
|
||||
example <<-PLAN
|
||||
# /open_api/v1/plans/9
|
||||
{
|
||||
"id": 9,
|
||||
"name": "One year - corporations",
|
||||
"slug": "one-month-corporations",
|
||||
"amount": 36000
|
||||
"interval": year,
|
||||
"interval_count": 1,
|
||||
"group_id": 3
|
||||
"disabled": null,
|
||||
"ui_weight": 9,
|
||||
"monthly_payment": true,
|
||||
"updated_at": "2020-12-14 14:10:11.056241000 Z",
|
||||
"created_at": "2020-12-14 14:10:11.056241000 Z",
|
||||
"training_credit_nb": 10,
|
||||
"is_rolling": true,
|
||||
"description": "10 trainings and 30 machine hours offered with your subscription to this plan",
|
||||
"type": "Plan",
|
||||
"plan_category_id": 2,
|
||||
"file": "https://example.com/uploads/plan_file/25/Pricing_Grid_2020_2021_v2.png"
|
||||
}
|
||||
PLAN
|
||||
end
|
||||
end
|
4
app/views/open_api/v1/plans/_plan.json.jbuilder
Normal file
4
app/views/open_api/v1/plans/_plan.json.jbuilder
Normal file
@ -0,0 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! plan, :id, :name, :slug, :amount, :interval, :interval_count, :group_id, :disabled, :ui_weight, :monthly_payment, :updated_at,
|
||||
:created_at
|
5
app/views/open_api/v1/plans/index.json.jbuilder
Normal file
5
app/views/open_api/v1/plans/index.json.jbuilder
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.plans @plans do |plan|
|
||||
json.partial! 'open_api/v1/plans/plan', plan: plan
|
||||
end
|
5
app/views/open_api/v1/plans/show.json.jbuilder
Normal file
5
app/views/open_api/v1/plans/show.json.jbuilder
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.partial! 'open_api/v1/plans/plan', plan: @plan
|
||||
json.extract! @plan, :training_credit_nb, :is_rolling, :description, :type, :plan_category_id
|
||||
json.file URI.join(root_url, @plan.plan_file.attachment.url) if @plan.plan_file
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.machines @spaces do |space|
|
||||
json.spaces @spaces do |space|
|
||||
json.partial! 'open_api/v1/spaces/space', space: space
|
||||
json.extract! space, :description, :characteristics
|
||||
end
|
||||
|
@ -240,6 +240,7 @@ Rails.application.routes.draw do
|
||||
namespace :open_api do
|
||||
namespace :v1 do
|
||||
scope only: :index do
|
||||
resources :plans, only: %i[index show]
|
||||
resources :users
|
||||
resources :trainings
|
||||
resources :user_trainings
|
||||
|
21
test/integration/open_api/plans_test.rb
Normal file
21
test/integration/open_api/plans_test.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module OpenApi; end
|
||||
|
||||
class OpenApi::PlansTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||
end
|
||||
|
||||
test 'list all plans' do
|
||||
get '/open_api/v1/plans', headers: open_api_headers(@token)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'get a plan' do
|
||||
get '/open_api/v1/plans/1', headers: open_api_headers(@token)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user