class MobileAppApi::V1::EventController

Public Instance Methods

add_event() click to toggle source

Api used to create new event by user through mobile app.

# File app/controllers/mobile_app_api/v1/event_controller.rb, line 30
def add_event
  event = @user.owned_events.build(event_params)
  if !event_params["user_emails"].blank?
    users = User.where(email: event_params["user_emails"].split(','))
    invitee_emails = event_params["user_emails"].split(',') - users.map(&:email)
    users.each do |user|
      event.shares.build(user_id: @user.id, shared_to: user)
    end
  end
  if event.save
    Invite.invite_users(invitee_emails, event) if invitee_emails.present?
    render json: {status: 200, message: 'event Added successfully.', event: serialized_event(event)}
  else
    render json: { status: 400, error: event.errors.full_messages }
  end
end
get_event() click to toggle source

Api to find event by its Id.

# File app/controllers/mobile_app_api/v1/event_controller.rb, line 20
def get_event
  begin
    event = @user.events.find(params[:id])
  rescue
    render json: {status: 401, error: 'Unauthorized'} and return
  end
  render json: {status: 200, event: serialized_event(event)}
end
get_events() click to toggle source

Api to get all events of current user

# File app/controllers/mobile_app_api/v1/event_controller.rb, line 6
def get_events
  start_date = if params[:start_date]
    Date.parse(params[:start_date])
  else
    Date.today_in_time_zone.beginning_of_day.to_date
  end
  end_date = (start_date + 6.days).end_of_day.to_date
  events = @user.events.order(:start_time).for_date_range(start_date, end_date)
  events = events.map {|t| serialized_event(t)}
  events = events.group_by {|t| t['start_time'].to_date.to_s(:iso8601)}
  render json: {status: 200, events: events, date_range: [start_date, end_date]}
end
remove_event() click to toggle source

Api to find and destroy the event created by current user.

# File app/controllers/mobile_app_api/v1/event_controller.rb, line 65
def remove_event
  begin
    event = @user.events.find(params[:id])
  rescue
    render json: {status: 401, error: 'Unauthorized'} and return
  end
  if event.can_delete?(@user)
    if event.destroy
      render json: {status: 200, message: 'event removed successfully.'}
    else
      render json: {status: 400, error: 'Unable to remove event, kindly contact our support team.'}
    end
  else
    render json: {status: 401, error: 'Unauthorized'}
  end
end
update_event() click to toggle source

Api to find and update the event created by current user

# File app/controllers/mobile_app_api/v1/event_controller.rb, line 48
def update_event
  begin
    event = @user.events.find(params[:id])
    if event.update_attributes(event_params)
      if !event_params["user_emails"].blank?
        event.share_with!(event_params["user_emails"].split(','))
      end
      render json: {status: 200, message: 'event updated successfully.', event: serialized_event(event)}
    else
      render json: { status: 400, error: event.errors.full_messages }
    end
  rescue
    render json: {status: 401, error: 'Unauthorized'} and return
  end
end