class NotificationsController < ApplicationController
  def index
    render_success :ok, json: notifications.ordered.limit(5)
  end

  def update
    if notification.update(notification_params)
      render_success :ok
    else
      render_error :unprocessable_entity, errors: notification
    end
  end

  private
    def notifications
      current_user.notification_messages
    end

    def notification
      @notification ||= notifications.find_by(id: params[:id])
    end

    def notification_params
      params.permit(:read)
    end
end
