From 52cb69615912c136dec9192351cdbedc4c0713e1 Mon Sep 17 00:00:00 2001 From: Laura Mosher <2660801+lauramosher@users.noreply.github.com> Date: Sat, 28 Oct 2023 08:44:29 -0400 Subject: [PATCH] enhanc: add additional Story details to explore api (#980) Co-authored-by: Laura Mosher --- .../app/views/api/stories/show.json.jbuilder | 22 +++++++++++++++++++ rails/spec/requests/api/public_story_spec.rb | 17 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/rails/app/views/api/stories/show.json.jbuilder b/rails/app/views/api/stories/show.json.jbuilder index 05423cb1d..a3c2d2669 100644 --- a/rails/app/views/api/stories/show.json.jbuilder +++ b/rails/app/views/api/stories/show.json.jbuilder @@ -4,9 +4,20 @@ 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])) @@ -14,6 +25,11 @@ json.speakers @story.speakers do |speaker| 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) @@ -21,6 +37,12 @@ json.places @story.places do |place| 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 diff --git a/rails/spec/requests/api/public_story_spec.rb b/rails/spec/requests/api/public_story_spec.rb index 9829bc76f..c68952c08 100644 --- a/rails/spec/requests/api/public_story_spec.rb +++ b/rails/spec/requests/api/public_story_spec.rb @@ -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