-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
Rewrite API RABL views as Jbuilder
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
inherit_from: ../../../.rubocop.yml | ||
|
||
Style/LambdaCall: | ||
EnforcedStyle: braces |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
json.array! @user_addresses do |user_address| | ||
json.partial!("spree/api/addresses/address", address: user_address.address) | ||
|
||
json.default user_address.default | ||
|
||
# This is a bit of a hack. | ||
# This attribute is only shown on the update action | ||
if @address | ||
json.update_target @address == user_address.address | ||
end | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
json.cache! address do | ||
json.(address, *address_attributes) | ||
json.country do | ||
if address.country | ||
json.(address.country, *country_attributes) | ||
else | ||
json.nil! | ||
end | ||
end | ||
json.state do | ||
if address.state | ||
json.(address.state, *state_attributes) | ||
else | ||
json.nil! | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial!("spree/api/addresses/address", address: @address) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.cache! [I18n.locale, adjustment] do | ||
json.(adjustment, *adjustment_attributes) | ||
json.display_amount(adjustment.display_amount.to_s) | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.symbol(::Money.new(1, Spree::Config[:currency]).symbol) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.default_country_id(Spree::Country.default.id) | ||
json.default_country_iso(Spree::Config[:default_country_iso]) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.countries(@countries) { |country| json.(country, *country_attributes) } | ||
json.count(@countries.count) | ||
json.current_page(@countries.current_page) | ||
json.pages(@countries.total_pages) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.(@country, *country_attributes) | ||
json.states(@country.states) do |state| | ||
json.(state, :id, :name, :abbr, :country_id) | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
json.cache! [I18n.locale, credit_card] do | ||
json.(credit_card, *creditcard_attributes) | ||
json.address do | ||
if credit_card.address | ||
json.partial!("spree/api/addresses/address", address: credit_card.address) | ||
else | ||
json.nil! | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
json.credit_cards(@credit_cards) do |credit_card| | ||
json.partial!("spree/api/credit_cards/credit_card", credit_card: credit_card) | ||
end | ||
json.count(@credit_cards.count) | ||
json.current_page(@credit_cards.current_page) | ||
json.pages(@credit_cards.total_pages) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial!("spree/api/credit_cards/credit_card", credit_card: @credit_card) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error I18n.t(:delete_restriction_error, scope: "spree.api") |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(I18n.t(:gateway_error, scope: "spree.api", text: @error)) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(I18n.t(:invalid_api_key, key: api_key, scope: "spree.api")) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.error(I18n.t(:invalid_resource, scope: "spree.api")) | ||
json.errors(@resource.errors.to_hash) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(I18n.t(:must_specify_api_key, scope: "spree.api")) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(I18n.t(:resource_not_found, scope: "spree.api")) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(I18n.t(:unauthorized, scope: "spree.api")) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(Spree.t(:item_not_in_stock_transfer)) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
json.(image, *image_attributes) | ||
json.(image, :viewable_type, :viewable_id) | ||
Spree::Image.attachment_definitions[:attachment][:styles].each do |k, _v| | ||
json.set! "#{k}_url", image.attachment.url(k) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.images(@images) do |image| | ||
json.partial!("spree/api/images/image", image: image) | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial!("spree/api/images/image", image: @image) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.(@inventory_unit, *inventory_unit_attributes) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
json.cache! [I18n.locale, line_item] do | ||
json.(line_item, *line_item_attributes) | ||
json.single_display_amount(line_item.single_display_amount.to_s) | ||
json.display_amount(line_item.display_amount.to_s) | ||
json.total(line_item.total) | ||
json.variant do | ||
json.partial!("spree/api/variants/small", variant: line_item.variant) | ||
json.(line_item.variant, :product_id) | ||
json.images(line_item.variant.images) do |image| | ||
json.partial!("spree/api/images/image", image: image) | ||
end | ||
end | ||
json.adjustments(line_item.adjustments) do |adjustment| | ||
json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.attributes(([*line_item_attributes] - [:id])) | ||
json.required_attributes([:variant_id, :quantity]) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial!("spree/api/line_items/line_item", line_item: @line_item) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
json.(option_type, *option_type_attributes) | ||
json.option_values(option_type.option_values) do |option_value| | ||
json.(option_value, *option_value_attributes) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.array! @option_types do |option_type| | ||
json.partial!("spree/api/option_types/option_type", option_type: option_type) | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial!("spree/api/option_types/option_type", option_type: @option_type) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.(option_value, *option_value_attributes) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.array! @option_values do |option_value| | ||
json.partial!("spree/api/option_values/option_value", option_value: option_value) | ||
end |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial!("spree/api/option_values/option_value", option_value: @option_value) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
json.partial!("spree/api/orders/order", order: order) | ||
json.payment_methods(order.available_payment_methods) do |payment_method| | ||
json.(payment_method, :id, :name, :partial_name) | ||
json.method_type payment_method.partial_name | ||
end | ||
json.bill_address do | ||
if order.billing_address | ||
json.partial!("spree/api/addresses/address", address: order.billing_address) | ||
else | ||
json.nil! | ||
end | ||
end | ||
json.ship_address do | ||
if order.shipping_address | ||
json.partial!("spree/api/addresses/address", address: order.shipping_address) | ||
else | ||
json.nil! | ||
end | ||
end | ||
json.line_items(order.line_items) do |line_item| | ||
json.partial!("spree/api/line_items/line_item", line_item: line_item) | ||
end | ||
json.payments(order.payments) do |payment| | ||
json.(payment, *payment_attributes) | ||
json.payment_method { json.(payment.payment_method, :id, :name) } | ||
json.source do | ||
if payment.source | ||
json.(payment.source, *payment_source_attributes) | ||
|
||
if @current_user_roles.include?("admin") | ||
json.(payment.source, :gateway_customer_profile_id, :gateway_payment_profile_id) | ||
end | ||
else | ||
json.nil! | ||
end | ||
end | ||
end | ||
json.shipments(order.shipments) do |shipment| | ||
json.partial!("spree/api/shipments/small", shipment: shipment) | ||
end | ||
json.adjustments(order.adjustments) do |adjustment| | ||
json.partial!("spree/api/adjustments/adjustment", adjustment: adjustment) | ||
end | ||
json.permissions do | ||
json.can_update current_ability.can?(:update, order) | ||
end | ||
json.credit_cards(order.valid_credit_cards) do |credit_card| | ||
json.partial!("spree/api/credit_cards/credit_card", credit_card: credit_card) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
json.cache! [I18n.locale, order] do | ||
json.(order, *order_attributes) | ||
json.display_item_total(order.display_item_total.to_s) | ||
json.total_quantity(order.line_items.sum(:quantity)) | ||
json.display_total(order.display_total.to_s) | ||
json.display_ship_total(order.display_ship_total) | ||
json.display_tax_total(order.display_tax_total) | ||
json.token(order.guest_token) | ||
json.checkout_steps(order.checkout_steps) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(@coupon_message) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.error(I18n.t(:could_not_transition, scope: "spree.api.order")) | ||
json.errors(@order.errors.to_hash) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.errors(expected_total: [I18n.t(:expected_total_mismatch, scope: "spree.api.order")]) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
json.orders(@orders) do |order| | ||
json.partial!("spree/api/orders/order", order: order) | ||
end | ||
json.count(@orders.count) | ||
json.current_page(@orders.current_page) | ||
json.pages(@orders.total_pages) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.errors([I18n.t(:invalid_shipping_method, scope: "spree.api.order")]) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
json.orders(@orders) do |order| | ||
json.partial!("spree/api/orders/big", order: order) | ||
end | ||
json.count(@orders.count) | ||
json.current_page(@orders.current_page) | ||
json.pages(@orders.total_pages) |