1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-03-21 12:29:03 +01:00

(api) OpenAPI plans categories index endpoint

This commit is contained in:
Sylvain 2022-08-30 13:11:08 +02:00
parent 657723bc22
commit 4319ea9bce
7 changed files with 74 additions and 1 deletions

View File

@ -2,6 +2,7 @@
- OpenAPI spaces endpoints (index/show)
- OpenAPI plans endpoints (index/show)
- OpenAPI plans categories index endpoint
- Improved automated test on statistics generation
- Refactored statistics generation
- Refactored test helpers

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
# authorized 3rd party softwares can fetch data about plan categories through the OpenAPI
class OpenAPI::V1::PlanCategoriesController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc
expose_doc
def index
@plans_categories = PlanCategory.order(:created_at)
end
end

View File

@ -0,0 +1,39 @@
# frozen_string_literal: true
# openAPI documentation for plan categories endpoint
class OpenAPI::V1::PlanCategoriesDoc < OpenAPI::V1::BaseDoc
resource_description do
short 'Plans categories'
desc 'Categories of subscription plans'
formats FORMATS
api_version API_VERSION
end
doc_for :index do
api :GET, "/#{API_VERSION}/plan_categories", 'Plans categories index'
description 'Plans categories index. Order by *created_at* ascendant.'
example <<-PLAN_CATEGORIES
# /open_api/v1/plan_categories
{
"plan_categories": [
{
"id": 1,
"name": "CRAZY LAB",
"weight": 0,
"description": "Lorem ipsum dolor sit amet",
"updated_at": "2021-12-01 15:15:19.860064000 Z",
"created_at": "2021-12-01 15:19:28.367161000 Z"
},
{
"id": 2,
"name": "PREMIUM",
"weight": 1,
"description": "<p>Lorem ipsum <b>dolor</b> sit amet</p>",
"updated_at": "2021-12-01 15:15:19.860064000 Z",
"created_at": "2021-12-01 15:19:28.367161000 Z"
}
]
}
PLAN_CATEGORIES
end
end

View File

@ -60,7 +60,7 @@ class OpenAPI::V1::PlansDoc < OpenAPI::V1::BaseDoc
"monthly_payment": true,
"updated_at": "2020-12-14 14:10:11.056241000 Z",
"created_at": "2020-12-14 14:10:11.056241000 Z"
},
}
]
}
PLANS

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
json.plan_categories @plans_categories do |category|
json.extract! category, :id, :name, :weight, :description, :updated_at, :created_at
end

View File

@ -241,6 +241,7 @@ Rails.application.routes.draw do
namespace :v1 do
scope only: :index do
resources :plans, only: %i[index show]
resources :plan_categories
resources :users
resources :trainings
resources :user_trainings

View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'test_helper'
module OpenApi; end
class OpenApi::PlanCategoriesTest < ActionDispatch::IntegrationTest
def setup
@token = OpenAPI::Client.find_by(name: 'minitest').token
end
test 'list all plan categories' do
get '/open_api/v1/plan_categories', headers: open_api_headers(@token)
assert_response :success
end
end