Class: Stay::Api::V1::PropertyCategoriesController
- Inherits:
-
BaseApiController
- Object
- BaseApiController
- Stay::Api::V1::PropertyCategoriesController
- Defined in:
- app/controllers/stay/api/v1/property_categories_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/stay/api/v1/property_categories_controller.rb', line 4 def index categories = Stay::PropertyCategory.all if categories.exists? serialized_data = ActiveModelSerializers::SerializableResource.new(categories, each_serializer: PropertyCategorySerializer) render json: { data: serialized_data, message: "Property categories found", success: true }, status: :ok else render json: { data: [], message: "No property categories found", success: false }, status: :not_found end rescue => e render json: { error: "Failed to fetch property categories", message: e., success: false }, status: :internal_server_error end |
#show ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/stay/api/v1/property_categories_controller.rb', line 29 def show category = Stay::PropertyCategory.find_by(id: params[:id]) if category.present? render json: { data: PropertyCategorySerializer.new(category), message: "Property category found", success: true }, status: :ok else render json: { data: {}, message: "Property category not found", success: false }, status: :not_found end rescue => e render json: { error: "Failed to fetch property category", message: e., success: false }, status: :internal_server_error end |