Skip to content

Commit

Permalink
Implement nested car and user for reservations#show
Browse files Browse the repository at this point in the history
  • Loading branch information
Estete9 committed Feb 24, 2024
1 parent ae34026 commit d34d4f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/reservations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
def show
render json: {
status: { code: 200, message: 'Reservation fetched successfully.' },
data: ReservationSerializer.new(@reservation).serializable_hash[:data][:attributes]
data: ReservationWithDetailsSerializer.new(@reservation).serializable_hash[:data][:attributes]
}, status: :ok
end

Expand Down
13 changes: 13 additions & 0 deletions app/serializers/reservation_with_details_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ReservationWithDetailsSerializer
include JSONAPI::Serializer

attributes :id, :date

attribute :user do |reservation|
UserSerializer.new(reservation.user).serializable_hash[:data][:attributes]
end

attribute :car do |reservation|
CarWithDetailsSerializer.new(reservation.car).serializable_hash[:data][:attributes]
end
end

0 comments on commit d34d4f9

Please sign in to comment.