diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-21 05:03:44 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-21 05:03:44 +0000 |
commit | 840c72cd85b265360fa31126ff4c3fa209f604c0 (patch) | |
tree | 94c62e5cbe9947d1700b7ef6dcf92b32ca667ef2 | |
parent | Add schema as dependency of tests (diff) | |
download | gentoobrowse-api-840c72cd85b265360fa31126ff4c3fa209f604c0.tar.bz2 gentoobrowse-api-840c72cd85b265360fa31126ff4c3fa209f604c0.tar.xz gentoobrowse-api-840c72cd85b265360fa31126ff4c3fa209f604c0.zip |
Add methods for getting recent news and searching news.
-rw-r--r-- | gentoobrowse-api/api/portage.ice | 2 | ||||
-rw-r--r-- | gentoobrowse-api/domain/portage-models.ice | 1 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.cpp | 18 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.h | 2 | ||||
-rw-r--r-- | gentoobrowse-api/service/sql/portage/getNewsRecent.sql | 4 | ||||
-rw-r--r-- | gentoobrowse-api/service/sql/portage/getNewsSearch.sql | 4 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testPortage.cpp | 18 |
7 files changed, 47 insertions, 2 deletions
diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 7e1eb43..9479eff 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -21,6 +21,8 @@ module Gentoo { idempotent SearchResultBugs getBugsSearch(string query); idempotent NewsItem getNewsItem(string newsid); + idempotent News getNewsSearch(string query); + idempotent News getNewsRecent(int items); }; }; diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index b5a75c9..ca018e8 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -84,6 +84,7 @@ module Gentoo { sequence<Ebuild> Ebuilds; sequence<Bug> Bugs; sequence<ChangeLogEntry> ChangeLog; + sequence<NewsItem> News; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index b199934..408d467 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -14,6 +14,8 @@ #include <sql/portage/getPackageBugs.h> #include <sql/portage/getBugsSearch.h> #include <sql/portage/getNewsItem.h> +#include <sql/portage/getNewsSearch.h> +#include <sql/portage/getNewsRecent.h> Portage::Portage(AdHoc::ResourcePool<DB::Connection> & d) : AbstractDatabaseClient(d) @@ -101,12 +103,24 @@ Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) Gentoo::SearchResultBugs Portage::getBugsSearch(const std::string & query, const Ice::Current &) { - return fetch<Gentoo::SearchResultBugs, sql::getBugsSearch>(query, query); + return fetch<Gentoo::SearchResultBugs, sql::getBugsSearch>(query, query); } Gentoo::NewsItemPtr Portage::getNewsItem(const std::string & id, const Ice::Current &) { - return fetch<Gentoo::NewsItemPtr, sql::getNewsItem>(id); + return fetch<Gentoo::NewsItemPtr, sql::getNewsItem>(id); +} + +Gentoo::News +Portage::getNewsSearch(const std::string & query, const Ice::Current &) +{ + return fetch<Gentoo::News, sql::getNewsSearch>(query); +} + +Gentoo::News +Portage::getNewsRecent(Ice::Int items, const Ice::Current &) +{ + return fetch<Gentoo::News, sql::getNewsRecent>(items); } diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 9588095..9a8246d 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -27,6 +27,8 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, AbstractDatabaseClient { Gentoo::SearchResultBugs getBugsSearch(const std::string & query, const Ice::Current &) override; Gentoo::NewsItemPtr getNewsItem(const std::string &, const Ice::Current &) override; + Gentoo::News getNewsSearch(const std::string &, const Ice::Current &) override; + Gentoo::News getNewsRecent(Ice::Int, const Ice::Current &) override; }; #endif diff --git a/gentoobrowse-api/service/sql/portage/getNewsRecent.sql b/gentoobrowse-api/service/sql/portage/getNewsRecent.sql new file mode 100644 index 0000000..a70c6b0 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getNewsRecent.sql @@ -0,0 +1,4 @@ +SELECT n.newsid, n.title, n.posted, n.authorname, n.authoremail, n.body, n.atomspec, n.urls +FROM gentoobrowse.news n +ORDER BY n.posted DESC, n.newsid +LIMIT ? diff --git a/gentoobrowse-api/service/sql/portage/getNewsSearch.sql b/gentoobrowse-api/service/sql/portage/getNewsSearch.sql new file mode 100644 index 0000000..b67ac99 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getNewsSearch.sql @@ -0,0 +1,4 @@ +SELECT n.newsid, n.title, n.posted, n.authorname, n.authoremail, n.body, n.atomspec, n.urls +FROM gentoobrowse.news n +WHERE gentoobrowse.newsfts(n) @@ plainto_tsquery(?) +ORDER BY n.posted DESC, n.newsid diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index c5c85f6..271ff34 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -241,6 +241,24 @@ BOOST_AUTO_TEST_CASE( getNewsItem ) BOOST_REQUIRE_EQUAL("http://ispras.linuxbase.org/index.php/ABI_compliance_checker", n2->urls.front()); } +BOOST_AUTO_TEST_CASE( getNewsSearch ) +{ + auto ns = p->getNewsSearch("gcc"); + BOOST_REQUIRE_EQUAL(5, ns.size()); + BOOST_REQUIRE_EQUAL("Or you might see linkage failures with \"std::__cxx11::string\" in the output.", ns.front()->body[1]); + BOOST_REQUIRE_EQUAL("These are signs that you need to rebuild packages using the new C++ ABI. You can quickly do so by using revdep-rebuild (from gentoolkit) like so: # revdep-rebuild --library 'libstdc\\+\\+\\.so\\.6' -- --exclude gcc", ns.front()->body[2]); + BOOST_REQUIRE_EQUAL("2015-10-22T00:00:00", ns.front()->posted); + BOOST_REQUIRE_EQUAL("2009-01-04T00:00:00", ns.back()->posted); +} + +BOOST_AUTO_TEST_CASE( getNewsRecent ) +{ + auto ns = p->getNewsRecent(3); + BOOST_REQUIRE_EQUAL(3, ns.size()); + BOOST_REQUIRE_EQUAL("2015-10-22T00:00:00", ns.front()->posted); + BOOST_REQUIRE_EQUAL("2015-10-07T00:00:00", ns.back()->posted); +} + BOOST_AUTO_TEST_CASE( cache ) { auto c1 = p->getCategory(311, Ice::Current()); |