API Subsonic: better support, added genre

This commit is contained in:
emeric
2019-04-03 23:53:41 +02:00
parent ab2ed24f75
commit 3ee937a409
10 changed files with 332 additions and 98 deletions
+15 -9
View File
@@ -63,9 +63,13 @@ Artist::create(Wt::Dbo::Session& session, const std::string& name, const std::st
}
std::vector<Artist::pointer>
Artist::getAll(Wt::Dbo::Session& session, int offset, int size)
Artist::getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> offset, boost::optional<std::size_t> size)
{
Wt::Dbo::collection<pointer> res = session.find<Artist>().offset(offset).limit(size);
Wt::Dbo::collection<pointer> res = session.find<Artist>()
.offset(offset ? static_cast<int>(*offset) : -1)
.limit(size ? static_cast<int>(*size) : -1)
.orderBy("name COLLATE NOCASE");
return std::vector<pointer>(res.begin(), res.end());
}
@@ -123,15 +127,17 @@ std::vector<Artist::pointer>
Artist::getByFilter(Wt::Dbo::Session& session,
const std::set<IdType>& clusters,
const std::vector<std::string> keywords,
int offset, int size, bool& moreResults)
boost::optional<std::size_t> offset,
boost::optional<std::size_t> size,
bool& moreResults)
{
Wt::Dbo::collection<Artist::pointer> collection = getQuery(session, clusters, keywords)
.limit(size != -1 ? size + 1 : -1)
.offset(offset);
.limit(size ? static_cast<int>(*size) + 1 : -1)
.offset(offset ? static_cast<int>(*offset) : -1);
auto res = std::vector<pointer>(collection.begin(), collection.end());
auto res {std::vector<pointer>(collection.begin(), collection.end())};
if (size != -1 && res.size() == static_cast<std::size_t>(size) + 1)
if (size && res.size() == static_cast<std::size_t>(*size) + 1)
{
moreResults = true;
res.pop_back();
@@ -143,13 +149,13 @@ Artist::getByFilter(Wt::Dbo::Session& session,
}
std::vector<Artist::pointer>
Artist::getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, int limit)
Artist::getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, boost::optional<std::size_t> limit)
{
Wt::Dbo::collection<Artist::pointer> res = session.query<Artist::pointer>("SELECT a from artist a INNER JOIN track_artist t_a ON t_a.artist_id = a.id INNER JOIN track t ON t.id = t_a.track_id")
.where("t.file_added > ?").bind(after)
.groupBy("a.id")
.orderBy("t.file_added DESC")
.limit(limit);
.limit(limit ? static_cast<int>(*limit) : -1);
return std::vector<pointer>(res.begin(), res.end());
}
+6 -4
View File
@@ -22,6 +22,8 @@
#include <string>
#include <vector>
#include <boost/optional.hpp>
#include <Wt/WDateTime.h>
#include <Wt/Dbo/Dbo.h>
@@ -51,13 +53,13 @@ class Artist : public Wt::Dbo::Dbo<Artist>
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session,
const std::set<IdType>& clusters, // at least one track that belongs to these clusters
const std::vector<std::string> keywords, // name must match all of these keywords
int offset,
int size,
boost::optional<std::size_t> offset,
boost::optional<std::size_t> size,
bool& moreExpected);
static std::vector<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, 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> getAllOrphans(Wt::Dbo::Session& session); // No track related
static std::vector<pointer> getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, int size = 1);
static std::vector<pointer> getLastAdded(Wt::Dbo::Session& session, Wt::WDateTime after, boost::optional<std::size_t> size = {});
// Accessors
const std::string& getName(void) const { return _name; }
+16 -6
View File
@@ -73,7 +73,8 @@ Release::getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> offset,
{
Wt::Dbo::collection<pointer> res = session.find<Release>()
.offset(offset ? static_cast<int>(*offset) : -1)
.limit(size ? static_cast<int>(*size) : - 1);
.limit(size ? static_cast<int>(*size) : - 1)
.orderBy("name COLLATE NOCASE");
return std::vector<pointer>(res.begin(), res.end());
}
@@ -150,19 +151,28 @@ getQuery(Wt::Dbo::Session& session,
return query;
}
std::vector<Release::pointer>
Release::getByFilter(Wt::Dbo::Session& session, const std::set<IdType>& clusterIds)
{
bool moreResults;
return getByFilter(session, clusterIds, {}, {}, {}, moreResults);
}
std::vector<Release::pointer>
Release::getByFilter(Wt::Dbo::Session& session,
const std::set<IdType>& clusterIds,
const std::vector<std::string> keywords,
int offset, int size, bool& moreResults)
boost::optional<std::size_t> offset,
boost::optional<std::size_t> size,
bool& moreResults)
{
Wt::Dbo::collection<pointer> collection = getQuery(session, clusterIds, keywords)
.limit(size != -1 ? size + 1 : -1)
.offset(offset);
.limit(size ? static_cast<int>(*size) + 1 : -1)
.offset(offset ? static_cast<int>(*offset) : -1);
auto res = std::vector<pointer>(collection.begin(), collection.end());
auto res {std::vector<pointer>(collection.begin(), collection.end())};
if (size != -1 && res.size() == static_cast<std::size_t>(size) + 1)
if (size && res.size() == static_cast<std::size_t>(*size) + 1)
{
moreResults = true;
res.pop_back();
+3 -2
View File
@@ -53,11 +53,12 @@ class Release : public Wt::Dbo::Dbo<Release>
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);
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session,
const std::set<IdType>& clusters, // at least one track that belongs to these clusters
const std::vector<std::string> keywords, // name must match all of these keywords
int offset,
int size,
boost::optional<std::size_t> offset,
boost::optional<std::size_t> size,
bool& moreExpected);
std::vector<Wt::Dbo::ptr<Track>> getTracks(const std::set<IdType>& clusters = std::set<IdType>()) const;
+7 -5
View File
@@ -202,15 +202,17 @@ std::vector<Track::pointer>
Track::getByFilter(Wt::Dbo::Session& session,
const std::set<IdType>& clusterIds,
const std::vector<std::string> keywords,
int offset, int size, bool& moreResults)
boost::optional<std::size_t> offset,
boost::optional<std::size_t> size,
bool& moreResults)
{
Wt::Dbo::collection<pointer> collection = getQuery(session, clusterIds, keywords)
.limit(size != -1 ? size + 1 : -1)
.offset(offset);
.limit(size ? static_cast<int>(*size) + 1 : -1)
.offset(offset ? static_cast<int>(*offset) : -1);
auto res = std::vector<pointer>(collection.begin(), collection.end());
if (size != -1 && res.size() == static_cast<std::size_t>(size) + 1)
if (size && res.size() == static_cast<std::size_t>(*size) + 1)
{
moreResults = true;
res.pop_back();
@@ -227,7 +229,7 @@ Track::getByFilter(Wt::Dbo::Session& session,
{
bool moreResults;
return getByFilter(session, clusters, std::vector<std::string>(), -1, -1, moreResults);
return getByFilter(session, clusters, std::vector<std::string>{}, -1, -1, moreResults);
}
void
+2 -2
View File
@@ -59,8 +59,8 @@ class Track : public Wt::Dbo::Dbo<Track>
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session,
const std::set<IdType>& clusters, // tracks that belong to these clusters
const std::vector<std::string> keywords, // name must match all of these keywords
int offset,
int size,
boost::optional<std::size_t> offset,
boost::optional<std::size_t> size,
bool& moreExpected);
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> limit = {});