-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oliver Azevedo Barnes
committed
Feb 19, 2016
1 parent
e268081
commit ed56a5e
Showing
47 changed files
with
870 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ | |
|
||
# vagrant instance folder | ||
.vagrant | ||
|
||
Procfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class V2::EventInvitationsController < ApplicationController | ||
def new | ||
@event_invitation = V2::EventInvitation.new | ||
end | ||
|
||
def create | ||
@event_invitation = V2::EventInvitation.new(event_invitation_params) | ||
|
||
if @event_invitation.save | ||
send_notifications(@event_invitation) | ||
flash[:notice] = 'Person was successfully invited.' | ||
else | ||
flash[:error] = 'There were problems with some of the fields.' | ||
end | ||
|
||
render :new | ||
end | ||
|
||
private | ||
|
||
def send_notifications(event_invitation) | ||
EventInvitationMailer.invite( | ||
email_address: event_invitation.email_address, | ||
event: event_invitation.event | ||
).deliver_later | ||
end | ||
|
||
def event_invitation_params | ||
params.require(:v2_event_invitation). | ||
permit( | ||
:email_address, | ||
:description, | ||
:slot_length, | ||
:date, | ||
:start_time, | ||
:end_time | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class V2::ReservationsController < ApplicationController | ||
skip_before_action :authenticate_user! | ||
|
||
def new | ||
event = V2::Event.find(event_params[:event_id]) | ||
@time_slots = event.time_slots | ||
@person = Person.find_by(email_address: person_params[:email_address]) | ||
@reservation = V2::Reservation.new(time_slot: V2::TimeSlot.new) | ||
end | ||
|
||
def create | ||
@reservation = V2::Reservation.new(reservation_params) | ||
|
||
if @reservation.save | ||
flash[:notice] = "An interview has been booked for #{@reservation.time_slot.to_weekday_and_time}" | ||
|
||
send_notifications(@reservation) | ||
else | ||
flash[:error] = "No time slot was selected, couldn't create the reservation" | ||
end | ||
|
||
@time_slots = [] | ||
@person = @reservation.person | ||
|
||
render :new | ||
end | ||
|
||
private | ||
|
||
def send_notifications(reservation) | ||
ReservationNotifier.notify( | ||
email_address: reservation.person.email_address, | ||
reservation: reservation | ||
).deliver_later | ||
end | ||
|
||
def event_params | ||
params.permit(:event_id) | ||
end | ||
|
||
def reservation_params | ||
params.require(:v2_reservation).permit(:person_id, :time_slot_id) | ||
end | ||
|
||
def person_params | ||
params.permit(:email_address, :person_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module ApplicationHelper | ||
def simple_time_select_options | ||
minutes = %w( 00 15 30 45 ) | ||
hours = (0..23).to_a.map { |h| format('%.2d', h) } | ||
options = hours.map do |h| | ||
minutes.map { |m| "#{h}:#{m}" } | ||
end.flatten | ||
options_for_select(options) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: '[email protected]' | ||
layout 'mailer' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class EventInvitationMailer < ApplicationMailer | ||
def invite(email_address:, event:) | ||
admin_email = '[email protected]' | ||
@email_address = email_address | ||
@event = event | ||
mail(to: email_address, | ||
bcc: admin_email, | ||
subject: 'Phone call interview') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ReservationNotifier < ApplicationMailer | ||
def notify(email_address:, reservation:) | ||
admin_email = '[email protected]' | ||
@email_address = email_address | ||
@reservation = reservation | ||
mail(to: email_address, | ||
bcc: admin_email, | ||
subject: 'Interview scheduled') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class V2::Event < ActiveRecord::Base | ||
has_many :time_slots, class_name: '::V2::TimeSlot' | ||
|
||
validates :description, presence: true | ||
validates :time_slots, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class V2::EventInvitation | ||
include ActiveModel::Model | ||
|
||
attr_accessor :email_address, :description, :slot_length, :date, :start_time, :end_time | ||
attr_reader :event | ||
|
||
validates :email_address, :description, :slot_length, :date, :start_time, :end_time, presence: true | ||
|
||
def save | ||
if valid? | ||
@event = V2::Event.new( | ||
description: description, | ||
time_slots: time_slots | ||
) | ||
|
||
@event.save! | ||
else | ||
false | ||
end | ||
end | ||
|
||
private | ||
|
||
def time_slots | ||
V2::TimeWindow.new( | ||
slot_length: slot_length, | ||
date: date, | ||
start_time: start_time, | ||
end_time: end_time | ||
).slots | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class V2::Reservation < ActiveRecord::Base | ||
self.table_name = 'v2_reservations' | ||
|
||
belongs_to :time_slot, class_name: '::V2::TimeSlot' | ||
belongs_to :person | ||
|
||
validates :person, presence: true | ||
validates :time_slot, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class V2::TimeSlot < ActiveRecord::Base | ||
self.table_name = 'v2_time_slots' | ||
|
||
belongs_to :event, class_name: '::V2::Event' | ||
|
||
validates :start_time, presence: true | ||
validates :end_time, presence: true | ||
|
||
def to_time_and_weekday | ||
"#{start_time.strftime('%H:%M')} - #{end_time.strftime('%H:%M')} #{start_time.strftime('%A %d')}" | ||
end | ||
|
||
def to_weekday_and_time | ||
"#{start_time.strftime('%A %d')} #{start_time.strftime('%H:%M')} - #{end_time.strftime('%H:%M')}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class V2::TimeWindow | ||
|
||
def initialize(date:, start_time:, end_time:, slot_length:) | ||
@date = date | ||
@start_time = start_time | ||
@end_time = end_time | ||
@slot_length = slot_length | ||
@slots = [] | ||
end | ||
|
||
def slots | ||
slot_start = start_time | ||
slot_end = slot_start + slot_length | ||
|
||
while slot_end <= end_time | ||
@slots << ::V2::TimeSlot.new(start_time: slot_start, end_time: slot_end) | ||
|
||
slot_start = slot_end | ||
slot_end += slot_length | ||
end | ||
|
||
@slots | ||
end | ||
|
||
private | ||
|
||
def date | ||
Date.strptime(@date, '%m/%d/%Y') | ||
end | ||
|
||
def start_time | ||
Time.zone.parse("#{date} #{@start_time}") | ||
end | ||
|
||
def end_time | ||
Time.zone.parse("#{date} #{@end_time}") | ||
end | ||
|
||
def slot_length | ||
@slot_length.delete(' mins').to_i.minutes | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p>Hello, you've been invited to a phone interview</p> | ||
|
||
<p><%= link_to 'Please click to setup a time for your interview', | ||
new_v2_reservation_url( | ||
email_address: @email_address, | ||
event_id: @event.id | ||
) %></p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Hello, you've been invited to a phone interview | ||
|
||
<%= link_to 'Please click to setup a time for your interview', | ||
new_v2_reservation_url( | ||
email_address: @email_address, | ||
event_id: @event.id | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= yield %> |
Oops, something went wrong.