diff --git a/ugc/CMakeLists.txt b/ugc/CMakeLists.txt index 20baffbe60..f1a77d90bb 100644 --- a/ugc/CMakeLists.txt +++ b/ugc/CMakeLists.txt @@ -4,6 +4,7 @@ set( SRC api.cpp api.hpp + types.hpp ) add_library(${PROJECT_NAME} ${SRC}) diff --git a/ugc/api.cpp b/ugc/api.cpp index 12ffd23e15..c8e47b9cca 100644 --- a/ugc/api.cpp +++ b/ugc/api.cpp @@ -10,25 +10,30 @@ namespace ugc { Api::Api(Index const & index) : m_index(index) {} -void Api::GetStaticUGC(FeatureID const & id, Callback callback) +void Api::GetUGC(FeatureID const & id, UGCCallback callback) { - m_thread.Push([=]() { GetStaticUGCImpl(id, callback); }); + m_thread.Push([=]() { GetUGCImpl(id, callback); }); } -void Api::GetDynamicUGC(FeatureID const & id, Callback callback) +void Api::GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback) { - m_thread.Push([=]() { GetDynamicUGCImpl(id, callback); }); + m_thread.Push([=]() { GetUGCUpdateImpl(id, callback); }); } -void Api::GetStaticUGCImpl(FeatureID const & /* id */, Callback callback) +void Api::GetUGCImpl(FeatureID const & /* id */, UGCCallback callback) { // TODO (@y, @mgsergio): retrieve static UGC - GetPlatform().RunOnGuiThread(callback); + UGC ugc(Rating({}, {}), {}, {}); + GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); }); } -void Api::GetDynamicUGCImpl(FeatureID const & /* id */, Callback callback) +void Api::GetUGCUpdateImpl(FeatureID const & /* id */, UGCUpdateCallback callback) { // TODO (@y, @mgsergio): retrieve dynamic UGC - GetPlatform().RunOnGuiThread(callback); + UGCUpdate ugc(Rating({}, {}), + Attribute({}, {}), + ReviewAbuse({}, {}), + ReviewFeedback({}, {})); + GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); }); } } // namespace ugc diff --git a/ugc/api.hpp b/ugc/api.hpp index 8b13853eae..eb6f731f39 100644 --- a/ugc/api.hpp +++ b/ugc/api.hpp @@ -2,6 +2,8 @@ #include "base/worker_thread.hpp" +#include "ugc/types.hpp" + #include class Index; @@ -12,17 +14,17 @@ namespace ugc class Api { public: - // TODO (@y, @mgsergio): replace void() by void(UGC const &). - using Callback = std::function; + using UGCCallback = std::function; + using UGCUpdateCallback = std::function; explicit Api(Index const & index); - void GetStaticUGC(FeatureID const & id, Callback callback); - void GetDynamicUGC(FeatureID const & id, Callback callback); + void GetUGC(FeatureID const & id, UGCCallback callback); + void GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback); private: - void GetStaticUGCImpl(FeatureID const & id, Callback callback); - void GetDynamicUGCImpl(FeatureID const & id, Callback callback); + void GetUGCImpl(FeatureID const & id, UGCCallback callback); + void GetUGCUpdateImpl(FeatureID const & id, UGCUpdateCallback callback); Index const & m_index; base::WorkerThread m_thread; diff --git a/ugc/types.hpp b/ugc/types.hpp new file mode 100644 index 0000000000..1a4aa3b956 --- /dev/null +++ b/ugc/types.hpp @@ -0,0 +1,180 @@ +#pragma once + +#include "indexer/feature_decl.hpp" + +#include +#include +#include +#include +#include + +namespace ugc +{ +struct RatingRecord +{ + RatingRecord(std::string const & key, float const value) + : m_key(key) + , m_value(value) + { + } + + std::string m_key; + float m_value; +}; + +struct Rating +{ + Rating(std::vector const & ratings, float const aggValue) + : m_ratings(ratings) + , m_aggValue(aggValue) + { + } + + std::vector m_ratings; + float m_aggValue; +}; + +class UID +{ +public: + UID(uint64_t const hi, uint64_t const lo) + : m_hi(hi) + , m_lo(lo) + { + } + + std::string ToString() const; + +private: + uint64_t m_hi; + uint64_t m_lo; +}; + +struct Author +{ + Author(UID const & uid, std::string const & name) + : m_uid(uid) + , m_name(name) + { + } + + UID m_uid; + std::string m_name; +}; + +struct Text +{ + Text(std::string const & text, uint8_t const lang) + : m_text(text) + , m_lang(lang) + { + } + + std::string m_text; + uint8_t m_lang; +}; + +struct Review +{ + using ReviewId = uint32_t; + + Review(Text const & text, Author const & author, + float const rating, bool const evaluation, + std::chrono::time_point const & time) + : m_text(text) + , m_author(author) + , m_rating(rating) + , m_evaluation(evaluation) + , m_time(time) + { + } + + ReviewId m_id; + + Text m_text; + Author m_author; + // A rating of a review itself. It is accumulated from other users likes or dislakes. + float m_rating; + // A positive/negative evaluation given to a place by a user. + bool m_evaluation; + std::chrono::time_point m_time; +}; + +struct Attribute +{ + Attribute(std::string const & key, std::string const & value) + : m_key(key) + , m_value(value) + { + } + + std::string m_key; + std::string m_value; +}; + +// struct Media +// { +// std::unique_ptr m_data; +// }; + +struct UGC +{ + UGC(Rating const & rating, + std::vector const & reviews, + std::vector const & attributes) + : m_rating(rating) + , m_reviews(reviews) + , m_attributes(attributes) + { + } + + Rating m_rating; + std::vector m_reviews; + std::vector m_attributes; + // Media m_media; +}; + +struct ReviewFeedback +{ + ReviewFeedback(bool const evaluation, + std::chrono::time_point const time) + : m_evaluation(evaluation) + , m_time(time) + { + } + + bool m_evaluation; + std::chrono::time_point m_time; +}; + +struct ReviewAbuse +{ + ReviewAbuse(std::string const & reason, + std::chrono::time_point const & time) + : m_reason(reason) + , m_time(time) + { + } + + std::string m_reason; + std::chrono::time_point m_time; +}; + +struct UGCUpdate +{ + UGCUpdate(Rating ratings, Attribute attribute, + ReviewAbuse abuses, ReviewFeedback feedbacks) + : m_ratings(ratings) + , m_attribute(attribute) + , m_abuses(abuses) + , m_feedbacks(feedbacks) + { + } + + Rating m_ratings; + Attribute m_attribute; + + ReviewAbuse m_abuses; + ReviewFeedback m_feedbacks; +}; +} // namespace ugc