mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
API with more options, includes #712
This commit is contained in:
parent
28e55f3f50
commit
ecef151f91
7 changed files with 86 additions and 38 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class ConferencesController < Api::BaseController
|
class ConferencesController < Api::BaseController
|
||||||
|
load_resource find_by: :short_title
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:conference_id].blank?
|
render json: @conferences, serializer: ConferencesArraySerializer
|
||||||
conferences = Conference.all
|
end
|
||||||
else
|
|
||||||
conferences = Conference.find_all_by_guid(params[:conference_id])
|
def show
|
||||||
end
|
render json: [@conference], serializer: ConferencesArraySerializer
|
||||||
render json: conferences, serializer: ConferencesArraySerializer
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class EventsController < Api::BaseController
|
class EventsController < Api::BaseController
|
||||||
|
load_resource :conference, find_by: :short_title
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
events = Event.includes(:conference, :track, :room, :event_type, event_users: :user)
|
events = Event.includes(:conference, :track, :room, :event_type, event_users: :user)
|
||||||
unless params[:conference_id].blank?
|
|
||||||
events = events.where(conferences: { guid: params[:conference_id] })
|
if @conference
|
||||||
|
events = events.where(conference: @conference)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with events.confirmed
|
respond_with events.confirmed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class RoomsController < Api::BaseController
|
class RoomsController < Api::BaseController
|
||||||
|
load_resource :conference, find_by: :short_title
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:conference_id].blank?
|
@conference ? (rooms = @conference.rooms) : (rooms = Room.all)
|
||||||
rooms = Room.all
|
|
||||||
else
|
|
||||||
conference = Conference.find_by_guid(params[:conference_id])
|
|
||||||
rooms = conference.rooms
|
|
||||||
end
|
|
||||||
respond_with rooms
|
respond_with rooms
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class SpeakersController < Api::BaseController
|
class SpeakersController < Api::BaseController
|
||||||
|
load_resource :conference, find_by: :short_title
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:conference_id].blank?
|
if @conference
|
||||||
users = User.joins(:event_users)
|
|
||||||
else
|
|
||||||
users = User.joins(event_users: { event: :conference })
|
users = User.joins(event_users: { event: :conference })
|
||||||
users = users.where(conferences: { guid: params[:conference_id] })
|
users = users.where(conferences: { short_title: @conference.short_title })
|
||||||
|
else
|
||||||
|
users = User.joins(:event_users)
|
||||||
end
|
end
|
||||||
users = users.where(event_users: {event_role: :speaker})
|
|
||||||
|
users = users.where(event_users: {event_role: :speaker}).uniq
|
||||||
render json: users, each_serializer: SpeakerSerializer
|
render json: users, each_serializer: SpeakerSerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class TracksController < Api::BaseController
|
class TracksController < Api::BaseController
|
||||||
|
load_resource :conference, find_by: :short_title
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:conference_id].blank?
|
@conference ? (tracks = @conference.tracks) : (tracks = Track.all)
|
||||||
tracks = Track.all
|
|
||||||
else
|
|
||||||
tracks = Track.joins(:conference)
|
|
||||||
tracks = tracks.where(conferences: { guid: params[:conference_id] })
|
|
||||||
end
|
|
||||||
respond_with tracks
|
respond_with tracks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,53 @@
|
||||||
class ConferenceSerializer < ActiveModel::Serializer
|
class ConferenceSerializer < ActiveModel::Serializer
|
||||||
attributes :guid, :name, :description, :year, :socialtag, :date_range, :url, :revision
|
attributes :short_title, :title, :description, :start_date, :end_date, :logo,
|
||||||
|
:difficulty_levels, :event_types, :rooms, :tracks,
|
||||||
|
:date_range, :revision
|
||||||
|
|
||||||
|
def difficulty_levels
|
||||||
|
object.difficulty_levels.map do |difficulty_level| { id: difficulty_level.id,
|
||||||
|
title: difficulty_level.title,
|
||||||
|
description: difficulty_level.description
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def event_types
|
||||||
|
object.event_types.map do |event_type| { id: event_type.id,
|
||||||
|
title: event_type.title,
|
||||||
|
length: event_type.length,
|
||||||
|
description: event_type.description
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def rooms
|
||||||
|
object.rooms.includes(:events).map do |room| { id: room.id,
|
||||||
|
size: room.size,
|
||||||
|
events: room.events.map do |event| { guid: event.title,
|
||||||
|
title: event.title,
|
||||||
|
subtitle: event.subtitle,
|
||||||
|
abstract: event.abstract,
|
||||||
|
description: event.description,
|
||||||
|
is_highlight: event.is_highlight,
|
||||||
|
require_registration: event.require_registration,
|
||||||
|
start_time: event.start_time,
|
||||||
|
event_type_id: event.event_type.id,
|
||||||
|
difficulty_level_id: event.difficulty_level_id,
|
||||||
|
track_id: event.track_id,
|
||||||
|
speaker_names: event.speaker_names
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def tracks
|
||||||
|
object.tracks.map do |track| { 'id' => track.id,
|
||||||
|
'name' => track.name,
|
||||||
|
'description' => track.description
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
object.title
|
object.title
|
||||||
|
|
@ -20,16 +68,18 @@ class ConferenceSerializer < ActiveModel::Serializer
|
||||||
# FIXME: adjusting the format the DIRTY way, for oSC13.
|
# FIXME: adjusting the format the DIRTY way, for oSC13.
|
||||||
# If you think this is ugly, don't look at the methods below
|
# If you think this is ugly, don't look at the methods below
|
||||||
def date_range
|
def date_range
|
||||||
object.date_range_string.try(:split, ',').try(:first)
|
if defined? object.date_range_string
|
||||||
|
object.date_range_string.try(:split, ',').try(:first)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: just giving suseconferenceclient something to play with
|
# # FIXME: just giving suseconferenceclient something to play with
|
||||||
def description
|
# def description
|
||||||
'openSUSE Conference 2013 - Power to the Geeko'
|
# 'openSUSE Conference 2013 - Power to the Geeko'
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
# FIXME: same than the former
|
# # FIXME: same than the former
|
||||||
def url
|
# def url
|
||||||
'https://conference.opensuse.org/'
|
# 'https://conference.opensuse.org/'
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,7 @@ Osem::Application.routes.draw do
|
||||||
|
|
||||||
namespace :api, defaults: {format: 'json'} do
|
namespace :api, defaults: {format: 'json'} do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :conferences, only: :index do
|
resources :conferences, only: [ :index, :show ] do
|
||||||
resources :conferences, only: :index
|
|
||||||
resources :rooms, only: :index
|
resources :rooms, only: :index
|
||||||
resources :tracks, only: :index
|
resources :tracks, only: :index
|
||||||
resources :speakers, only: :index
|
resources :speakers, only: :index
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue