<file_sep>class HostReviewsController < ApplicationController
  def create
    @reservation =  Reseration.where(
                      id: host_review_params[:reservation_id]
                      room_id: host_review_params[:room_id]
                      user_id: host_review_params[:guest_id]
                    ).first
    if !@reservation.nil?
      @has_reviewed = HostReview.where(
                        reservation_id: @reservation.id
                        guest_id: host_review_params[:guest_id]
                      ).first
      if @has_reviewed.nil?
        @host_review = current_user.host_reviews.create(host_review_params)
        flash[:success] = 'Review created'
      else
        flash[:alert] = "You have already reviwing this reservation "
      end
    else
      flash[:alert] = "Not ound this registration"
     end
     redirect_back(fallback_location: request.referrer)
  end
  def destroy
    @host_review = Review.find(params[:id])
    @host_review.destroy
    redirect_back(fallback_location: request.referrer, notice: "Removed!")
  end

private
  def host_review_params
    params.require(:host_review).permit(:comment, :star, :room_id, :reservation_id, :guest_id)
  end
end
<file_sep>class ReservationsController < ApplicationController
before_action :authenticate_user!

def create
  room = Room.find(params[:room_id])
  if current_user == room.user
    flash[:alert] = "You can not book your own property"
  else
    start_date = Date.parse(reservation_params[:start_date])
    end_date = Date.parse(reservation_params[:end_date])
    days = (end_date - start_date).to_i + 1
    @reservation = current_user.reservations.build(reservation_params)
    @reservation.room = room
    @reservation.price = room.price
    @reservation.total = @reservation.price * days
    @reservation.save

    flash[:notice] = "Boocked Successfully"

  end
  redirect_to room
end
def your_trips
  @trips = current_user.reservations.order(start_date: :asc)
end

def your_reservations
  @rooms = current_user.rooms

end

private
def reservation_params
  params.require(:reservation).permit(:start_date, :end_date)

end
end
