workarea-api-admin 4.4.6

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