workarea-api-admin 4.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/README.md +82 -0
- data/Rakefile +10 -0
- data/app/assets/images/workarea/api/admin/icons/api.svg +1 -0
- data/app/controllers/workarea/api/admin/application_controller.rb +73 -0
- data/app/controllers/workarea/api/admin/categories_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/category_product_rules_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/content_assets_controller.rb +299 -0
- data/app/controllers/workarea/api/admin/content_controller.rb +268 -0
- data/app/controllers/workarea/api/admin/discounts_controller.rb +271 -0
- data/app/controllers/workarea/api/admin/email_signups_controller.rb +108 -0
- data/app/controllers/workarea/api/admin/fulfillments_controller.rb +268 -0
- data/app/controllers/workarea/api/admin/inventory_skus_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/navigation_menus_controller.rb +267 -0
- data/app/controllers/workarea/api/admin/navigation_taxons_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/orders_controller.rb +160 -0
- data/app/controllers/workarea/api/admin/pages_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/payment_profiles_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/payment_transactions_controller.rb +108 -0
- data/app/controllers/workarea/api/admin/payments_controller.rb +115 -0
- data/app/controllers/workarea/api/admin/prices_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/pricing_skus_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/product_images_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/products_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/promo_code_lists_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/recommendation_settings_controller.rb +122 -0
- data/app/controllers/workarea/api/admin/redirects_controller.rb +305 -0
- data/app/controllers/workarea/api/admin/releases_controller.rb +304 -0
- data/app/controllers/workarea/api/admin/saved_addresses_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/saved_credit_cards_controller.rb +256 -0
- data/app/controllers/workarea/api/admin/shipping_rates_controller.rb +232 -0
- data/app/controllers/workarea/api/admin/shipping_services_controller.rb +299 -0
- data/app/controllers/workarea/api/admin/shippings_controller.rb +105 -0
- data/app/controllers/workarea/api/admin/swagger_controller.rb +41 -0
- data/app/controllers/workarea/api/admin/tax_categories_controller.rb +242 -0
- data/app/controllers/workarea/api/admin/tax_rates_controller.rb +292 -0
- data/app/controllers/workarea/api/admin/users_controller.rb +296 -0
- data/app/controllers/workarea/api/admin/variants_controller.rb +232 -0
- data/app/models/workarea/api/admin/bulk_upsert.rb +74 -0
- data/app/models/workarea/user.decorator +7 -0
- data/app/views/workarea/admin/users/_api_permissions.html.haml +6 -0
- data/app/workers/workarea/perform_api_bulk_upsert.rb +15 -0
- data/bin/rails +18 -0
- data/config/initializers/append_points.rb +4 -0
- data/config/initializers/config.rb +15 -0
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +81 -0
- data/lib/workarea/api/admin.rb +21 -0
- data/lib/workarea/api/admin/engine.rb +14 -0
- data/lib/workarea/api/admin/swagger.rb +106 -0
- data/test/documentation/workarea/api/admin/categories_documentation_test.rb +106 -0
- data/test/documentation/workarea/api/admin/category_product_rules_documentation_test.rb +78 -0
- data/test/documentation/workarea/api/admin/content_assets_documentation_test.rb +94 -0
- data/test/documentation/workarea/api/admin/content_documentation_test.rb +87 -0
- data/test/documentation/workarea/api/admin/discounts_documentation_test.rb +85 -0
- data/test/documentation/workarea/api/admin/email_signups_documentation_test.rb +41 -0
- data/test/documentation/workarea/api/admin/fulfillment_documentation_test.rb +84 -0
- data/test/documentation/workarea/api/admin/inventory_skus_documentation_test.rb +95 -0
- data/test/documentation/workarea/api/admin/navigation_menus_documentation_test.rb +81 -0
- data/test/documentation/workarea/api/admin/navigation_taxons_documentation_test.rb +94 -0
- data/test/documentation/workarea/api/admin/orders_documentation_test.rb +65 -0
- data/test/documentation/workarea/api/admin/pages_documentation_test.rb +93 -0
- data/test/documentation/workarea/api/admin/payment_profiles_documentation_test.rb +98 -0
- data/test/documentation/workarea/api/admin/payment_transactions_documentation_test.rb +43 -0
- data/test/documentation/workarea/api/admin/payments_documentation_test.rb +41 -0
- data/test/documentation/workarea/api/admin/prices_documentation_test.rb +82 -0
- data/test/documentation/workarea/api/admin/pricing_skus_documentation_test.rb +95 -0
- data/test/documentation/workarea/api/admin/product_images_documentation_test.rb +101 -0
- data/test/documentation/workarea/api/admin/products_documentation_test.rb +96 -0
- data/test/documentation/workarea/api/admin/promo_code_lists_documentation_test.rb +94 -0
- data/test/documentation/workarea/api/admin/recommendation_settings_documentation_test.rb +37 -0
- data/test/documentation/workarea/api/admin/redirects_documentation_test.rb +96 -0
- data/test/documentation/workarea/api/admin/release_changes_documentation_test.rb +32 -0
- data/test/documentation/workarea/api/admin/releases_documentation_test.rb +93 -0
- data/test/documentation/workarea/api/admin/saved_addresses_documentation_test.rb +92 -0
- data/test/documentation/workarea/api/admin/saved_credit_cards_documentation_test.rb +86 -0
- data/test/documentation/workarea/api/admin/shipping_rates_documentation_test.rb +78 -0
- data/test/documentation/workarea/api/admin/shipping_services_documentation_test.rb +93 -0
- data/test/documentation/workarea/api/admin/shippings_documentation_test.rb +41 -0
- data/test/documentation/workarea/api/admin/tax_categories_documentation_test.rb +95 -0
- data/test/documentation/workarea/api/admin/tax_rates_documentation_test.rb +78 -0
- data/test/documentation/workarea/api/admin/users_documentation_test.rb +99 -0
- data/test/documentation/workarea/api/admin/variants_documentation_test.rb +80 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +55 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +1 -0
- data/test/integration/workarea/api/admin/audit_log_integration_test.rb +20 -0
- data/test/integration/workarea/api/admin/authentication_integration_test.rb +61 -0
- data/test/integration/workarea/api/admin/categories_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/category_product_rules_integration_test.rb +58 -0
- data/test/integration/workarea/api/admin/content_assets_integration_test.rb +65 -0
- data/test/integration/workarea/api/admin/content_integration_test.rb +59 -0
- data/test/integration/workarea/api/admin/discounts_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/email_signups_integration_test.rb +32 -0
- data/test/integration/workarea/api/admin/error_handling_integration_test.rb +16 -0
- data/test/integration/workarea/api/admin/fulfillments_integration_test.rb +62 -0
- data/test/integration/workarea/api/admin/inventory_skus_integration_test.rb +70 -0
- data/test/integration/workarea/api/admin/navigation_menus_integration_test.rb +54 -0
- data/test/integration/workarea/api/admin/navigation_taxons_integration_test.rb +63 -0
- data/test/integration/workarea/api/admin/orders_integration_test.rb +53 -0
- data/test/integration/workarea/api/admin/pages_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/payment_profiles_integration_test.rb +75 -0
- data/test/integration/workarea/api/admin/payment_transactions_integration_test.rb +45 -0
- data/test/integration/workarea/api/admin/payments_integration_test.rb +29 -0
- data/test/integration/workarea/api/admin/prices_integration_test.rb +55 -0
- data/test/integration/workarea/api/admin/pricing_skus_integration_test.rb +72 -0
- data/test/integration/workarea/api/admin/product_images_integration_test.rb +56 -0
- data/test/integration/workarea/api/admin/products_integration_test.rb +66 -0
- data/test/integration/workarea/api/admin/promo_code_lists_integration_test.rb +70 -0
- data/test/integration/workarea/api/admin/recommendation_settings_integration_test.rb +41 -0
- data/test/integration/workarea/api/admin/redirects_integration_test.rb +69 -0
- data/test/integration/workarea/api/admin/release_changes_integration_test.rb +32 -0
- data/test/integration/workarea/api/admin/releases_integration_test.rb +60 -0
- data/test/integration/workarea/api/admin/saved_addresses_integration_test.rb +70 -0
- data/test/integration/workarea/api/admin/saved_credit_cards_integration_test.rb +76 -0
- data/test/integration/workarea/api/admin/shipping_rates_integration_test.rb +54 -0
- data/test/integration/workarea/api/admin/shipping_services_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/shippings_integration_test.rb +34 -0
- data/test/integration/workarea/api/admin/tax_categories_integration_test.rb +64 -0
- data/test/integration/workarea/api/admin/tax_rates_integration_test.rb +66 -0
- data/test/integration/workarea/api/admin/users_integration_test.rb +67 -0
- data/test/integration/workarea/api/admin/variants_integration_test.rb +59 -0
- data/test/models/workarea/api/admin/bulk_upsert_test.rb +79 -0
- data/test/test_helper.rb +10 -0
- data/test/vcr_cassettes/product_image_from_url.yml +43 -0
- data/workarea-api-admin.gemspec +18 -0
- metadata +252 -0
@@ -0,0 +1,292 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Admin
|
4
|
+
class TaxRatesController < Admin::ApplicationController
|
5
|
+
before_action :find_tax_category
|
6
|
+
before_action :find_tax_rate, except: [:index, :create, :bulk]
|
7
|
+
|
8
|
+
swagger_path '/tax_categories/{id}/rates' do
|
9
|
+
operation :get do
|
10
|
+
key :summary, 'All Tax Category Rates'
|
11
|
+
key :description, 'Returns all rates for a tax category'
|
12
|
+
key :operationId, 'listTaxCategoryRates'
|
13
|
+
key :produces, ['application/json']
|
14
|
+
|
15
|
+
parameter do
|
16
|
+
key :name, :id
|
17
|
+
key :in, :path
|
18
|
+
key :description, 'tax category ID'
|
19
|
+
key :required, true
|
20
|
+
key :type, :string
|
21
|
+
end
|
22
|
+
|
23
|
+
response 200 do
|
24
|
+
key :description, 'Tax category rates'
|
25
|
+
schema do
|
26
|
+
key :type, :object
|
27
|
+
property :rates do
|
28
|
+
key :type, :array
|
29
|
+
items do
|
30
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
operation :post do
|
38
|
+
key :summary, 'Create Tax Category Rate'
|
39
|
+
key :description, 'Creates a new tax category rate.'
|
40
|
+
key :operationId, 'addTaxCategoryRate'
|
41
|
+
key :produces, ['application/json']
|
42
|
+
|
43
|
+
parameter do
|
44
|
+
key :name, :id
|
45
|
+
key :in, :path
|
46
|
+
key :description, 'tax category ID'
|
47
|
+
key :required, true
|
48
|
+
key :type, :string
|
49
|
+
end
|
50
|
+
|
51
|
+
parameter do
|
52
|
+
key :name, :body
|
53
|
+
key :in, :body
|
54
|
+
key :description, 'Rate to add'
|
55
|
+
key :required, true
|
56
|
+
schema do
|
57
|
+
key :type, :object
|
58
|
+
property :rate do
|
59
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
response 201 do
|
65
|
+
key :description, 'Tax rate created'
|
66
|
+
schema do
|
67
|
+
key :type, :object
|
68
|
+
property :rate do
|
69
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
response 422 do
|
75
|
+
key :description, 'Validation failure'
|
76
|
+
schema do
|
77
|
+
key :type, :object
|
78
|
+
property :problem do
|
79
|
+
key :type, :string
|
80
|
+
end
|
81
|
+
property :document do
|
82
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def index
|
90
|
+
@tax_rates = @tax_category
|
91
|
+
.rates
|
92
|
+
.order_by(sort_field => sort_direction)
|
93
|
+
.page(params[:page])
|
94
|
+
|
95
|
+
respond_with rates: @tax_rates
|
96
|
+
end
|
97
|
+
|
98
|
+
def create
|
99
|
+
@tax_rate = @tax_category.rates.create!(params[:rate])
|
100
|
+
respond_with(
|
101
|
+
{ rate: @tax_rate },
|
102
|
+
{ status: :created,
|
103
|
+
location: tax_category_rate_path(@tax_category, @tax_rate) }
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
swagger_path '/tax_categories/{tax_category_id}/rates/{id}' do
|
108
|
+
operation :patch do
|
109
|
+
key :summary, 'Update a tax category rate'
|
110
|
+
key :description, 'Updates attributes on a tax category rate'
|
111
|
+
key :operationId, 'updateTaxCategoryRate'
|
112
|
+
|
113
|
+
parameter do
|
114
|
+
key :name, :tax_category_id
|
115
|
+
key :in, :path
|
116
|
+
key :description, 'ID of tax category to update'
|
117
|
+
key :required, true
|
118
|
+
key :type, :string
|
119
|
+
end
|
120
|
+
|
121
|
+
parameter do
|
122
|
+
key :name, :id
|
123
|
+
key :in, :path
|
124
|
+
key :description, 'ID of tax category rate to update'
|
125
|
+
key :required, true
|
126
|
+
key :type, :string
|
127
|
+
end
|
128
|
+
|
129
|
+
parameter do
|
130
|
+
key :name, :body
|
131
|
+
key :in, :body
|
132
|
+
key :description, 'New attributes'
|
133
|
+
key :required, true
|
134
|
+
schema do
|
135
|
+
key :type, :object
|
136
|
+
property :rate do
|
137
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
response 204 do
|
143
|
+
key :description, 'Tax category rate updated successfully'
|
144
|
+
end
|
145
|
+
|
146
|
+
response 422 do
|
147
|
+
key :description, 'Validation failure'
|
148
|
+
schema do
|
149
|
+
key :type, :object
|
150
|
+
property :problem do
|
151
|
+
key :type, :string
|
152
|
+
end
|
153
|
+
property :document do
|
154
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
response 404 do
|
160
|
+
key :description, 'Tax category or rate not found'
|
161
|
+
schema do
|
162
|
+
key :type, :object
|
163
|
+
property :problem do
|
164
|
+
key :type, :string
|
165
|
+
end
|
166
|
+
property :params do
|
167
|
+
key :type, :object
|
168
|
+
key :additionalProperties, true
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
operation :delete do
|
175
|
+
key :summary, 'Remove a Tax Category Rate'
|
176
|
+
key :description, 'Remove a tax category rate'
|
177
|
+
key :operationId, 'removeTaxCategoryRate'
|
178
|
+
|
179
|
+
parameter do
|
180
|
+
key :name, :tax_category_id
|
181
|
+
key :in, :path
|
182
|
+
key :description, 'ID of tax category'
|
183
|
+
key :required, true
|
184
|
+
key :type, :string
|
185
|
+
end
|
186
|
+
|
187
|
+
parameter do
|
188
|
+
key :name, :id
|
189
|
+
key :in, :path
|
190
|
+
key :description, 'ID of rate to update'
|
191
|
+
key :required, true
|
192
|
+
key :type, :string
|
193
|
+
end
|
194
|
+
|
195
|
+
response 204 do
|
196
|
+
key :description, 'Tax category rate removed successfully'
|
197
|
+
end
|
198
|
+
|
199
|
+
response 404 do
|
200
|
+
key :description, 'Tax category or rate not found'
|
201
|
+
schema do
|
202
|
+
key :type, :object
|
203
|
+
property :problem do
|
204
|
+
key :type, :string
|
205
|
+
end
|
206
|
+
property :params do
|
207
|
+
key :type, :object
|
208
|
+
key :additionalProperties, true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def show
|
216
|
+
respond_with rate: @tax_rate
|
217
|
+
end
|
218
|
+
|
219
|
+
def update
|
220
|
+
@tax_rate.update_attributes!(params[:rate])
|
221
|
+
respond_with rate: @tax_rate
|
222
|
+
end
|
223
|
+
|
224
|
+
def destroy
|
225
|
+
@tax_rate.destroy
|
226
|
+
head :no_content
|
227
|
+
end
|
228
|
+
|
229
|
+
swagger_path '/tax_categories/{tax_category_id}/rates/bulk' do
|
230
|
+
operation :patch do
|
231
|
+
key :summary, 'Bulk Upsert Rates'
|
232
|
+
key :description, 'Creates new rates or updates existing ones in bulk.'
|
233
|
+
key :operationId, 'upsertTaxCategoryRates'
|
234
|
+
key :produces, ['application/json']
|
235
|
+
|
236
|
+
parameter do
|
237
|
+
key :name, :tax_category_id
|
238
|
+
key :in, :path
|
239
|
+
key :description, 'ID of tax category'
|
240
|
+
key :required, true
|
241
|
+
key :type, :string
|
242
|
+
end
|
243
|
+
|
244
|
+
parameter do
|
245
|
+
key :name, :body
|
246
|
+
key :in, :body
|
247
|
+
key :description, 'Array of rates to upsert'
|
248
|
+
key :required, true
|
249
|
+
schema do
|
250
|
+
key :type, :object
|
251
|
+
property :rates do
|
252
|
+
key :type, :array
|
253
|
+
items do
|
254
|
+
key :'$ref', 'Workarea::Tax::Rate'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
response 204 do
|
261
|
+
key :description, 'Upsert received'
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def bulk
|
267
|
+
data = params[:rates].presence || []
|
268
|
+
data.map!(&:to_h)
|
269
|
+
data.map! { |a| a.merge(category_id: @tax_category.id) }
|
270
|
+
|
271
|
+
@bulk = Api::Admin::BulkUpsert.create!(
|
272
|
+
klass: Tax::Rate,
|
273
|
+
data: data
|
274
|
+
)
|
275
|
+
|
276
|
+
head :no_content
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
private
|
281
|
+
|
282
|
+
def find_tax_category
|
283
|
+
@tax_category = Tax::Category.find(params[:tax_category_id])
|
284
|
+
end
|
285
|
+
|
286
|
+
def find_tax_rate
|
287
|
+
@tax_rate = @tax_category.rates.find(params[:id])
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,296 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Admin
|
4
|
+
class UsersController < Admin::ApplicationController
|
5
|
+
before_action :find_user, except: [:index, :create, :bulk]
|
6
|
+
|
7
|
+
swagger_path '/users' do
|
8
|
+
operation :get do
|
9
|
+
key :summary, 'All Users'
|
10
|
+
key :description, 'Returns all users from the system'
|
11
|
+
key :operationId, 'listUsers'
|
12
|
+
key :produces, ['application/json']
|
13
|
+
|
14
|
+
parameter do
|
15
|
+
key :name, :page
|
16
|
+
key :in, :query
|
17
|
+
key :description, 'Current page'
|
18
|
+
key :required, false
|
19
|
+
key :type, :integer
|
20
|
+
key :default, 1
|
21
|
+
end
|
22
|
+
parameter do
|
23
|
+
key :name, :sort_by
|
24
|
+
key :in, :query
|
25
|
+
key :description, 'Field on which to sort (see responses for possible values)'
|
26
|
+
key :required, false
|
27
|
+
key :type, :string
|
28
|
+
key :default, 'created_at'
|
29
|
+
end
|
30
|
+
parameter do
|
31
|
+
key :name, :sort_direction
|
32
|
+
key :in, :query
|
33
|
+
key :description, 'Direction for sort by'
|
34
|
+
key :type, :string
|
35
|
+
key :enum, %w(asc desc)
|
36
|
+
key :default, 'desc'
|
37
|
+
end
|
38
|
+
|
39
|
+
response 200 do
|
40
|
+
key :description, 'User'
|
41
|
+
schema do
|
42
|
+
key :type, :object
|
43
|
+
property :user do
|
44
|
+
key :type, :array
|
45
|
+
items do
|
46
|
+
key :'$ref', 'Workarea::User'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
operation :post do
|
54
|
+
key :summary, 'Create User'
|
55
|
+
key :description, 'Creates a new user.'
|
56
|
+
key :operationId, 'addUser'
|
57
|
+
key :produces, ['application/json']
|
58
|
+
|
59
|
+
parameter do
|
60
|
+
key :name, :body
|
61
|
+
key :in, :body
|
62
|
+
key :description, 'User to add'
|
63
|
+
key :required, true
|
64
|
+
schema do
|
65
|
+
key :type, :object
|
66
|
+
property :user do
|
67
|
+
key :'$ref', 'Workarea::User'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
response 201 do
|
73
|
+
key :description, 'User created'
|
74
|
+
schema do
|
75
|
+
key :type, :object
|
76
|
+
property :user do
|
77
|
+
key :'$ref', 'Workarea::User'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
response 422 do
|
83
|
+
key :description, 'Validation failure'
|
84
|
+
schema do
|
85
|
+
key :type, :object
|
86
|
+
property :problem do
|
87
|
+
key :type, :string
|
88
|
+
end
|
89
|
+
property :document do
|
90
|
+
key :'$ref', 'Workarea::User'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def index
|
99
|
+
@users = User
|
100
|
+
.all
|
101
|
+
.order_by(sort_field => sort_direction)
|
102
|
+
.page(params[:page])
|
103
|
+
|
104
|
+
respond_with users: @users.to_a.map { |u| api_attributes_for(u) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def create
|
108
|
+
@user = User.create!(params[:user])
|
109
|
+
respond_with(
|
110
|
+
{ user: api_attributes_for(@user) },
|
111
|
+
{ status: :created,
|
112
|
+
location: user_path(@user) }
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
swagger_path '/users/{id}' do
|
117
|
+
operation :get do
|
118
|
+
key :summary, 'Show User by ID'
|
119
|
+
key :description, 'Returns a user by ID'
|
120
|
+
key :operationId, 'showUser'
|
121
|
+
key :produces, ['application/json']
|
122
|
+
|
123
|
+
parameter do
|
124
|
+
key :name, :id
|
125
|
+
key :in, :path
|
126
|
+
key :description, 'user ID'
|
127
|
+
key :required, true
|
128
|
+
key :type, :string
|
129
|
+
end
|
130
|
+
|
131
|
+
response 200 do
|
132
|
+
key :description, 'User Details'
|
133
|
+
schema do
|
134
|
+
key :type, :object
|
135
|
+
property :user do
|
136
|
+
key :'$ref', 'Workarea::User'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
operation :patch do
|
143
|
+
key :summary, 'Update User'
|
144
|
+
key :description, 'Updates attributes on user'
|
145
|
+
key :operationId, 'updateUser'
|
146
|
+
|
147
|
+
parameter do
|
148
|
+
key :name, :id
|
149
|
+
key :in, :path
|
150
|
+
key :description, 'ID of user to update'
|
151
|
+
key :required, true
|
152
|
+
key :type, :string
|
153
|
+
end
|
154
|
+
|
155
|
+
parameter do
|
156
|
+
key :name, :body
|
157
|
+
key :in, :body
|
158
|
+
key :description, 'New user attributes'
|
159
|
+
key :required, true
|
160
|
+
schema do
|
161
|
+
key :type, :object
|
162
|
+
property :user do
|
163
|
+
key :'$ref', 'Workarea::User'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
response 204 do
|
169
|
+
key :description, 'User updated successfully'
|
170
|
+
end
|
171
|
+
|
172
|
+
response 422 do
|
173
|
+
key :description, 'Validation failure'
|
174
|
+
schema do
|
175
|
+
key :type, :object
|
176
|
+
property :problem do
|
177
|
+
key :type, :string
|
178
|
+
end
|
179
|
+
property :document do
|
180
|
+
key :'$ref', 'Workarea::User'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
response 404 do
|
186
|
+
key :description, 'User not found'
|
187
|
+
schema do
|
188
|
+
key :type, :object
|
189
|
+
property :problem do
|
190
|
+
key :type, :string
|
191
|
+
end
|
192
|
+
property :params do
|
193
|
+
key :type, :object
|
194
|
+
key :additionalProperties, true
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
operation :delete do
|
201
|
+
key :summary, 'Remove a User'
|
202
|
+
key :description, 'Remove a User'
|
203
|
+
key :operationId, 'removeUser'
|
204
|
+
|
205
|
+
parameter do
|
206
|
+
key :name, :id
|
207
|
+
key :in, :path
|
208
|
+
key :description, 'ID of user to remove'
|
209
|
+
key :required, true
|
210
|
+
key :type, :string
|
211
|
+
end
|
212
|
+
|
213
|
+
response 204 do
|
214
|
+
key :description, 'User removed successfully'
|
215
|
+
end
|
216
|
+
|
217
|
+
response 404 do
|
218
|
+
key :description, 'User not found'
|
219
|
+
schema do
|
220
|
+
key :type, :object
|
221
|
+
property :problem do
|
222
|
+
key :type, :string
|
223
|
+
end
|
224
|
+
property :params do
|
225
|
+
key :type, :object
|
226
|
+
key :additionalProperties, true
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def show
|
234
|
+
respond_with user: api_attributes_for(@user)
|
235
|
+
end
|
236
|
+
|
237
|
+
def update
|
238
|
+
@user.update_attributes!(params[:user])
|
239
|
+
respond_with user: api_attributes_for(@user)
|
240
|
+
end
|
241
|
+
|
242
|
+
def destroy
|
243
|
+
@user.destroy
|
244
|
+
head :no_content
|
245
|
+
end
|
246
|
+
|
247
|
+
swagger_path '/users/bulk' do
|
248
|
+
operation :patch do
|
249
|
+
key :summary, 'Bulk Upsert Users'
|
250
|
+
key :description, 'Creates new users or updates existing ones in bulk.'
|
251
|
+
key :operationId, 'upsertUser'
|
252
|
+
key :produces, ['application/json']
|
253
|
+
|
254
|
+
parameter do
|
255
|
+
key :name, :body
|
256
|
+
key :in, :body
|
257
|
+
key :description, 'Array of users to upsert'
|
258
|
+
key :required, true
|
259
|
+
schema do
|
260
|
+
key :type, :object
|
261
|
+
property :users do
|
262
|
+
items do
|
263
|
+
key :'$ref', 'Workarea::User'
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
response 204 do
|
270
|
+
key :description, 'Upsert received'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def bulk
|
276
|
+
@bulk = Api::Admin::BulkUpsert.create!(
|
277
|
+
klass: User,
|
278
|
+
data: params[:users].map(&:to_h)
|
279
|
+
)
|
280
|
+
|
281
|
+
head :no_content
|
282
|
+
end
|
283
|
+
|
284
|
+
private
|
285
|
+
|
286
|
+
def find_user
|
287
|
+
@user = User.find(params[:id])
|
288
|
+
end
|
289
|
+
|
290
|
+
def api_attributes_for(user)
|
291
|
+
user.as_json.except('password_digest', 'super_admin', 'name')
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|