Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Get tomorrow staff #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/controllers/worksessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'net/http'

class WorksessionsController < ApplicationController
before_action :authenticate_user!, except: [:view, :tomorrow_status]
before_action :authenticate_user!, except: [:view, :tomorrow_status, :get_staff_tomorrow]
before_action :set_worksession, :set_user, only: [:show, :edit, :update, :destroy, :sign_up, :cancel]
before_action :set_today
respond_to :json
Expand Down Expand Up @@ -233,6 +233,23 @@ def get_events
end
end

def get_staff_tomorrow
available_tomorrow = Worksession.where("begin_at >= :start_date", {:start_date => (Date.tomorrow.midnight)})
.where("begin_at <= :end_date", {:end_date => (Date.tomorrow.tomorrow.midnight)})
if Rails.env.production?
url = URI.parse('https://worksessions-notifier.pierobotics.org/api/v0/sheets/')
else
url = URI.parse('http://127.0.0.1:5000/api/v0/sheets/')
end
available_tomorrow.all.each do |worksession|
if worksession.bookings.size > 0
date = worksession.begin_at.strftime('%m/%d/%Y')
start_time = worksession.begin_at.strftime('%I:%M %p')
res = Net::HTTP.post_form(url, 'date' => date, 'start-time' => start_time)
end
end
end

private

# We set the scope of worksession we interact with to only those that happened this year
Expand Down
1 change: 1 addition & 0 deletions app/views/worksessions/get_staff_tomorrow.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1> Hello </h1>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# post 'worksessions/view' => 'worksessions#view', as: :views
get '/worksessions/create_2_weeks' => 'worksessions#create_worksessions', as: :create_worksessions
get '/users/reset_password' => 'users#reset_password', as: :reset_password

get '/worksessions/get_staff_tomorrow' => 'worksessions#get_staff_tomorrow', as: :get_staff_tomorrow

resources :users do
resources :worksessions
end
Expand All @@ -28,7 +31,6 @@
post '/worksessions/:id/sign_up' => 'worksessions#sign_up', as: :signup
get '/worksessions/:id/sign_up' => 'worksessions#sign_up', as: :signUp


get '/worksessions/:id/cancel' => 'worksessions#cancel', as: :cancel
get '/worksessions/:worksession_id/:user_id/add_team' => 'worksessions#add_team', as: :add_team

Expand Down