Basic functionality working

This commit is contained in:
2015-09-08 13:31:20 +02:00
parent 1caa488524
commit d87befd00f
6 changed files with 26 additions and 13 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ module Users
end
def show
@list ||= List.find(params[:id])
@list ||= List.find(params[:id]) if params[:id]
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users])
end
+10 -4
View File
@@ -9,8 +9,14 @@ module Users
def supplier
table = Table.find(params[:id])
supplier = table.supplier
supplier.product_categories.include_relations(:products)
render json: JSONAPI::Serializer.serialize(supplier, serializer: Users::SupplierSerializer, include: %w[product_categories product_categories.products product_categories.supplier])
supplier.product_categories.include_relations(products: :product_variants)
render json: JSONAPI::Serializer.serialize(supplier, serializer: Users::SupplierSerializer, include: %w[
product_categories
product_categories.products
product_categories.supplier
product_categories.products.product_variants
product_categories.products.product_variants.product
])
end
# POST /tables/:id/needs_help.json
@@ -39,8 +45,8 @@ module Users
# - move_table
# into separate class and implement security in a non stupid way as it is now
def status_info
render json: json_alert('messages.table_not_found') and return unless params[:table_id].present?
table = Table.find(params[:table_id])
render json: json_alert('messages.table_not_found') and return unless params[:id].present?
table = Table.find(params[:id])
res = {}
res[:occupied] = table.occupied?
res[:reserved] = table.reserved?
+11 -7
View File
@@ -1,14 +1,18 @@
class Users::ProductSerializer
include Qwaiter::UserBaseSerializer
attributes :name, :price, :description, :image, :code, :position, :visible, :active, :product_category_id
has_many :product_variants, serializer: Users::ProductVariantSerializer
def image
HOST = Rails.application.config.action_controller.asset_host.to_s
attributes :name, :price, :description, :code, :position, :visible, :active
attribute :image do
if object.image.present?
{small: object.image.url(:small)}
{
thumb: File.join(HOST, object.image.url(:thumb).to_s),
small: File.join(HOST, object.image.url(:small).to_s)
}
else
nil
dummy = File.join(HOST, object.image.url.to_s)
{thumb: dummy, small: dummy}
end
end
has_many :product_variants, serializer: Users::ProductVariantSerializer
end
@@ -1,4 +1,6 @@
class Users::ProductVariantSerializer
include Qwaiter::UserBaseSerializer
attributes :name
has_one :product, serializer: Users::ProductSerializer
end