API: Update post location format to floats instead of floats as strings

This commit is contained in:
Jonne Haß 2019-04-27 16:04:44 +02:00
parent af59bf3265
commit 52e4e9f903
2 changed files with 13 additions and 4 deletions

View file

@ -28,12 +28,12 @@ class PostPresenter < BasePresenter
author: PersonPresenter.new(@post.author).as_api_json, author: PersonPresenter.new(@post.author).as_api_json,
provider_display_name: @post.provider_display_name, provider_display_name: @post.provider_display_name,
interaction_counters: PostInteractionPresenter.new(@post, current_user).as_counters, interaction_counters: PostInteractionPresenter.new(@post, current_user).as_counters,
location: @post.post_location, location: location_as_api_json,
poll: PollPresenter.new(@post.poll, current_user).as_api_json, poll: PollPresenter.new(@post.poll, current_user).as_api_json,
mentioned_people: build_mentioned_people_json, mentioned_people: build_mentioned_people_json,
photos: build_photos_json, photos: build_photos_json,
root: root_api_response root: root_api_response
} }.compact
end end
def with_interactions def with_interactions
@ -192,4 +192,13 @@ class PostPresenter < BasePresenter
def description def description
message.try(:plain_text_without_markdown, truncate: 1000) message.try(:plain_text_without_markdown, truncate: 1000)
end end
def location_as_api_json
location = @post.post_location
return if location.values.all?(&:nil?)
location[:lat] = location[:lat].to_f
location[:lng] = location[:lng].to_f
location
end
end end

View file

@ -723,8 +723,8 @@ describe Api::V1::PostsController do
def confirm_location(location, ref_location) def confirm_location(location, ref_location)
expect(location["address"]).to eq(ref_location[:address]) expect(location["address"]).to eq(ref_location[:address])
expect(location["lat"]).to eq(ref_location[:lat]) expect(location["lat"]).to eq(ref_location[:lat].to_f)
expect(location["lng"]).to eq(ref_location[:lng]) expect(location["lng"]).to eq(ref_location[:lng].to_f)
end end
def confirm_photos(photos, ref_photos) def confirm_photos(photos, ref_photos)