-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'HER-32-remove-jwt-at-unauthorized-response' of https://…
…github.com/Code-the-Dream-School/herring-team-3 into HER-32-remove-jwt-at-unauthorized-response
- Loading branch information
Showing
116 changed files
with
2,842 additions
and
185 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
/tmp/* | ||
!/log/.keep | ||
!/tmp/.keep | ||
/temp/ | ||
|
||
# Ignore pidfiles, but keep the directory. | ||
/tmp/pids/* | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,41 @@ | ||
class Api::V1::AddressesController < ApplicationController | ||
before_action :set_addressable | ||
|
||
def create | ||
@address = @addressable.addresses.build(address_params) | ||
if @address.save | ||
render json: @address, status: :created | ||
else | ||
render json: @address.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
@address = @addressable.addresses.find(params[:id]) | ||
if @address.update(address_params) | ||
render json: @address, status: :ok | ||
else | ||
render json: @address.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@address = @addressable.addresses.find(params[:id]) | ||
@address.destroy | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def set_addressable | ||
@addressable = if params[:user_id] | ||
User.find(params[:user_id]) | ||
elsif params[:organization_id] | ||
Organization.find(params[:organization_id]) | ||
end | ||
end | ||
|
||
def address_params | ||
params.require(:address).permit(:street_address, :city, :state, :postal_code, :save_to_user) | ||
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,96 @@ | ||
class Api::V1::AvailabilitiesController < ApplicationController | ||
before_action :set_availability, only: [ :show, :update, :destroy ] | ||
|
||
def index | ||
# This shows the availabilities including recurring availabilities for the month | ||
# and year sent in the request from the frontend or a default month and year. | ||
|
||
viewing_month = params[:month].to_i || Date.today.month | ||
viewing_year = params[:year].to_i || Date.today.year | ||
start_date = Date.new(viewing_year, viewing_month, 1) | ||
end_date = start_date.end_of_month | ||
|
||
puts "Received Year: #{params[:year]}, Month: #{params[:month]}" # Debugging the incoming params | ||
|
||
# Debugging the parsed values of year and month | ||
puts "Parsed Year: #{viewing_year}, Month: #{viewing_month}" | ||
|
||
# Handling cases where the month or year might be invalid (e.g., 0 or nil) | ||
if viewing_month == 0 || viewing_year == 0 | ||
puts "Invalid date parameters, setting to current date." # Debugging invalid date handling | ||
viewing_month = Date.today.month | ||
viewing_year = Date.today.year | ||
end | ||
|
||
# Debugging the final year and month values used for date calculation | ||
puts "Final Year: #{viewing_year}, Month: #{viewing_month}" | ||
|
||
begin | ||
# Create start and end date for the requested month and year | ||
start_date = DateTime.new(viewing_year, viewing_month, 1).beginning_of_day | ||
end_date = start_date.end_of_month.end_of_day | ||
puts "Start Date: #{start_date}, End Date: #{end_date}" # Debugging start and end dates | ||
rescue => e | ||
# Catch any errors related to invalid date creation and log them | ||
puts "Error creating start or end date: #{e.message}" | ||
end | ||
|
||
# Trigger the job to create next month's availabilities if needed | ||
trigger_recurring_availability_job(viewing_month, viewing_year) | ||
|
||
# Fetch the availabilities within the specified date range | ||
@availabilities = Availability.where(start_time: start_date..end_date) | ||
render json: @availabilities | ||
end | ||
|
||
|
||
def show | ||
render json: @availability | ||
end | ||
|
||
def create | ||
@availability = Availability.new(availability_params) | ||
|
||
if @availability.save | ||
render json: @availability, status: :created | ||
else | ||
render json: { errors: @availability.errors.full_messages }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @availability.update(availability_params) | ||
render json: @availability, status: :ok | ||
else | ||
puts @availability.errors.full_messages # Add this line to log validation errors | ||
render json: { errors: @availability.errors.full_messages }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@availability.destroy | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def set_availability | ||
@availability = Availability.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
render json: { error: "Availability not found" }, status: :not_found | ||
end | ||
|
||
def availability_params | ||
params.require(:availability).permit(:start_time, :end_time, :speaker_id, :recurring_availability_id) | ||
end | ||
|
||
def trigger_recurring_availability_job(viewing_month, viewing_year) | ||
# Calculate the next month and year based on the viewing month and year | ||
next_month_date = Date.new(viewing_year, viewing_month, 1).next_month | ||
next_month = next_month_date.month | ||
next_year = next_month_date.year | ||
|
||
# Trigger the job for the next month | ||
RecurringAvailabilityJob.perform_later(next_month, next_year) | ||
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,37 @@ | ||
class Api::V1::BookingsController < ApplicationController | ||
load_and_authorize_resource | ||
|
||
def index | ||
@bookings = Booking.accessible_by(current_ability) | ||
render json: @bookings | ||
end | ||
|
||
def show | ||
render json: @booking | ||
end | ||
|
||
def create | ||
@booking = Booking.new(booking_params) | ||
@booking.user = current_user | ||
|
||
if @booking.save | ||
render json: @booking, status: :created | ||
else | ||
render json: @booking.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @booking.update(booking_params) | ||
render json: @booking | ||
else | ||
render json: @booking.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def booking_params | ||
params.require(:booking).permit(:event_id, :availability_id, :start_time, :end_time, :status) | ||
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,44 @@ | ||
class Api::V1::EventsController < ApplicationController | ||
before_action :set_event, only: [ :show, :update, :destroy ] | ||
|
||
def index | ||
@events = Event.all | ||
render json: @events | ||
end | ||
|
||
def show | ||
render json: @event | ||
end | ||
|
||
def create | ||
@event = Event.new(event_params) | ||
if @event.save | ||
render json: @event, status: :created | ||
else | ||
render json: @event.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
if @event.update(event_params) | ||
render json: @event | ||
else | ||
render json: @event.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@event.destroy | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def set_event | ||
@event = Event.find(params[:id]) | ||
end | ||
|
||
def event_params | ||
params.require(:event).permit(:speaker_id, :title, :description, :duration) | ||
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
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
Oops, something went wrong.