From ea317076af06aa3e45633005ba4dec52480de108 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 4 Oct 2016 00:27:26 +0100 Subject: Add methods for getting repo details --- gentoobrowse-api/api/portage.ice | 3 +++ gentoobrowse-api/domain/portage-models.ice | 9 ++++++++ gentoobrowse-api/service/portageimpl.cpp | 14 ++++++++++++ gentoobrowse-api/service/portageimpl.h | 3 +++ .../service/sql/portage/getRepositories.sql | 3 +++ .../service/sql/portage/getRepository.sql | 3 +++ gentoobrowse-api/unittests/testPortage.cpp | 25 ++++++++++++++++++++++ 7 files changed, 60 insertions(+) create mode 100644 gentoobrowse-api/service/sql/portage/getRepositories.sql create mode 100644 gentoobrowse-api/service/sql/portage/getRepository.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 98b39fe..1f211fd 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -36,6 +36,9 @@ module Gentoo { idempotent NewsItem getNewsItem(string newsid) throws Slicer::NoRowsReturned; idempotent News getNewsSearch(string query); idempotent News getNewsRecent(int items); + + idempotent Repository getRepository(int id) throws Slicer::NoRowsReturned; + idempotent Repositories getRepositories(); }; }; diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index 5ee9b76..dd57551 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -107,6 +107,13 @@ module Gentoo { int ebuilds; }; + struct Repository { + ["slicer:db:pkey"] + int repoid; + string name; + string path; + }; + [ "slicer:element:category" ] sequence Categories; [ "slicer:element:package" ] @@ -123,6 +130,8 @@ module Gentoo { sequence Syncs; [ "slicer:element:mask" ] sequence Masks; + [ "slicer:element:repo" ] + sequence Repositories; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index 689b173..a12c8d7 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include namespace Gentoo { namespace Service { @@ -215,6 +217,18 @@ Portage::getNewsRecent(Ice::Int items, const Ice::Current &) { return fetchCache(sql::portage::getNewsRecent, 30, items); } + +Gentoo::Repository +Portage::getRepository(Ice::Int id, const Ice::Current &) +{ + return fetchCache(sql::portage::getRepository, 30, id); +} + +Gentoo::Repositories +Portage::getRepositories(const Ice::Current &) +{ + return fetchCache(sql::portage::getRepositories, 30); +} } } diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 8810068..42d57e4 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -43,6 +43,9 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab 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; + + Gentoo::Repository getRepository(Ice::Int, const Ice::Current &) override; + Gentoo::Repositories getRepositories(const Ice::Current &) override; }; } } diff --git a/gentoobrowse-api/service/sql/portage/getRepositories.sql b/gentoobrowse-api/service/sql/portage/getRepositories.sql new file mode 100644 index 0000000..3236628 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getRepositories.sql @@ -0,0 +1,3 @@ +SELECT repoid, name, path +FROM gentoobrowse.repos +ORDER BY repoid diff --git a/gentoobrowse-api/service/sql/portage/getRepository.sql b/gentoobrowse-api/service/sql/portage/getRepository.sql new file mode 100644 index 0000000..fc12ff8 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getRepository.sql @@ -0,0 +1,3 @@ +SELECT repoid, name, path +FROM gentoobrowse.repos +WHERE repoid = ? diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 135ae7f..c408a83 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -382,5 +382,30 @@ BOOST_AUTO_TEST_CASE( getNewsRecent ) BOOST_REQUIRE_EQUAL("2015-10-07", ns.back()->posted); } +BOOST_AUTO_TEST_CASE( getRepository ) +{ + auto r = p->getRepository(17); + BOOST_REQUIRE_EQUAL(17, r.repoid); + BOOST_REQUIRE_EQUAL("gentoo", r.name); + BOOST_REQUIRE_EQUAL("/usr/portage", r.path); +} + +BOOST_AUTO_TEST_CASE( getRepositoryMissing ) +{ + BOOST_REQUIRE_THROW(p->getRepository(1), Slicer::NoRowsReturned); +} + +BOOST_AUTO_TEST_CASE( getRepositories ) +{ + auto rs = p->getRepositories(); + BOOST_REQUIRE_EQUAL(2, rs.size()); + BOOST_REQUIRE_EQUAL(17, rs.front().repoid); + BOOST_REQUIRE_EQUAL("gentoo", rs.front().name); + BOOST_REQUIRE_EQUAL("/usr/portage", rs.front().path); + BOOST_REQUIRE_EQUAL(18, rs.back().repoid); + BOOST_REQUIRE_EQUAL("RandomLAN", rs.back().name); + BOOST_REQUIRE_EQUAL("/home/randomdan/dev/portage", rs.back().path); +} + BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3