From bfcbd95f3268e4585ad1100e383e4820566630fb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 4 Nov 2016 12:06:53 +0000 Subject: Add support for getting a user's tracked packages --- gentoobrowse-api/api/users.ice | 3 +++ gentoobrowse-api/service/sql/users/tracked.sql | 4 ++++ gentoobrowse-api/service/usersimpl.cpp | 7 +++++++ gentoobrowse-api/service/usersimpl.h | 1 + gentoobrowse-api/unittests/testUsers.cpp | 7 +++++++ 5 files changed, 22 insertions(+) create mode 100644 gentoobrowse-api/service/sql/users/tracked.sql diff --git a/gentoobrowse-api/api/users.ice b/gentoobrowse-api/api/users.ice index d0c37f7..16fa7e2 100644 --- a/gentoobrowse-api/api/users.ice +++ b/gentoobrowse-api/api/users.ice @@ -5,6 +5,8 @@ #include module Gentoo { + sequence PackageIds; + interface Users { User authenticate(string username, string password) throws Slicer::NoRowsReturned; User verify(string username, string verifyguid) throws Slicer::NoRowsReturned; @@ -16,6 +18,7 @@ module Gentoo { void track(int userId, int packageId); void untrack(int userId, int packageId); + PackageIds tracked(int userId); }; }; diff --git a/gentoobrowse-api/service/sql/users/tracked.sql b/gentoobrowse-api/service/sql/users/tracked.sql new file mode 100644 index 0000000..7bf2a8d --- /dev/null +++ b/gentoobrowse-api/service/sql/users/tracked.sql @@ -0,0 +1,4 @@ +SELECT packageid +FROM gentoobrowse.user_packages +WHERE userid = ? +ORDER BY packageid diff --git a/gentoobrowse-api/service/usersimpl.cpp b/gentoobrowse-api/service/usersimpl.cpp index 6aee42d..67a1bd1 100644 --- a/gentoobrowse-api/service/usersimpl.cpp +++ b/gentoobrowse-api/service/usersimpl.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace Gentoo { namespace Service { @@ -75,6 +76,12 @@ Users::untrack(Ice::Int userId, Ice::Int packageId, const Ice::Current &) untrack->bindParamI(1, packageId); untrack->execute(); } + +Gentoo::PackageIds +Users::tracked(Ice::Int userId, const Ice::Current &) +{ + return fetchCache(sql::users::tracked, 10, userId); +} } } diff --git a/gentoobrowse-api/service/usersimpl.h b/gentoobrowse-api/service/usersimpl.h index f97e2ad..ae342a9 100644 --- a/gentoobrowse-api/service/usersimpl.h +++ b/gentoobrowse-api/service/usersimpl.h @@ -21,6 +21,7 @@ class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseC void track(Ice::Int, Ice::Int, const Ice::Current &) override; void untrack(Ice::Int, Ice::Int, const Ice::Current &) override; + Gentoo::PackageIds tracked(Ice::Int, const Ice::Current &) override; }; } } diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp index e4c1ac4..a4567f3 100644 --- a/gentoobrowse-api/unittests/testUsers.cpp +++ b/gentoobrowse-api/unittests/testUsers.cpp @@ -95,6 +95,13 @@ BOOST_AUTO_TEST_CASE( track ) u->track(1, 44473); } +BOOST_AUTO_TEST_CASE( tracked ) +{ + auto ids = u->tracked(1); + BOOST_REQUIRE_EQUAL(4, ids.size()); + BOOST_REQUIRE_EQUAL(44473, ids.front()); +} + BOOST_AUTO_TEST_CASE( untrack ) { u->untrack(1, 44473); -- cgit v1.2.3