Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #2045 improve adding venue to product admin #2046

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

nangdypanhar
Copy link
Collaborator

@nangdypanhar nangdypanhar commented Nov 6, 2024

Demo :

Screencast.from.2024-11-28.10-10-05.webm

Description :

  • Create an api for venue search and it fetches the place from the google.
  • We 're no longer take the place from database to select , we can search and create the product place.

@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch 2 times, most recently from 5f9dc0f to cfbf574 Compare November 26, 2024 07:38
@nangdypanhar nangdypanhar self-assigned this Nov 26, 2024
@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch 2 times, most recently from 62a6087 to 8407aac Compare November 26, 2024 11:51
@nangdypanhar nangdypanhar changed the title WIP#2045 add nearby places suggestion close#2045 improve adding venue to product admin Nov 26, 2024
@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch 2 times, most recently from 8213496 to 03c4358 Compare November 27, 2024 00:11
@nangdypanhar nangdypanhar added enhancement New feature or request L From 2 to 3 days to make it ready labels Nov 27, 2024
@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch 4 times, most recently from ba02ac8 to 78332af Compare November 28, 2024 03:06
@nangdypanhar nangdypanhar changed the title close#2045 improve adding venue to product admin close# 2045 improve adding venue to product admin Nov 28, 2024
@nangdypanhar nangdypanhar changed the title close# 2045 improve adding venue to product admin close #2045 improve adding venue to product admin Nov 28, 2024
@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch from 78332af to a5c3476 Compare November 28, 2024 03:24
@nangdypanhar nangdypanhar linked an issue Nov 28, 2024 that may be closed by this pull request
end

def collection
@collection ||= begin
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the begin statement here cause nested code. let's remove it.


private

Place = Struct.new(:id, :name, :base_64_content)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this Struct from global declaration in the controller, it might cause a conflict of type in the future.

context.google_places = []
json_response = fetch_google_place_by_name

json_response['results'].each_with_index do |json, _|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the .map instead.

end

def fetch_google_place_by_name
url = URI("#{GOOGLE_MAP_API_URL}/place/textsearch/json?query=#{name}&key=#{google_map_key}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't construct the query manually, it is not safe.

queries = {
   query: name,
   key: google_map_key
}.to_param

google_uri =   URI("#{GOOGLE_MAP_API_URL}/place/textsearch/json?#{queries}")


def fetch_google_place_by_name
url = URI("#{GOOGLE_MAP_API_URL}/place/textsearch/json?query=#{name}&key=#{google_map_key}")
https = Net::HTTP.new(url.host, url.port)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the Faraday instead of the Net. Make sure to keep the Http outbound request consitent by not employing other libs/classes

Place.new(
id: place.reference,
name: place.name,
base_64_content: Base64.strict_encode64(place.to_json)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget. why do we need the base_64_content for?

Copy link
Collaborator Author

@nangdypanhar nangdypanhar Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In form, we can only pass key & value bong. Because we want to pass all google place data, we need to encode it.

In controller, we can decode it back, and create place in database if not yet exist.

@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch 2 times, most recently from 7c74577 to 972724c Compare November 28, 2024 07:57
@nangdypanhar nangdypanhar force-pushed the 2045-add-nearby-places-suggestion branch from 972724c to e31a208 Compare November 28, 2024 08:10
@channainfo channainfo merged commit bd30198 into develop Nov 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request L From 2 to 3 days to make it ready
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

add nearby places suggestion
3 participants