mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add URLs to API responses
Resolves inability of API consumers to provide links to OSEM.
This commit is contained in:
parent
5b89f64eaf
commit
e01fd2d721
6 changed files with 27 additions and 3 deletions
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
class ConferenceSerializer < ActiveModel::Serializer
|
class ConferenceSerializer < ActiveModel::Serializer
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
attributes :short_title, :title, :description, :start_date, :end_date, :picture_url,
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
attributes :short_title, :url, :title, :description, :start_date, :end_date, :picture_url,
|
||||||
:difficulty_levels, :event_types, :rooms, :tracks,
|
:difficulty_levels, :event_types, :rooms, :tracks,
|
||||||
:date_range, :revision
|
:date_range, :revision
|
||||||
|
|
||||||
|
|
@ -56,6 +58,10 @@ class ConferenceSerializer < ActiveModel::Serializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
url_for(object)
|
||||||
|
end
|
||||||
|
|
||||||
def revision
|
def revision
|
||||||
object.revision || 0
|
object.revision || 0
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
class EventSerializer < ActiveModel::Serializer
|
class EventSerializer < ActiveModel::Serializer
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
attributes :guid, :title, :length, :scheduled_date, :language, :abstract, :speaker_ids, :type, :room, :track
|
attributes :guid, :url, :title, :length, :scheduled_date, :language, :abstract, :speaker_ids, :type, :room, :track
|
||||||
|
|
||||||
|
def url
|
||||||
|
conference_program_proposal_url(object.conference.short_title, object.id)
|
||||||
|
end
|
||||||
|
|
||||||
def scheduled_date
|
def scheduled_date
|
||||||
t = object.time
|
t = object.time
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
class SpeakerSerializer < ActiveModel::Serializer
|
class SpeakerSerializer < ActiveModel::Serializer
|
||||||
include ActionView::Helpers::TextHelper
|
include ActionView::Helpers::TextHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
attributes :name, :affiliation, :biography
|
attributes :url, :name, :affiliation, :biography
|
||||||
|
|
||||||
delegate :name, to: :object
|
delegate :name, to: :object
|
||||||
|
|
||||||
|
def url
|
||||||
|
url_for(object)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ describe EventSerializer, type: :serializer do
|
||||||
it 'sets guid, title, length, abstract and type' do
|
it 'sets guid, title, length, abstract and type' do
|
||||||
expected_json = {
|
expected_json = {
|
||||||
guid: event.guid,
|
guid: event.guid,
|
||||||
|
url: "http://localhost:3000/conferences/#{event.conference.short_title}/program/proposals/#{event.id}",
|
||||||
title: 'Some Talk',
|
title: 'Some Talk',
|
||||||
length: 30,
|
length: 30,
|
||||||
scheduled_date: '',
|
scheduled_date: '',
|
||||||
|
|
@ -39,6 +40,7 @@ describe EventSerializer, type: :serializer do
|
||||||
it 'sets guid, title, length, abstract, type, date, language, speakers, room and track' do
|
it 'sets guid, title, length, abstract, type, date, language, speakers, room and track' do
|
||||||
expected_json = {
|
expected_json = {
|
||||||
guid: event.guid,
|
guid: event.guid,
|
||||||
|
url: "http://localhost:3000/conferences/#{event.conference.short_title}/program/proposals/#{event.id}",
|
||||||
title: 'Some Talk',
|
title: 'Some Talk',
|
||||||
length: 30,
|
length: 30,
|
||||||
scheduled_date: ' 2014-03-04T09:00:00+0000 ',
|
scheduled_date: ' 2014-03-04T09:00:00+0000 ',
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ describe SpeakerSerializer, type: :serializer do
|
||||||
context 'speaker does not have biography' do
|
context 'speaker does not have biography' do
|
||||||
it 'sets name and affiliation' do
|
it 'sets name and affiliation' do
|
||||||
expected_json = {
|
expected_json = {
|
||||||
|
url: "http://localhost:3000/users/#{speaker.id}",
|
||||||
name: 'John Doe',
|
name: 'John Doe',
|
||||||
affiliation: 'JohnDoesInc',
|
affiliation: 'JohnDoesInc',
|
||||||
biography: nil
|
biography: nil
|
||||||
|
|
@ -22,6 +23,7 @@ describe SpeakerSerializer, type: :serializer do
|
||||||
|
|
||||||
it 'sets name, affiliation and biography' do
|
it 'sets name, affiliation and biography' do
|
||||||
expected_json = {
|
expected_json = {
|
||||||
|
url: "http://localhost:3000/users/#{speaker.id}",
|
||||||
name: 'John Doe',
|
name: 'John Doe',
|
||||||
affiliation: 'JohnDoesInc',
|
affiliation: 'JohnDoesInc',
|
||||||
biography: 'Doest of all Jon Does'
|
biography: 'Doest of all Jon Does'
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"required" : [
|
"required" : [
|
||||||
"short_title",
|
"short_title",
|
||||||
|
"url",
|
||||||
"title",
|
"title",
|
||||||
"description",
|
"description",
|
||||||
"start_date",
|
"start_date",
|
||||||
|
|
@ -19,6 +20,9 @@
|
||||||
"short_title": {
|
"short_title": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"title": {
|
"title": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue