class UsersController < ApplicationController
  before_action :authenticate_user!, except: [:create]
  def create
    user = User.new(user_params)
    if user.save
      session[:user_id] = user.id
      redirect_to user_path(user.id)
    else
      redirect_to new_user_path
    end
  end

  def show
    @user = User.find(params[:id])
    @reviews = Review.where(reviewee_id: @user.id)
    @reviewer = false
  end

  def current
    # look into eager loading
    @user = current_user
    @parcels = @user.parcels.where(delivered: false)
    @trips = @user.trips.where(completed: false)
    @notifications = @user.mailbox.notifications
    @conversations = @user.mailbox.inbox
    @num_messages = @conversations.count
    render 'current', layout: false
  end

  def history
    @user = current_user
    @trips = @user.trips.where(completed: true)
    @parcels = @user.parcels.where(delivered: true)
    render 'history'
  end

  private

  def user_params
    params.require(:user).permit(:username, :password)
  end

end
class UsersController < ApplicationController
  before_action :authenticate_user!, except: [:create]
  def create
    user = User.new(user_params)
    if user.save
      session[:user_id] = user.id
      redirect_to user_path(user.id)
    else
      redirect_to new_user_path
    end
  end

  def show
    @user = User.find(params[:id])
    @reviews = Review.where(reviewee_id: @user.id)
    @reviewer = false
  end

  def current
    # look into eager loading
    @user = current_user
    @parcels = @user.parcels.where(delivered: false).order(updated_at: :desc)
    @trips = @user.trips.where(completed: false).order(updated_at: :desc)
    @notifications = @user.mailbox.notifications
    @conversations = @user.mailbox.inbox
    @num_messages = @conversations.count
    render 'current', layout: false
  end

  def history
    @user = current_user
    @trips = @user.trips.where(completed: true)
    @parcels = @user.parcels.where(delivered: true)
    render 'history'
  end

  private

  def user_params
    params.require(:user).permit(:username, :password)
  end

end
Add date sort to parcels and trips in users controller
Add date sort to parcels and trips in users controller
