From 2f53edfbdda374bafa30e3dfad8e948cbc3f0e7a Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Thu, 23 Apr 2020 14:31:59 +0300 Subject: [PATCH] [partners_api] guides on map review fixes --- map/guides_manager.hpp | 5 +- partners_api/guides_on_map_api.cpp | 46 +++++++++++-------- partners_api/guides_on_map_api.hpp | 24 +++++----- .../guides_on_map_tests.cpp | 15 +++--- xcode/map/map.xcodeproj/project.pbxproj | 8 ++++ .../partners_api.xcodeproj/project.pbxproj | 12 +++++ 6 files changed, 69 insertions(+), 41 deletions(-) diff --git a/map/guides_manager.hpp b/map/guides_manager.hpp index 550b58dae7..aaf20aad2d 100644 --- a/map/guides_manager.hpp +++ b/map/guides_manager.hpp @@ -8,7 +8,6 @@ #include "geometry/rect2d.hpp" #include "geometry/screenbase.hpp" -#include #include #include #include @@ -58,8 +57,8 @@ public: std::string m_subTitle; Type m_type = Type::City; bool m_downloaded = false; - boost::optional m_cityParams; - boost::optional m_outdoorsParams; + CityParams m_cityParams; + OutdoorParams m_outdoorsParams; }; std::vector m_items; diff --git a/partners_api/guides_on_map_api.cpp b/partners_api/guides_on_map_api.cpp index 7852e45105..1513d4f9c8 100644 --- a/partners_api/guides_on_map_api.cpp +++ b/partners_api/guides_on_map_api.cpp @@ -17,7 +17,7 @@ using namespace base; namespace { -void ParseGallery(std::string const & src, guides_on_map::GalleryOnMap & result) +void ParseGallery(std::string const & src, guides_on_map::GuidesOnMap & result) { Json root(src.c_str()); auto const dataArray = json_object_get(root.get(), "data"); @@ -27,7 +27,7 @@ void ParseGallery(std::string const & src, guides_on_map::GalleryOnMap & result) result.reserve(size); for (size_t i = 0; i < size; ++i) { - guides_on_map::GalleryItem item; + guides_on_map::GuidesNode item; auto const obj = json_array_get(dataArray, i); auto const pointObj = json_object_get(obj, "point"); if (!json_is_object(pointObj)) @@ -48,22 +48,23 @@ void ParseGallery(std::string const & src, guides_on_map::GalleryOnMap & result) auto const extraObj = json_object_get(obj, "extra"); if (json_is_object(extraObj)) { - FromJSONObject(extraObj, "server_id", item.m_guideInfo.m_id); - FromJSONObject(extraObj, "name", item.m_guideInfo.m_name); - FromJSONObject(extraObj, "image_url", item.m_guideInfo.m_imageUrl); - FromJSONObjectOptionalField(extraObj, "tag", item.m_guideInfo.m_tag); - FromJSONObject(extraObj, "bookmarks_count", item.m_guideInfo.m_bookmarksCount); - FromJSONObject(extraObj, "has_track", item.m_guideInfo.m_hasTrack); - FromJSONObjectOptionalField(extraObj, "tracks_length", item.m_guideInfo.m_tracksLength); - FromJSONObjectOptionalField(extraObj, "tour_duration", item.m_guideInfo.m_tourDuration); - FromJSONObjectOptionalField(extraObj, "ascent", item.m_guideInfo.m_ascent); + auto & info = item.m_guideInfo; + FromJSONObject(extraObj, "server_id", info.m_id); + FromJSONObject(extraObj, "name", info.m_name); + FromJSONObject(extraObj, "image_url", info.m_imageUrl); + FromJSONObjectOptionalField(extraObj, "tag", info.m_tag); + FromJSONObject(extraObj, "bookmarks_count", info.m_bookmarksCount); + FromJSONObject(extraObj, "has_track", info.m_hasTrack); + FromJSONObjectOptionalField(extraObj, "tracks_length", info.m_tracksLength); + FromJSONObjectOptionalField(extraObj, "tour_duration", info.m_tourDuration); + FromJSONObjectOptionalField(extraObj, "ascent", info.m_ascent); } result.emplace_back(std::move(item)); } } -std::string MakeGalleryUrl(std::string const & baseUrl, m2::RectD const & viewport, int zoomLevel, +std::string MakeGalleryUrl(std::string const & baseUrl, m2::AnyRectD const & viewport, int zoomLevel, std::string const & lang) { // Support empty baseUrl for opensource build. @@ -79,10 +80,15 @@ std::string MakeGalleryUrl(std::string const & baseUrl, m2::RectD const & viewpo return strings::to_string_dac(latLon.m_lat, 6) + "," + strings::to_string_dac(latLon.m_lon, 6); }; - params.emplace_back("left_bottom", toLatLonFormatted(viewport.LeftBottom())); - params.emplace_back("left_top", toLatLonFormatted(viewport.LeftTop())); - params.emplace_back("right_top", toLatLonFormatted(viewport.RightTop())); - params.emplace_back("right_bottom", toLatLonFormatted(viewport.RightBottom())); + m2::AnyRectD::Corners corners; + viewport.GetGlobalPoints(corners); + + ASSERT_EQUAL(corners.size(), 4, ()); + + params.emplace_back("left_bottom", toLatLonFormatted(corners[0])); + params.emplace_back("left_top", toLatLonFormatted(corners[1])); + params.emplace_back("right_top", toLatLonFormatted(corners[2])); + params.emplace_back("right_bottom", toLatLonFormatted(corners[3])); return url::Make(url::Join(baseUrl, "/gallery/v2/map"), params); } @@ -110,8 +116,8 @@ void Api::SetDelegate(std::unique_ptr delegate) m_delegate = std::move(delegate); } -void Api::GetGalleryOnMap(m2::RectD const & viewport, uint8_t zoomLevel, - GalleryCallback const & onSuccess, OnError const & onError) const +void Api::GetGuidesOnMap(m2::AnyRectD const & viewport, uint8_t zoomLevel, + GuidesOnMapCallback const & onSuccess, OnError const & onError) const { auto const url = MakeGalleryUrl(m_baseUrl, viewport, zoomLevel, languages::GetCurrentNorm()); if (url.empty()) @@ -130,7 +136,7 @@ void Api::GetGalleryOnMap(m2::RectD const & viewport, uint8_t zoomLevel, return; } - GalleryOnMap result; + GuidesOnMap result; try { ParseGallery(httpResult, result); @@ -145,4 +151,4 @@ void Api::GetGalleryOnMap(m2::RectD const & viewport, uint8_t zoomLevel, onSuccess(result); }); } -} // namespace guides_on_map \ No newline at end of file +} // namespace guides_on_map diff --git a/partners_api/guides_on_map_api.hpp b/partners_api/guides_on_map_api.hpp index e791c5dd99..d7de7b6a26 100644 --- a/partners_api/guides_on_map_api.hpp +++ b/partners_api/guides_on_map_api.hpp @@ -3,29 +3,31 @@ #include "platform/http_client.hpp" #include "platform/safe_callback.hpp" +#include "geometry/any_rect2d.hpp" #include "geometry/point2d.hpp" -#include "geometry/rect2d.hpp" #include "private.h" #include +#include #include namespace guides_on_map { -struct GalleryItem +struct GuidesNode { struct GuideInfo { + // |id| contains guide id on the server. std::string m_id; std::string m_name; std::string m_imageUrl; std::string m_tag; - uint32_t m_bookmarksCount; - bool m_hasTrack; - double m_tracksLength; - double m_tourDuration; - int32_t m_ascent; + uint32_t m_bookmarksCount = 0; + bool m_hasTrack = false; + double m_tracksLength = 0.0; + double m_tourDuration = 0.0; + int32_t m_ascent = 0; }; m2::PointD m_point; @@ -34,9 +36,9 @@ struct GalleryItem GuideInfo m_guideInfo; }; -using GalleryOnMap = std::vector; +using GuidesOnMap = std::vector; -using GalleryCallback = platform::SafeCallback; +using GuidesOnMapCallback = platform::SafeCallback; using OnError = platform::SafeCallback; class Api @@ -54,8 +56,8 @@ public: void SetDelegate(std::unique_ptr delegate); - void GetGalleryOnMap(m2::RectD const & viewport, uint8_t zoomLevel, - GalleryCallback const & onSuccess, OnError const & onError) const; + void GetGuidesOnMap(m2::AnyRectD const & viewport, uint8_t zoomLevel, + GuidesOnMapCallback const & onSuccess, OnError const & onError) const; private: std::unique_ptr m_delegate; diff --git a/partners_api/partners_api_tests/guides_on_map_tests.cpp b/partners_api/partners_api_tests/guides_on_map_tests.cpp index 4080119041..7dc2ff2736 100644 --- a/partners_api/partners_api_tests/guides_on_map_tests.cpp +++ b/partners_api/partners_api_tests/guides_on_map_tests.cpp @@ -6,7 +6,7 @@ #include "geometry/mercator.hpp" #include "geometry/point2d.hpp" -#include "geometry/rect2d.hpp" +#include "geometry/any_rect2d.hpp" #include @@ -26,11 +26,11 @@ UNIT_CLASS_TEST(AsyncGuiThread, GuidesOnMap_GetGalleryOnMap) { guides_on_map::Api api("http://localhost:34568/"); api.SetDelegate(std::make_unique()); - m2::RectD viewport = {}; + m2::AnyRectD viewport = {}; uint8_t zoomlevel = 1; - guides_on_map::GalleryOnMap result{}; - api.GetGalleryOnMap(viewport, zoomlevel, [&result](guides_on_map::GalleryOnMap const & gallery) + guides_on_map::GuidesOnMap result{}; + api.GetGuidesOnMap(viewport, zoomlevel, [&result](guides_on_map::GuidesOnMap const & gallery) { result = gallery; testing::Notify(); @@ -48,11 +48,12 @@ UNIT_CLASS_TEST(AsyncGuiThread, GuidesOnMap_GetGalleryOnMap) api.SetDelegate(std::make_unique()); m2::PointD leftTop = mercator::FromLatLon(55.781177, 37.564582); m2::PointD rightBottom = mercator::FromLatLon(55.725608, 37.699851); - m2::RectD viewport(leftTop, rightBottom); + m2::RectD rect(leftTop, rightBottom); + m2::AnyRectD viewport(rect); uint8_t zoomlevel = 1; - guides_on_map::GalleryOnMap result{}; - api.GetGalleryOnMap(viewport, zoomlevel, [&result](guides_on_map::GalleryOnMap const & gallery) + guides_on_map::GuidesOnMap result{}; + api.GetGuidesOnMap(viewport, zoomlevel, [&result](guides_on_map::GuidesOnMap const & gallery) { result = gallery; testing::Notify(); diff --git a/xcode/map/map.xcodeproj/project.pbxproj b/xcode/map/map.xcodeproj/project.pbxproj index 4ecf7bf817..fb27c7a39b 100644 --- a/xcode/map/map.xcodeproj/project.pbxproj +++ b/xcode/map/map.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 39B9682423E1AC7400D3B8E3 /* libge0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 39B9682323E1AC7400D3B8E3 /* libge0.a */; }; 39E3C60323312BA800FB0C37 /* features_fetcher.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 39E3C60123312BA800FB0C37 /* features_fetcher.hpp */; }; 39E3C60423312BA800FB0C37 /* features_fetcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39E3C60223312BA800FB0C37 /* features_fetcher.cpp */; }; + 3D035CA82451960400C21B57 /* guides_on_map_delegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D035CA62451960400C21B57 /* guides_on_map_delegate.cpp */; }; + 3D035CA92451960400C21B57 /* guides_on_map_delegate.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D035CA72451960400C21B57 /* guides_on_map_delegate.hpp */; }; 3D0AEAFC1FBB0FF400AD042B /* libgenerator_tests_support.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D0AEAFF1FBB0FF400AD042B /* libgenerator_tests_support.a */; }; 3D0AEAFE1FBB0FF400AD042B /* libsearch_tests_support.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D0AEB011FBB0FF400AD042B /* libsearch_tests_support.a */; }; 3D0BBAE523F3EEEF00A50354 /* libweb_api.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D0BBAE423F3EEEF00A50354 /* libweb_api.a */; }; @@ -317,6 +319,8 @@ 39B9682323E1AC7400D3B8E3 /* libge0.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libge0.a; sourceTree = BUILT_PRODUCTS_DIR; }; 39E3C60123312BA800FB0C37 /* features_fetcher.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = features_fetcher.hpp; sourceTree = ""; }; 39E3C60223312BA800FB0C37 /* features_fetcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = features_fetcher.cpp; sourceTree = ""; }; + 3D035CA62451960400C21B57 /* guides_on_map_delegate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = guides_on_map_delegate.cpp; sourceTree = ""; }; + 3D035CA72451960400C21B57 /* guides_on_map_delegate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = guides_on_map_delegate.hpp; sourceTree = ""; }; 3D0AEAFF1FBB0FF400AD042B /* libgenerator_tests_support.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libgenerator_tests_support.a; sourceTree = BUILT_PRODUCTS_DIR; }; 3D0AEB001FBB0FF400AD042B /* libindexer_tests_support.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libindexer_tests_support.a; sourceTree = BUILT_PRODUCTS_DIR; }; 3D0AEB011FBB0FF400AD042B /* libsearch_tests_support.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libsearch_tests_support.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -900,6 +904,8 @@ 675345BD1A4054AD00A0A8C3 /* map */ = { isa = PBXGroup; children = ( + 3D035CA62451960400C21B57 /* guides_on_map_delegate.cpp */, + 3D035CA72451960400C21B57 /* guides_on_map_delegate.hpp */, BBBB5ED024460BF9000CBFF4 /* guides_manager.cpp */, BBBB5ED124460BF9000CBFF4 /* guides_manager.hpp */, 3DBD7BE024237FA600ED9FE8 /* download_on_map_ads_delegate.cpp */, @@ -1061,6 +1067,7 @@ 347B60771DD9926D0050FA24 /* traffic_manager.hpp in Headers */, 45F6EE9E1FB1C77600019892 /* mwm_tree.hpp in Headers */, F6B283081C1B03320081957A /* gps_track_storage.hpp in Headers */, + 3D035CA92451960400C21B57 /* guides_on_map_delegate.hpp in Headers */, 3DD1166B21888AAD007A2ED4 /* notification_manager.hpp in Headers */, 3D4F44BB21345D270005E765 /* tips_api.hpp in Headers */, 675346A21A4054E800A0A8C3 /* user_mark.hpp in Headers */, @@ -1313,6 +1320,7 @@ 3DF54F8A21AEA04A00D12E37 /* framework_light.cpp in Sources */, 674C38621BFF3095000D603B /* user_mark.cpp in Sources */, 3DA5723320C195ED007BDE27 /* viewport_search_callback.cpp in Sources */, + 3D035CA82451960400C21B57 /* guides_on_map_delegate.cpp in Sources */, 675346641A4054E800A0A8C3 /* framework.cpp in Sources */, BBBB5ED224460BFA000CBFF4 /* guides_manager.cpp in Sources */, 40ACC79623191C2600238E21 /* countries_names_tests.cpp in Sources */, diff --git a/xcode/partners_api/partners_api.xcodeproj/project.pbxproj b/xcode/partners_api/partners_api.xcodeproj/project.pbxproj index 592480a9b0..e751151ab7 100644 --- a/xcode/partners_api/partners_api.xcodeproj/project.pbxproj +++ b/xcode/partners_api/partners_api.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 349FEC5A2010D54D00FE5CA3 /* liboauthcpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 349FEC5B2010D54D00FE5CA3 /* liboauthcpp.a */; }; 349FEC5C2010D56400FE5CA3 /* libprotobuf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 349FEC5D2010D56400FE5CA3 /* libprotobuf.a */; }; 349FEC5E2010D67B00FE5CA3 /* libopening_hours.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 349FEC5F2010D67B00FE5CA3 /* libopening_hours.a */; }; + 3D035CA2245195E600C21B57 /* guides_on_map_api.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D035CA0245195E500C21B57 /* guides_on_map_api.hpp */; }; + 3D035CA3245195E600C21B57 /* guides_on_map_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D035CA1245195E600C21B57 /* guides_on_map_api.cpp */; }; + 3D035CA5245195EF00C21B57 /* guides_on_map_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D035CA4245195EF00C21B57 /* guides_on_map_tests.cpp */; }; 3D15ACE6214AA1B000F725D5 /* taxi_delegate.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D15ACE3214AA1AF00F725D5 /* taxi_delegate.hpp */; }; 3D15ACE7214AA1B000F725D5 /* rutaxi_api.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D15ACE4214AA1B000F725D5 /* rutaxi_api.hpp */; }; 3D15ACE8214AA1B000F725D5 /* rutaxi_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D15ACE5214AA1B000F725D5 /* rutaxi_api.cpp */; }; @@ -132,6 +135,9 @@ 349FEC5B2010D54D00FE5CA3 /* liboauthcpp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = liboauthcpp.a; sourceTree = BUILT_PRODUCTS_DIR; }; 349FEC5D2010D56400FE5CA3 /* libprotobuf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libprotobuf.a; sourceTree = BUILT_PRODUCTS_DIR; }; 349FEC5F2010D67B00FE5CA3 /* libopening_hours.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libopening_hours.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 3D035CA0245195E500C21B57 /* guides_on_map_api.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = guides_on_map_api.hpp; sourceTree = ""; }; + 3D035CA1245195E600C21B57 /* guides_on_map_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = guides_on_map_api.cpp; sourceTree = ""; }; + 3D035CA4245195EF00C21B57 /* guides_on_map_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = guides_on_map_tests.cpp; sourceTree = ""; }; 3D15ACE3214AA1AF00F725D5 /* taxi_delegate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_delegate.hpp; sourceTree = ""; }; 3D15ACE4214AA1B000F725D5 /* rutaxi_api.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rutaxi_api.hpp; sourceTree = ""; }; 3D15ACE5214AA1B000F725D5 /* rutaxi_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rutaxi_api.cpp; sourceTree = ""; }; @@ -326,6 +332,8 @@ F6B5363B1DA520B20067EEA5 /* partners_api */ = { isa = PBXGroup; children = ( + 3D035CA1245195E600C21B57 /* guides_on_map_api.cpp */, + 3D035CA0245195E500C21B57 /* guides_on_map_api.hpp */, 3DBD7BE524251BF000ED9FE8 /* ads */, 3DBD7B9624112DE000ED9FE8 /* freenow_api.cpp */, 3DBD7B9724112DE100ED9FE8 /* freenow_api.hpp */, @@ -377,6 +385,7 @@ F6B536441DA521060067EEA5 /* partners_api_tests */ = { isa = PBXGroup; children = ( + 3D035CA4245195EF00C21B57 /* guides_on_map_tests.cpp */, 3DBD7C1C24251C1100ED9FE8 /* bookmark_catalog_ads_tests.cpp */, 3DBD7C1A24251C1000ED9FE8 /* download_on_map_container_delegate.hpp */, 3DBD7C1924251C1000ED9FE8 /* mts_tests.cpp */, @@ -474,6 +483,7 @@ 45AC338F22C4F449004DC574 /* utm.hpp in Headers */, 4566605120D91FEE0085E8C1 /* megafon_countries.hpp in Headers */, F6B536431DA520E40067EEA5 /* uber_api.hpp in Headers */, + 3D035CA2245195E600C21B57 /* guides_on_map_api.hpp in Headers */, 3DBD7C0424251BF000ED9FE8 /* mopub_ads.hpp in Headers */, 3DBD7C1224251BF000ED9FE8 /* ads_utils.hpp in Headers */, 3DBD7C0624251BF000ED9FE8 /* ads_engine.hpp in Headers */, @@ -581,9 +591,11 @@ 3DFEBFA41EFBFC2300317D5C /* yandex_tests.cpp in Sources */, 3D1775A72318198700F8889C /* promo_catalog_types.cpp in Sources */, 3D452AEF1EE6D202009EAB9B /* google_tests.cpp in Sources */, + 3D035CA3245195E600C21B57 /* guides_on_map_api.cpp in Sources */, 3D452AF01EE6D202009EAB9B /* mopub_tests.cpp in Sources */, 3D18DC3422953FF600A583A6 /* rutaxi_tests.cpp in Sources */, 3DBD7C0924251BF000ED9FE8 /* ads_utils.cpp in Sources */, + 3D035CA5245195EF00C21B57 /* guides_on_map_tests.cpp in Sources */, 3DBD7C0824251BF000ED9FE8 /* skyeng_ads.cpp in Sources */, 3DBD7BFF24251BF000ED9FE8 /* bookmark_catalog_ads.cpp in Sources */, 3D4E997F1FB439300025B48C /* utils.cpp in Sources */,