Skip to content

Commit

Permalink
enhanc: add additional Story details to explore api (#980)
Browse files Browse the repository at this point in the history
Co-authored-by: Laura Mosher <lauramosher@users.noreply.github.com>
  • Loading branch information
lauramosher and lauramosher committed Oct 28, 2023
1 parent 4ac38c3 commit 52cb696
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rails/app/views/api/stories/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,45 @@ json.media @story.media do |media|
json.blob media.blob_id
json.url rails_blob_url(media.media)
end
if @story.interviewer
json.interviewer do
json.(@story.interviewer, :name)
end
end
if @story.interview_location
json.interviewLocation do
json.(@story.interview_location, :name)
end
end
json.speakers @story.speakers do |speaker|
json.(speaker, :id, :name)
json.speakerCommunity speaker.speaker_community
json.birthdate speaker.birthdate
if speaker.photo.attached?
if speaker.photo.variable?
json.photoUrl rails_representation_url(speaker.photo.variant(resize_to_fit: [100, 100]))
else
json.photoUrl rails_blob_url(speaker.photo)
end
end
if speaker.birthplace
json.birthplace do
json.(speaker.birthplace, :name)
end
end
end
json.places @story.places do |place|
json.(place, :id, :name, :description, :region)

json.placenameAudio place.name_audio_url(full_url: true)
json.photoUrl place.photo_url(full_url: true)
json.typeOfPlace place.type_of_place
json.center RGeo::GeoJSON.encode(
RGeo::GeoJSON::Feature.new(
RGeo::Cartesian.factory.point(place.long, place.lat),
place.id
)
)
end

json.points @story.public_points
17 changes: 17 additions & 0 deletions rails/spec/requests/api/public_story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,21 @@ def json_response
"points"
)
end

it "returns optional story details when they are available" do
interviewer = create(:speaker, community: community)
interview_location = create(:place, community: community)
story.update!(
interviewer: interviewer,
interview_location: interview_location,
)

get "/api/communities/cool_community/stories/123"

expect(response).to have_http_status(:ok)
expect(json_response.keys).to include(
"interviewer",
"interviewLocation",
)
end
end

0 comments on commit 52cb696

Please sign in to comment.