-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into api-documentation
- Loading branch information
Showing
5 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Api::V1::ReservationsController < ApplicationController | ||
before_action :authenticate, only: %i[index create show update destroy] | ||
before_action :set_reservation, only: %i[show update destroy] | ||
|
||
def index | ||
current_user = User.find(params[:user_id]) | ||
@reservations = current_user.reservations.order(created_at: :desc).all | ||
if @reservations | ||
render json: { status: { code: 200, message: 'Reservations retrieved successfully.', data: @reservations } }, status: :ok | ||
else | ||
render json: { error: 'Reservations not found.' }, status: :not_found | ||
end | ||
end | ||
|
||
def show | ||
render json: @reservation | ||
end | ||
|
||
def create | ||
current_user = User.find(params[:user_id]) | ||
@reservation = current_user.reservations.new(reservation_params) | ||
if @reservation.save | ||
render json: @reservation, status: :created | ||
else | ||
render json: @reservation.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@reservation.destroy | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def set_reservation | ||
@reservation = Reservation.find(params[:id]) | ||
end | ||
|
||
def reservation_params | ||
params.permit(:location, :date, :car_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters