forked from ComPlat/chemotion_ELN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add element form type model, admin area
- Loading branch information
Showing
12 changed files
with
773 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
module Chemotion | ||
class ElementFormTypeAPI < Grape::API | ||
resource :element_form_types do | ||
desc 'Index: List all element form types' | ||
get do | ||
present ElementFormType.all, with: Entities::ElementFormTypeEntity | ||
end | ||
|
||
desc 'create a new element form type' | ||
params do | ||
requires :name, type: String | ||
optional :description, type: String | ||
requires :element_type, type: String, values: %w[sample reaction wellplate screen] | ||
optional :enabled, type: Boolean | ||
end | ||
post do | ||
element_form_type = | ||
ElementFormType.create!( | ||
creator: current_user, | ||
name: params[:name], | ||
description: params[:description], | ||
element_type: params[:element_type], | ||
enabled: params[:enabled], | ||
) | ||
present element_form_type, with: Entities::ElementFormTypeEntity | ||
end | ||
|
||
desc 'get element form type by id' | ||
params do | ||
requires :id, type: Integer, desc: 'element form type id' | ||
end | ||
route_param :id do | ||
get do | ||
present ElementFormType.find_by(id: params[:id]), with: Entities::ElementFormTypeEntity | ||
end | ||
end | ||
|
||
desc 'update a element form type' | ||
params do | ||
optional :id, type: Integer | ||
optional :name, type: String | ||
optional :description, type: String | ||
optional :element_type, type: String, values: %w[sample reaction wellplate screen] | ||
optional :enabled, type: Boolean | ||
optional :structure, type: Hash | ||
end | ||
put ':id' do | ||
element_form_type = ElementFormType.find_by(id: params[:id]) | ||
element_form_type.update!( | ||
name: params[:name], | ||
description: params[:description], | ||
element_type: params[:element_type], | ||
enabled: params[:enabled], | ||
structure: params[:structure], | ||
) | ||
present element_form_type, with: Entities::ElementFormTypeEntity | ||
end | ||
|
||
desc 'update a element form type' | ||
delete ':id' do | ||
element_form_type = ElementFormType.find_by(id: params[:id]) | ||
unless element_form_type.present? && element_form_type.destroy | ||
error!('element form type could not be deleted', 400) | ||
end | ||
|
||
{ deleted: element_form_type.id } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Entities | ||
class ElementFormTypeEntity < ApplicationEntity | ||
root :element_form_types # root key when rendering a list of element form types | ||
|
||
expose :id | ||
expose :name | ||
expose :description | ||
expose :element_type | ||
expose :structure, default: {} | ||
expose :enabled | ||
|
||
# expose_timestamps | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class ElementFormType < ApplicationRecord | ||
belongs_to :creator, class_name: 'User' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.