[promo_api] inject promo api into discovery manager

This commit is contained in:
Arsentiy Milchakov 2019-05-23 15:13:21 +03:00 committed by Tatiana Yan
parent 5dc96147be
commit 0d005a09d0
5 changed files with 28 additions and 14 deletions

View file

@ -12,7 +12,8 @@ enum class ItemType
Attractions,
Cafes,
Hotels,
LocalExperts
LocalExperts,
Promo
};
using ItemTypes = std::vector<ItemType>;

View file

@ -16,6 +16,7 @@ std::string GetQuery(discovery::ItemType const type)
case discovery::ItemType::Attractions: return "attractions ";
case discovery::ItemType::Cafes: return "cafe ";
case discovery::ItemType::LocalExperts: return "";
case discovery::ItemType::Promo: return "";
}
UNREACHABLE();
@ -27,6 +28,7 @@ namespace discovery
Manager::Manager(DataSource const & dataSource, APIs const & apis)
: m_dataSource(dataSource)
, m_searchApi(apis.m_search)
, m_promoApi(apis.m_promo)
, m_localsApi(apis.m_locals)
{
}

View file

@ -8,6 +8,7 @@
#include "partners_api/booking_api.hpp"
#include "partners_api/locals_api.hpp"
#include "partners_api/promo_api.hpp"
#include "platform/marketing_service.hpp"
#include "platform/platform.hpp"
@ -32,12 +33,13 @@ class Manager final
public:
struct APIs
{
APIs(SearchAPI & search, locals::Api & locals)
: m_search(search), m_locals(locals)
APIs(SearchAPI & search, promo::Api & promo, locals::Api & locals)
: m_search(search), m_promo(promo), m_locals(locals)
{
}
SearchAPI & m_search;
promo::Api & m_promo;
locals::Api & m_locals;
};
@ -109,6 +111,19 @@ public:
});
break;
}
case ItemType::Promo:
{
m_promoApi.GetCityGallery(params.m_viewportCenter, [this, requestId, onResult, onError, type](promo::CityGallery const & cityGallery)
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
if (cityGallery.empty())
onError(requestId, type);
else
onResult(requestId, cityGallery);
});
break;
}
}
}
return requestId;
@ -121,6 +136,7 @@ private:
DataSource const & m_dataSource;
SearchAPI & m_searchApi;
promo::Api & m_promoApi;
locals::Api & m_localsApi;
uint32_t m_requestCounter = 0;
ThreadChecker m_threadChecker;

View file

@ -96,17 +96,11 @@ void GetPromoCityGalleryImpl(std::string const & baseUrl, std::string const & id
ASSERT(!baseUrl.empty(), ());
ASSERT_EQUAL(baseUrl.back(), '/', ());
if (id.empty())
{
GetPlatform().RunTask(Platform::Thread::Gui, [cb]() { cb({}); });
return;
}
CityGallery result;
std::string httpResult;
if (!WebApi::GetCityGalleryById(baseUrl, id, languages::GetCurrentNorm(), httpResult))
if (id.empty() || !WebApi::GetCityGalleryById(baseUrl, id, languages::GetCurrentNorm(), httpResult))
{
GetPlatform().RunTask(Platform::Thread::Gui, [cb]() { cb({}); });
cb({});
return;
}
@ -120,7 +114,7 @@ void GetPromoCityGalleryImpl(std::string const & baseUrl, std::string const & id
result.clear();
}
GetPlatform().RunTask(Platform::Thread::Gui, [ cb, result = move(result) ]() { cb(result); });
cb(std::move(result));
}
} // namespace

View file

@ -2,9 +2,10 @@
#include "metrics/eye.hpp"
#include "platform/safe_callback.hpp"
#include "geometry/point2d.hpp"
#include <functional>
#include <memory>
#include <string>
#include <vector>
@ -42,7 +43,7 @@ public:
std::string const & lang, std::string & result);
};
using CityGalleryCallback = std::function<void(CityGallery const & gallery)>;
using CityGalleryCallback = platform::SafeCallback<void(CityGallery const & gallery)>;
class Api : public eye::Subscriber
{