API Subsonic: first working version, still WIP (missing commands, no authentication)
This commit is contained in:
@@ -61,10 +61,30 @@ Release::create(Wt::Dbo::Session& session, const std::string& name, const std::s
|
||||
return session.add(std::make_unique<Release>(name, MBID));
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::getAll(Wt::Dbo::Session& session, int offset, int size)
|
||||
std::size_t
|
||||
Release::getCount(Wt::Dbo::Session& session)
|
||||
{
|
||||
Wt::Dbo::collection<pointer> res = session.find<Release>().offset(offset).limit(size);
|
||||
Wt::Dbo::collection<pointer> releases {session.find<Release>()};
|
||||
return releases.size();
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> offset, boost::optional<std::size_t> size)
|
||||
{
|
||||
Wt::Dbo::collection<pointer> res = session.find<Release>()
|
||||
.offset(offset ? static_cast<int>(*offset) : -1)
|
||||
.limit(size ? static_cast<int>(*size) : - 1);
|
||||
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::getAllRandom(Wt::Dbo::Session& session, boost::optional<std::size_t> size)
|
||||
{
|
||||
Wt::Dbo::collection<pointer> res = session.find<Release>()
|
||||
.limit(size ? static_cast<int>(*size) : - 1)
|
||||
.orderBy("RANDOM()");
|
||||
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
@@ -77,13 +97,14 @@ Release::getAllOrphans(Wt::Dbo::Session& session)
|
||||
}
|
||||
|
||||
std::vector<Release::pointer>
|
||||
Release::getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, int limit)
|
||||
Release::getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, boost::optional<std::size_t> offset, boost::optional<std::size_t> limit)
|
||||
{
|
||||
Wt::Dbo::collection<Release::pointer> res = session.query<Release::pointer>("SELECT r from release r INNER JOIN track t ON r.id = t.release_id")
|
||||
.where("t.file_added > ?").bind(after)
|
||||
.groupBy("r.id")
|
||||
.orderBy("t.file_added DESC")
|
||||
.limit(limit);
|
||||
.offset(offset ? static_cast<int>(*offset) : -1)
|
||||
.limit(limit ? static_cast<int>(*limit) : -1);
|
||||
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
@@ -44,12 +44,14 @@ class Release : public Wt::Dbo::Dbo<Release>
|
||||
Release(const std::string& name, const std::string& MBID = "");
|
||||
|
||||
// Accessors
|
||||
static std::size_t getCount(Wt::Dbo::Session& session);
|
||||
static pointer getByMBID(Wt::Dbo::Session& session, const std::string& MBID);
|
||||
static std::vector<pointer> getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||
static pointer getById(Wt::Dbo::Session& session, IdType id);
|
||||
static std::vector<pointer> getAllOrphans(Wt::Dbo::Session& session); // no track related
|
||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session, int offset, int size);
|
||||
static std::vector<pointer> getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, int size = 1);
|
||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> offset = {}, boost::optional<std::size_t> size = {});
|
||||
static std::vector<pointer> getAllRandom(Wt::Dbo::Session& session, boost::optional<std::size_t> size = {});
|
||||
static std::vector<pointer> getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, boost::optional<std::size_t> offset = {}, boost::optional<std::size_t> size = {});
|
||||
|
||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session,
|
||||
const std::set<IdType>& clusters, // at least one track that belongs to these clusters
|
||||
|
||||
+14
-2
@@ -38,9 +38,21 @@ _filePath( p.string() )
|
||||
}
|
||||
|
||||
Wt::Dbo::collection< Track::pointer >
|
||||
Track::getAll(Wt::Dbo::Session& session)
|
||||
Track::getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> limit)
|
||||
{
|
||||
return session.find<Track>();
|
||||
int size {limit ? static_cast<int>(*limit) : -1};
|
||||
|
||||
return session.find<Track>().limit(size);
|
||||
}
|
||||
|
||||
std::vector<Track::pointer>
|
||||
Track::getAllRandom(Wt::Dbo::Session& session, boost::optional<std::size_t> limit)
|
||||
{
|
||||
Wt::Dbo::collection<Track::pointer> res {session.find<Track>()
|
||||
.limit(limit ? static_cast<int>(*limit) : -1)
|
||||
.orderBy("RANDOM()")};
|
||||
|
||||
return std::vector<Track::pointer>(std::cbegin(res), std::cend(res));
|
||||
}
|
||||
|
||||
std::vector<IdType>
|
||||
|
||||
@@ -63,7 +63,8 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
int size,
|
||||
bool& moreExpected);
|
||||
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> limit = {});
|
||||
static std::vector<pointer> getAllRandom(Wt::Dbo::Session& session, boost::optional<std::size_t> limit = {});
|
||||
static std::vector<IdType> getAllIds(Wt::Dbo::Session& session); // nested transaction
|
||||
static std::vector<boost::filesystem::path> getAllPaths(Wt::Dbo::Session& session); // nested transaction
|
||||
static std::vector<pointer> getMBIDDuplicates(Wt::Dbo::Session& session);
|
||||
|
||||
Reference in New Issue
Block a user