2024-07-21 10:45:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-08-25 14:19:02 -04:00
|
|
|
class Api::V1::PointsController < ApiController
|
2024-07-31 13:35:35 -04:00
|
|
|
def index
|
|
|
|
|
start_at = params[:start_at]&.to_datetime&.to_i
|
|
|
|
|
end_at = params[:end_at]&.to_datetime&.to_i || Time.zone.now.to_i
|
|
|
|
|
|
2024-08-21 13:20:04 -04:00
|
|
|
points = current_api_user
|
|
|
|
|
.tracked_points
|
|
|
|
|
.where(timestamp: start_at..end_at)
|
|
|
|
|
.order(:timestamp)
|
|
|
|
|
.page(params[:page])
|
|
|
|
|
.per(params[:per_page] || 100)
|
2024-07-31 13:35:35 -04:00
|
|
|
|
2024-09-14 16:52:25 -04:00
|
|
|
response.set_header('X-Current-Page', points.current_page)
|
|
|
|
|
response.set_header('X-Total-Pages', points.total_pages)
|
|
|
|
|
|
2024-07-31 13:35:35 -04:00
|
|
|
render json: points
|
|
|
|
|
end
|
2024-07-21 10:45:29 -04:00
|
|
|
|
|
|
|
|
def destroy
|
2024-07-31 13:35:35 -04:00
|
|
|
point = current_api_user.tracked_points.find(params[:id])
|
2024-07-21 10:45:29 -04:00
|
|
|
point.destroy
|
|
|
|
|
|
|
|
|
|
render json: { message: 'Point deleted successfully' }
|
|
|
|
|
end
|
|
|
|
|
end
|