class CheckOutsController < ApplicationController
  before_action :authenticate_user!

  def borrow
    @book = Book.find(params[:id])
    current_user.books << @book

    respond_to do |format|
      format.js
    end
  end

  def returns
    @book = current_user.books.find(params[:id])
    user_book = UsersBook.find_by(book_id: @book.id, user_id: current_user.id)
    user_book.update(status: :returned, returned_at: Time.zone.now)
    redirect_to  dashboard_index_path
  end
end
