forked from organicmaps/organicmaps
[booking] review fixes
This commit is contained in:
parent
a5e68c191c
commit
0049019dc0
3 changed files with 32 additions and 18 deletions
|
@ -15,7 +15,6 @@
|
|||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "3party/jansson/myjansson.hpp"
|
||||
|
@ -39,8 +38,17 @@ string const kSearchBaseUrl = "https://www.booking.com/search.html";
|
|||
string const kDeepLinkBaseUrl = "booking://hotel/";
|
||||
string g_BookingUrlForTesting = "";
|
||||
|
||||
unordered_set<string> const kAvailabilityParamsForUniversalLink = {"checkin", "checkout", "room"};
|
||||
unordered_set<string> const kAvailabilityParamsForDeepLink = {"checkin", "checkout"};
|
||||
booking::AvailabilityParams::Filter const kAvailabilityParamsForUniversalLink =
|
||||
{
|
||||
"checkin",
|
||||
"checkout",
|
||||
"room"
|
||||
};
|
||||
booking::AvailabilityParams::Filter const kAvailabilityParamsForDeepLink =
|
||||
{
|
||||
"checkin",
|
||||
"checkout"
|
||||
};
|
||||
|
||||
bool RunSimpleHttpRequest(bool const needAuth, string const & url, string & result)
|
||||
{
|
||||
|
@ -273,9 +281,9 @@ string ApplyAvailabilityParamsDeep(string const & url, AvailabilityParams const
|
|||
{
|
||||
auto p = params.Get(kAvailabilityParamsForDeepLink);
|
||||
|
||||
int const sum = std::accumulate(
|
||||
params.m_rooms.cbegin(), params.m_rooms.cend(), 0,
|
||||
[](int const s, AvailabilityParams::Room const & room) { return s + room.GetAdultsCount(); });
|
||||
auto const sum = std::accumulate(
|
||||
params.m_rooms.cbegin(), params.m_rooms.cend(), 0 /* sum start value */,
|
||||
[](auto const s, auto const & room) { return s + room.GetAdultsCount(); });
|
||||
|
||||
p.emplace_back("numberOfGuests", std::to_string(sum));
|
||||
|
||||
|
@ -319,7 +327,7 @@ string Api::GetBookHotelUrl(string const & baseUrl) const
|
|||
return GetDescriptionUrl(baseUrl) + "#availability";
|
||||
}
|
||||
|
||||
std::string Api::GetDeepLink(std::string const & hotelId) const
|
||||
string Api::GetDeepLink(string const & hotelId) const
|
||||
{
|
||||
ASSERT(!hotelId.empty(), ());
|
||||
|
||||
|
|
|
@ -14,8 +14,12 @@ std::string FormatTime(booking::AvailabilityParams::Time p)
|
|||
return partners_api::FormatTime(p, "%Y-%m-%d");
|
||||
}
|
||||
|
||||
bool Contains(std::unordered_set<std::string> const & filter, std::string const & value)
|
||||
bool IsAcceptedByFilter(booking::AvailabilityParams::Filter const & filter,
|
||||
std::string const & value)
|
||||
{
|
||||
if (filter.empty())
|
||||
return true;
|
||||
|
||||
return filter.find(value) != filter.cend();
|
||||
}
|
||||
} // namespace
|
||||
|
@ -37,7 +41,7 @@ void AvailabilityParams::Room::SetAgeOfChild(int8_t ageOfChild)
|
|||
m_ageOfChild = ageOfChild;
|
||||
}
|
||||
|
||||
int8_t AvailabilityParams::Room::GetAdultsCount() const
|
||||
uint8_t AvailabilityParams::Room::GetAdultsCount() const
|
||||
{
|
||||
return m_adultsCount;
|
||||
}
|
||||
|
@ -69,29 +73,29 @@ bool AvailabilityParams::Room::operator==(AvailabilityParams::Room const & rhs)
|
|||
return !this->operator!=(rhs);
|
||||
}
|
||||
|
||||
url::Params AvailabilityParams::Get(std::unordered_set<std::string> const & filter /* = {} */) const
|
||||
url::Params AvailabilityParams::Get(Filter const & filter /* = {} */) const
|
||||
{
|
||||
url::Params result;
|
||||
|
||||
if (filter.empty() || Contains(filter, "hotel_ids"))
|
||||
if (IsAcceptedByFilter(filter, "hotel_ids"))
|
||||
result.emplace_back("hotel_ids", strings::JoinStrings(m_hotelIds, ','));
|
||||
|
||||
if (filter.empty() || Contains(filter, "checkin"))
|
||||
if (IsAcceptedByFilter(filter, "checkin"))
|
||||
result.emplace_back("checkin", FormatTime(m_checkin));
|
||||
|
||||
if (filter.empty() || Contains(filter, "checkout"))
|
||||
if (IsAcceptedByFilter(filter, "checkout"))
|
||||
result.emplace_back("checkout", FormatTime(m_checkout));
|
||||
|
||||
if (filter.empty() || Contains(filter, "room"))
|
||||
if (IsAcceptedByFilter(filter, "room"))
|
||||
{
|
||||
for (size_t i = 0; i < m_rooms.size(); ++i)
|
||||
result.emplace_back("room" + to_string(i + 1), m_rooms[i].ToString());
|
||||
}
|
||||
|
||||
if (m_minReviewScore != 0.0 && (filter.empty() || Contains(filter, "min_review_score")))
|
||||
if (m_minReviewScore != 0.0 && IsAcceptedByFilter(filter, "min_review_score"))
|
||||
result.emplace_back("min_review_score", to_string(m_minReviewScore));
|
||||
|
||||
if (!m_stars.empty() && (filter.empty() || Contains(filter, "stars")))
|
||||
if (!m_stars.empty() && IsAcceptedByFilter(filter, "stars"))
|
||||
result.emplace_back("stars", strings::JoinStrings(m_stars, ','));
|
||||
|
||||
return result;
|
||||
|
|
|
@ -22,7 +22,7 @@ struct AvailabilityParams
|
|||
void SetAdultsCount(uint8_t adultsCount);
|
||||
void SetAgeOfChild(int8_t ageOfChild);
|
||||
|
||||
int8_t GetAdultsCount() const;
|
||||
uint8_t GetAdultsCount() const;
|
||||
int8_t GetAgeOfChild() const;
|
||||
|
||||
std::string ToString() const;
|
||||
|
@ -41,7 +41,9 @@ struct AvailabilityParams
|
|||
using Rooms = std::vector<Room>;
|
||||
using Stars = std::vector<std::string>;
|
||||
|
||||
base::url::Params Get(std::unordered_set<std::string> const & filter = {}) const;
|
||||
using Filter = std::unordered_set<std::string>;
|
||||
|
||||
base::url::Params Get(Filter const & filter = {}) const;
|
||||
bool IsEmpty() const;
|
||||
bool operator!=(AvailabilityParams const & rhs) const;
|
||||
bool operator==(AvailabilityParams const & rhs) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue