-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcheckins_controller.rb
More file actions
37 lines (28 loc) · 919 Bytes
/
checkins_controller.rb
File metadata and controls
37 lines (28 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Api::V1::CheckinsController < ApplicationController
def index
date = params[:date]
if date.blank? && params.require(:page)
render json: current_user.checkins.where(:note.nin => [nil, '']).order_by(date: :desc).page(params[:page]).per(10)
else
render json: current_user.checkins.where(date: Date.parse(date))
end
end
def show
render json: Checkin.find(id)
end
def create
date = params.require(:checkin).require(:date)
checkin = Checkin::Creator.new(current_user.id, Date.parse(date)).create!
SendDataToSendy.perform_async(name: current_user.screen_name,
email: current_user.email,
last_checkin_at: checkin.date)
render json: checkin
end
def update
render json: Checkin::Updater.new(current_user, params).update!
end
private
def id
params.require(:id)
end
end