Skip to content

Commit

Permalink
Change how location is passed on to core
Browse files Browse the repository at this point in the history
  • Loading branch information
renatolond committed Nov 15, 2024
1 parent 648c70e commit 3fc9bb2
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 38 deletions.
3 changes: 2 additions & 1 deletion app/controllers/profiles/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def search
end

def update
retro_meet_client.update_profile_location(location: params["location"])
location, osm_id = params["location"].split("|", 2)
retro_meet_client.update_profile_location(location:, osm_id:)
if response
redirect_to profile_path, status: :see_other
else
Expand Down
3 changes: 3 additions & 0 deletions app/models/location_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

LocationResult = Data.define(:display_name, :osm_id, :osm_type)
55 changes: 30 additions & 25 deletions app/models/profile_info.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# frozen_string_literal: true

ABOUT_ME_TEXT = "I'm very much into computers. I spend most of my time jacked into the ship's computers using my neuro-port. I really am not that much into humans, but I'm hoping that maybe I can find someone that's into the same things that I am and we can maybe spend time in virtual.
I also make a mean carbonara, but most of the time I just live off Soylent Green, it has a distinct flavor that really pleases me."
ProfileInfo = Data.define(:display_name,
:birth_date,
:genders,
:orientations,
:age,
:profile_picture,
:location,
:location_display_name,
:about_me,
:pronouns,
:languages,
Expand All @@ -26,28 +23,28 @@
:religion,
:religion_importance) do
# TODO: remove default later, these are here to make it easier to create new profile page
def initialize(display_name: "Lommie Thorne",
birth_date: Date.new(2083, 6, 12),
genders: %i[genderfluid questioning],
orientations: %i[asexual bisexual],
age: nil,
profile_picture: "https://picsum.photos/id/433/256/256",
location: "Nightflyer, Space",
about_me: ABOUT_ME_TEXT,
def initialize(display_name:,
birth_date:,
genders:,
orientations:,
location_display_name:,
about_me:,
languages:,
relationship_status:,
relationship_type:,
tobacco:,
alcohol:,
marijuana:,
other_recreational_drugs:,
pets:,
wants_pets:,
kids:,
wants_kids:,
religion:,
religion_importance:,
pronouns: "She/Her",
languages: %i[por eng qaa],
relationship_status: :single,
relationship_type: :non_monogamous,
tobacco: :never,
alcohol: :often,
marijuana: :sometimes,
other_recreational_drugs: :sometimes,
pets: :have,
wants_pets: :do_not_want_more,
kids: :have_not,
wants_kids: :dont_know,
religion: :atheism,
religion_importance: :important)
age: nil,
profile_picture: "https://picsum.photos/id/433/256/256")
if birth_date
birth_date = Date.parse(birth_date) if birth_date.is_a? String
age ||= begin
Expand All @@ -65,4 +62,12 @@ def initialize(display_name: "Lommie Thorne",
def persisted?
true
end

# @param user_language [Symbol,nil]
# @return [String]
def location(user_language: nil)
return nil if location_display_name.nil?

location_display_name[user_language] || location_display_name[:en]
end
end
10 changes: 7 additions & 3 deletions app/objects/retro_meet_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ def location_search(query:)
response = client.post("/api/search/address", headers: base_headers, body:)
case response.status
when 200
JSON.parse(response.read, symbolize_names: true)
response_body = JSON.parse(response.read, symbolize_names: true)
response_body.map! do |result|
LocationResult.new(**result.slice(*LocationResult.members))
end
else
raise UnknownError, "An unknown error happened while calling retromeet-core"
end
Expand All @@ -137,11 +140,12 @@ def location_search(query:)

# Calls the update profile location endpoint in retromeet-core and returns the response as a ruby object
# @param location [String] A location to be used as the current profile location
# @param osm_id [Integer] The OSM id to be matched to the location
# @return [TrueClass] If the request is sucessfull
def update_profile_location(location:)
def update_profile_location(location:, osm_id:)
return nil if @authorization_header.blank?

body = { location: }.to_json
body = { location:, osm_id: }.to_json
Sync do
response = client.post("/api/profile/location", headers: base_headers, body:)
case response.status
Expand Down
15 changes: 6 additions & 9 deletions app/views/profiles/locations/search.turbo_stream.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@
.field-body
.field
.control
= form.text_field :location, class: "input", value: @locations.first[:display_name], readonly: true
= form.text_field :location, class: "input", value: "#{@locations.first.display_name}|#{@locations.first.osm_id}", readonly: true
.field.is-grouped-right.is-grouped
.control
= form.submit class: "button is-info"
- elsif @locations.size > 1
.message.is-success
.message-body= t(".multiple_results_help")
= form_with(url: profile_location_path, method: :patch) do |form|
.field.is-horizontal
.field-label.is-normal
= form.label :location, class: "label"
.field-body
.field
.control
.select.is-fullwidth
= form.select :location, @locations.map { |v| v[:display_name] }
- @locations.each do |location|
.control
%label.radio
= form.radio_button :location, "#{location.display_name}|#{location.osm_id}"
#{location.display_name} (#{t(location.osm_type, scope: "osm_types")})
.field.is-grouped-right.is-grouped
.control
= form.submit class: "button is-info"
2 changes: 2 additions & 0 deletions app/views/profiles/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- if controller.action_name == 'show'
.is-pulled-right
%a{href: edit_profile_path}= I18n.t("edit_profile")
|
%a{href: edit_profile_location_path}= I18n.t("edit_profile_location")
.title.is-4
#{@profile_info.display_name}
.subtitle.is-6
Expand Down
12 changes: 12 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ en:
other: "%{count} years old"
alcohol: Alcohol
edit_profile: Edit profile
edit_profile_location: Edit profile location
forced_log_out: Forced log out
frequency:
never: Never
Expand Down Expand Up @@ -324,3 +325,14 @@ en:
want_more: want more
want_some: want some
welcome: Welcome, %{display_name}!
osm_types:
town: "Town"
village: "Village"
hamlet: "Hamlet"
isolated_dwelling: "Isolated dwelling"
city: "City"
borough: "Borough"
suburb: "Suburb"
quarter: "Quarter"
neighbourhood: "Neighbourhood"
municipality: "Municipality"

0 comments on commit 3fc9bb2

Please sign in to comment.