mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
(api) openAPI spaces endpoints
index spaces and show a space
This commit is contained in:
parent
5429e9889f
commit
4c3aa59bc0
@ -1,5 +1,6 @@
|
||||
# Changelog Fab-manager
|
||||
|
||||
- OpenAPI spaces endpoints (index/show)
|
||||
- Improved automated test on statistics generation
|
||||
- Refactored statistics generation
|
||||
- Refactored test helpers
|
||||
|
21
app/controllers/open_api/v1/spaces_controller.rb
Normal file
21
app/controllers/open_api/v1/spaces_controller.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# authorized 3rd party softwares can fetch data about spaces through the OpenAPI
|
||||
class OpenAPI::V1::SpacesController < OpenAPI::V1::BaseController
|
||||
extend OpenAPI::ApiDoc
|
||||
expose_doc
|
||||
|
||||
before_action :set_space, only: %i[show]
|
||||
|
||||
def index
|
||||
@spaces = Space.order(:created_at)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
private
|
||||
|
||||
def set_space
|
||||
@space = Space.friendly.find(params[:id])
|
||||
end
|
||||
end
|
@ -93,7 +93,8 @@ class OpenAPI::V1::MachinesDoc < OpenAPI::V1::BaseDoc
|
||||
param :name, String, desc: 'The name of the machine.', required: true
|
||||
param :description, String, desc: 'A long textual description of the machine. HTML is supported.', required: true
|
||||
param :spec, String, desc: 'A long textual description of the technical specifications of the machine. HTML is supported.'
|
||||
param :disabled, [TrueClass, FalseClass], desc: "Should the machine be disabled? If yes, the machine won't be reservable and will be shown apart."
|
||||
param :disabled, [TrueClass, FalseClass], desc: "Should the machine be disabled? If yes, the machine won't be reservable and " \
|
||||
'will be shown apart.'
|
||||
param :machine_image_attributes, Hash do
|
||||
param :attachment, ActionDispatch::Http::UploadedFile, required: true, desc: 'Upload a picture for the machine.'
|
||||
end
|
||||
@ -126,7 +127,8 @@ class OpenAPI::V1::MachinesDoc < OpenAPI::V1::BaseDoc
|
||||
param :name, String, desc: 'The name of the machine.', required: true
|
||||
param :description, String, desc: 'A long textual description of the machine. HTML is supported.', required: true
|
||||
param :spec, String, desc: 'A long textual description of the technical specifications of the machine. HTML is supported.'
|
||||
param :disabled, [TrueClass, FalseClass], desc: "Should the machine be disabled? If yes, the machine won't be reservable and will be shown apart."
|
||||
param :disabled, [TrueClass, FalseClass], desc: "Should the machine be disabled? If yes, the machine won't be reservable and " \
|
||||
'will be shown apart.'
|
||||
param :machine_image_attributes, Hash do
|
||||
param :attachment, ActionDispatch::Http::UploadedFile, required: true, desc: 'Upload a picture for the machine.'
|
||||
end
|
||||
@ -163,7 +165,7 @@ class OpenAPI::V1::MachinesDoc < OpenAPI::V1::BaseDoc
|
||||
"created_at": "2014-06-30T03:32:31.972+02:00",
|
||||
"description": "La découpeuse Laser, EPILOG Legend 36EXT\r\n\r\nInformations générales :\r\nLa découpeuse laser vous permet de découper ou graver des matériaux. \r\n\r\nPour la découpe, il suffit d'apporter votre fichier vectorisé type illustrator, svg ou dxf avec des \"lignes de coupe\" d'une épaisseur inférieure à 0,01 mm et la machine s'occupera du reste!\r\n\r\nLa gravure est basée sur le spectre noir et blanc. Les nuances sont obtenues par différentes profondeurs de gravure correspondant aux niveaux de gris de votre image. Il suffit pour cela d'apporter une image scannée ou un fichier photo en noir et blanc pour pouvoir reproduire celle-ci sur votre support.\r\n\r\nTypes de matériaux gravables/découpeables ?\r\nDu bois au tissu, du plexiglass au cuir, cette machine permet de découper et graver la plupart des matériaux sauf les métaux. La gravure est néanmoins possible sur les métaux recouverts d'une couche de peinture ou les aluminiums anodisés. \r\nConcernant l'épaisseur des matériaux découpés, il est préférable de ne pas dépasser 5 mm pour le bois et 6 mm pour le plexiglass.\r\n",
|
||||
"spec": "Puissance : 40W\r\nSurface de travail : 914x609 mm \r\nEpaisseur maximale de la matière : 305mm\r\nSource laser : tube laser type CO2\r\nContrôles de vitesse et de puissance : ces deux paramètres sont ajustables en fonction du matériau (de 1% à 100%) .\r\n",
|
||||
"image": "/uploads/machine_image/2514/machine_image.jpg"
|
||||
"image": "https://example.com/uploads/machine_image/2514/machine_image.jpg"
|
||||
}
|
||||
MACHINES
|
||||
end
|
||||
|
63
app/doc/open_api/v1/spaces_doc.rb
Normal file
63
app/doc/open_api/v1/spaces_doc.rb
Normal file
@ -0,0 +1,63 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# openAPI documentation for spaces endpoint
|
||||
class OpenAPI::V1::SpacesDoc < OpenAPI::V1::BaseDoc
|
||||
resource_description do
|
||||
short 'Spaces'
|
||||
desc 'Spaces of Fab-manager'
|
||||
formats FORMATS
|
||||
api_version API_VERSION
|
||||
end
|
||||
|
||||
doc_for :index do
|
||||
api :GET, "/#{API_VERSION}/spaces", 'Spaces index'
|
||||
description 'Spaces index. Order by *created_at* ascendant.'
|
||||
example <<-SPACES
|
||||
# /open_api/v1/spaces
|
||||
{
|
||||
"spaces": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Wood workshop",
|
||||
"slug": "wood-workshop",
|
||||
"disabled": null,
|
||||
"updated_at": "2017-02-15 15:55:04.123928000 Z",
|
||||
"created_at": "2017-02-24 18:02:21.852147000+01:00",
|
||||
"description": "Become a real carpenter in the wood workshop area of your fablab.\r\n",
|
||||
"characteristics": "Tools available: Coping saw, plane, jointer, beveller and pyrographer.\r\n"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Movie studio",
|
||||
"slug": "Movie-studio",
|
||||
"disabled": null,
|
||||
"updated_at": "2018-04-22 18:16:09.143617000 Z",
|
||||
"created_at": "2018-06-29T07:47:59.187510000+02:00",
|
||||
"description": "Think of yourself as Alfred Hitchcock and let your imagination run free to take your best indoor shots in this fully-equipped cinema studio.\r\n",
|
||||
"spec": "Thanks to a system of hanging curtains, this studio is divisible into 3 parts of 90m², each one being equipped with a fixed grill of 9Mx7M, an inlay green screen of 8.5Mx8M opening, as well as 8 projectors DMX controlled cycloids for green screen lighting."
|
||||
}
|
||||
]
|
||||
}
|
||||
SPACES
|
||||
end
|
||||
|
||||
doc_for :show do
|
||||
api :GET, "/#{API_VERSION}/spaces/:id", 'Show a space'
|
||||
description 'Show all the details of single space.'
|
||||
example <<-SPACES
|
||||
# /open_api/v1/spaces/1
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Wood workshop",
|
||||
"slug": "wood-workshop",
|
||||
"disabled": null,
|
||||
"updated_at": "2017-02-15 15:55:04.123928000 Z",
|
||||
"created_at": "2017-02-24 18:02:21.852147000+01:00",
|
||||
"description": "Become a real carpenter in the wood workshop area of your fablab.\r\n",
|
||||
"characteristics": "Tools available: Coping saw, plane, jointer, beveller and pyrographer.\r\n",
|
||||
"default_places": 4,
|
||||
"image": "https://example.com/uploads/space_image/2686/space_image.jpg"
|
||||
}
|
||||
SPACES
|
||||
end
|
||||
end
|
3
app/views/open_api/v1/spaces/_space.json.jbuilder
Normal file
3
app/views/open_api/v1/spaces/_space.json.jbuilder
Normal file
@ -0,0 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! space, :id, :name, :slug, :disabled, :updated_at, :created_at
|
6
app/views/open_api/v1/spaces/index.json.jbuilder
Normal file
6
app/views/open_api/v1/spaces/index.json.jbuilder
Normal file
@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.machines @spaces do |space|
|
||||
json.partial! 'open_api/v1/spaces/space', space: space
|
||||
json.extract! space, :description, :characteristics
|
||||
end
|
5
app/views/open_api/v1/spaces/show.json.jbuilder
Normal file
5
app/views/open_api/v1/spaces/show.json.jbuilder
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.partial! 'open_api/v1/spaces/space', space: @space
|
||||
json.extract! @space, :description, :characteristics
|
||||
json.image URI.join(root_url, @space.space_image.attachment.url) if @space.space_image
|
@ -245,6 +245,7 @@ Rails.application.routes.draw do
|
||||
resources :user_trainings
|
||||
resources :reservations
|
||||
resources :machines, only: %i[index create update show destroy]
|
||||
resources :spaces, only: %i[index show]
|
||||
resources :bookable_machines
|
||||
resources :invoices do
|
||||
get :download, on: :member
|
||||
@ -262,7 +263,7 @@ Rails.application.routes.draw do
|
||||
post '/stats/global/export', to: 'api/statistics#export_global'
|
||||
post '_search/scroll', to: 'api/statistics#scroll'
|
||||
|
||||
match '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid', via: :get
|
||||
get '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid'
|
||||
|
||||
authenticate :user, ->(u) { u.admin? } do
|
||||
mount Sidekiq::Web => '/admin/sidekiq'
|
||||
|
21
test/integration/open_api/spaces_test.rb
Normal file
21
test/integration/open_api/spaces_test.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module OpenApi; end
|
||||
|
||||
class OpenApi::SpacesTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||
end
|
||||
|
||||
test 'list all spaces' do
|
||||
get '/open_api/v1/spaces', headers: open_api_headers(@token)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'get a space' do
|
||||
get '/open_api/v1/spaces/1', headers: open_api_headers(@token)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user