Class: Stay::Api::V1::PropertyTypesController

Inherits:
BaseApiController
  • Object
show all
Defined in:
app/controllers/stay/api/v1/property_types_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/stay/api/v1/property_types_controller.rb', line 4

def index
  property_types = Stay::PropertyType.all

  if property_types.exists?
    serialized_data = ActiveModelSerializers::SerializableResource.new(property_types, each_serializer: PropertyTypeSerializer)

    render json: {
      data: serialized_data,
      message: "Property types found",
      success: true
    }, status: :ok
  else
    render json: {
      data: [],
      message: "No property types found",
      success: false
    }, status: :not_found
  end
rescue => e
  render json: {
    error: "Failed to fetch property types",
    message: e.message,
    success: false
  }, status: :internal_server_error
end

#showObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/stay/api/v1/property_types_controller.rb', line 30

def show
  type = Stay::PropertyType.find_by(id: params[:id])

  if type.present?
    render json: {
      data: PropertyTypeSerializer.new(type),
      message: "Property type found",
      success: true
    }, status: :ok
  else
    render json: {
      data: {},
      message: "Property type not found",
      success: false
    }, status: :not_found
  end
rescue => e
  render json: {
    error: "Failed to fetch property type",
    message: e.message,
    success: false
  }, status: :internal_server_error
end