Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # frozen_string_literal: true
- module V1
- module Shops
- module MobileApi
- class GetDatasController < V1::ShopApiController
- respond_to :json
- before_action :set_company, :set_shop
- around_action :company_shard
- before_action :read_products, only: :index
- def index
- data_type = params[:data_type]
- updated_at = params[:updated_at].blank? ? nil : params[:updated_at].to_datetime
- case data_type
- when "categories"
- @datas = @current_shop.categories.order("created_at desc")
- when "tags"
- @datas = @current_shop.tags
- when "taggings"
- @datas = @current_shop.taggings
- when "option_types"
- @datas = @current_shop.option_types
- when "option_type_values"
- @datas = @current_shop.option_type_values
- when "option_type_values"
- @datas = @current_shop.option_type_values
- when "prices"
- @datas = current_user.prices.where(shop_id: @current_shop.id)
- when "products"
- @datas = @current_shop.products
- when "product_barcodes"
- @datas = @current_shop.product_barcodes
- when "product_option_types"
- @datas = @current_shop.product_option_types
- when "product_option_type_values"
- @datas = @current_shop.product_option_type_values
- when "product_packs"
- @datas = @current_shop.product_packs
- when "product_vendor_codes"
- @datas = @current_shop.product_vendor_codes
- when "variants"
- @datas = @current_shop.variants
- when "variant_option_type_values"
- @datas = @current_shop.variant_option_type_values
- else
- @datas = []
- end
- @datas = @datas.where(["updated_at >= ?", updated_at]) unless updated_at.blank?
- @datas = @datas.order("updated_at asc") unless updated_at.blank?
- @datas = @datas.page(params[:page] || 1)
- .per(params[:per_page] || 100)
- render json: @datas,
- each_serializer: MobileApiSerializer,
- root: "data",
- meta: {
- current_page: @datas.current_page,
- total_pages: @datas.total_pages,
- limit_value: @datas.limit_value,
- total_items: @datas.total_count,
- last_update_time: Time.zone.now
- }
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement