dawarich/app/controllers/api/v1/settings_controller.rb

37 lines
1.1 KiB
Ruby
Raw Normal View History

2024-08-28 14:24:35 -04:00
# frozen_string_literal: true
class Api::V1::SettingsController < ApiController
before_action :authenticate_active_api_user!, only: %i[update]
2024-08-28 14:24:35 -04:00
def index
render json: {
settings: current_api_user.safe_settings,
2024-08-28 14:24:35 -04:00
status: 'success'
}, status: :ok
end
def update
settings_params.each { |key, value| current_api_user.settings[key] = value }
if current_api_user.save
render json: { message: 'Settings updated', settings: current_api_user.settings, status: 'success' },
status: :ok
2024-08-28 14:24:35 -04:00
else
render json: { message: 'Something went wrong', errors: current_api_user.errors.full_messages },
status: :unprocessable_content
2024-08-28 14:24:35 -04:00
end
end
private
def settings_params
params.require(:settings).permit(
:meters_between_routes, :minutes_between_routes, :fog_of_war_meters,
2024-09-15 15:04:13 -04:00
:time_threshold_minutes, :merge_threshold_minutes, :route_opacity,
:preferred_map_layer, :points_rendering_mode, :live_map_enabled,
:immich_url, :immich_api_key, :photoprism_url, :photoprism_api_key,
2025-05-14 15:04:47 -04:00
:speed_colored_routes, :speed_color_scale, :fog_of_war_threshold
2024-08-28 14:24:35 -04:00
)
end
end