2024-07-24 14:25:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class VisitsController < ApplicationController
|
2024-07-27 09:05:08 -04:00
|
|
|
before_action :authenticate_user!
|
2024-07-27 06:35:47 -04:00
|
|
|
before_action :set_visit, only: %i[update]
|
2024-07-24 14:25:16 -04:00
|
|
|
|
|
|
|
|
def index
|
2024-07-31 13:35:35 -04:00
|
|
|
order_by = params[:order_by] || 'asc'
|
2024-08-05 15:23:08 -04:00
|
|
|
status = params[:status] || 'confirmed'
|
2024-07-31 13:35:35 -04:00
|
|
|
|
2024-07-24 14:25:16 -04:00
|
|
|
visits = current_user
|
|
|
|
|
.visits
|
2024-08-05 15:23:08 -04:00
|
|
|
.where(status:)
|
2025-07-26 19:08:29 -04:00
|
|
|
.includes(%i[suggested_places area points place])
|
2024-07-31 13:35:35 -04:00
|
|
|
.order(started_at: order_by)
|
2024-07-24 14:25:16 -04:00
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
@suggested_visits_count = current_user.visits.suggested.count
|
2024-12-11 08:21:44 -05:00
|
|
|
@visits = visits.page(params[:page]).per(10)
|
2024-07-24 14:25:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
if @visit.update(visit_params)
|
2024-08-13 12:25:48 -04:00
|
|
|
redirect_back(fallback_location: visits_path(status: :suggested))
|
2024-07-24 14:25:16 -04:00
|
|
|
else
|
2025-09-12 15:08:45 -04:00
|
|
|
render :edit, status: :unprocessable_content
|
2024-07-24 14:25:16 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def set_visit
|
|
|
|
|
@visit = current_user.visits.find(params[:id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def visit_params
|
|
|
|
|
params.require(:visit).permit(:name, :started_at, :ended_at, :status)
|
|
|
|
|
end
|
|
|
|
|
end
|