Adding basic radio mode
This commit is contained in:
@@ -57,6 +57,24 @@ Cluster::getById(Wt::Dbo::Session& session, IdType id)
|
||||
return session.find<Cluster>().where("id = ?").bind(id);
|
||||
}
|
||||
|
||||
void
|
||||
Cluster::addTrack(Wt::Dbo::ptr<Track> track)
|
||||
{
|
||||
_tracks.insert(track);
|
||||
}
|
||||
|
||||
std::vector<Wt::Dbo::ptr<Track>>
|
||||
Cluster::getTracks(int offset, int limit) const
|
||||
{
|
||||
Wt::Dbo::collection<Track::pointer> res = session()->query<Track::pointer>("select t from track t INNER JOIN cluster c ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id")
|
||||
.where("c.id = ?").bind(self()->id())
|
||||
.offset(offset)
|
||||
.limit(limit);
|
||||
|
||||
return std::vector<Wt::Dbo::ptr<Track>>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
|
||||
ClusterType::ClusterType(std::string name)
|
||||
: _name(name)
|
||||
{
|
||||
@@ -117,11 +135,6 @@ ClusterType::getClusters() const
|
||||
return std::vector<Cluster::pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
void
|
||||
Cluster::addTrack(Wt::Dbo::ptr<Track> track)
|
||||
{
|
||||
_tracks.insert(track);
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ class Cluster : public Wt::Dbo::Dbo<Cluster>
|
||||
const std::string& getName(void) const { return _name; }
|
||||
Wt::Dbo::ptr<ClusterType> getType() const { return _clusterType; }
|
||||
const Wt::Dbo::collection<Wt::Dbo::ptr<Track>>& getTracks() const { return _tracks; }
|
||||
std::size_t getTrackCount() const { return _tracks.size(); }
|
||||
std::vector<Wt::Dbo::ptr<Track>> getTracks(int offset, int limit) const;
|
||||
|
||||
void addTrack(Wt::Dbo::ptr<Track> track);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "Cluster.hpp"
|
||||
#include "User.hpp"
|
||||
#include "Track.hpp"
|
||||
|
||||
@@ -50,7 +51,7 @@ PlaylistEntry::PlaylistEntry()
|
||||
}
|
||||
|
||||
PlaylistEntry::pointer
|
||||
PlaylistEntry::getById(Wt::Dbo::Session& session, PlaylistEntry::id_type id)
|
||||
PlaylistEntry::getById(Wt::Dbo::Session& session, IdType id)
|
||||
{
|
||||
return session.find<PlaylistEntry>().where("id = ?").bind(id);
|
||||
}
|
||||
@@ -133,4 +134,31 @@ Playlist::getCount() const
|
||||
return _entries.size();
|
||||
}
|
||||
|
||||
std::vector<Wt::Dbo::ptr<Cluster>>
|
||||
Playlist::getClusters() const
|
||||
{
|
||||
assert(session());
|
||||
assert(IdIsValid(self()->id()));
|
||||
|
||||
Wt::Dbo::collection<Cluster::pointer> res = session()->query<Cluster::pointer>("SELECT c from cluster c INNER JOIN track t ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN playlist_entry p_e ON p_e.track_id = t.id INNER JOIN playlist p ON p.id = p_e.playlist_id")
|
||||
.where("p.id = ?").bind(self()->id())
|
||||
.groupBy("c.id")
|
||||
.orderBy("COUNT(c.id) DESC");
|
||||
|
||||
return std::vector<Wt::Dbo::ptr<Cluster>>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
bool
|
||||
Playlist::hasTrack(IdType trackId) const
|
||||
{
|
||||
assert(session());
|
||||
assert(IdIsValid(self()->id()));
|
||||
|
||||
Wt::Dbo::collection<PlaylistEntry::pointer> res = session()->query<PlaylistEntry::pointer>("SELECT p_e from playlist_entry p_e INNER JOIN playlist p ON p_e.playlist_id = p.id")
|
||||
.where("p_e.track_id = ?").bind(trackId);
|
||||
|
||||
return res.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -23,11 +23,14 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
class PlaylistEntry;
|
||||
class User;
|
||||
class Track;
|
||||
class Cluster;
|
||||
|
||||
class Playlist : public Wt::Dbo::Dbo<Playlist>
|
||||
{
|
||||
@@ -56,6 +59,11 @@ class Playlist : public Wt::Dbo::Dbo<Playlist>
|
||||
Wt::Dbo::ptr<PlaylistEntry> getEntry(std::size_t pos) const;
|
||||
std::vector<Wt::Dbo::ptr<PlaylistEntry>> getEntries(int offset, int size, bool& moreResults) const;
|
||||
|
||||
// Get clusters, order by occurence
|
||||
std::vector<Wt::Dbo::ptr<Cluster>> getClusters() const;
|
||||
|
||||
bool hasTrack(IdType trackId) const;
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
@@ -79,12 +87,11 @@ class PlaylistEntry
|
||||
public:
|
||||
|
||||
using pointer = Wt::Dbo::ptr<PlaylistEntry>;
|
||||
using id_type = Wt::Dbo::dbo_traits<PlaylistEntry>::IdType;
|
||||
|
||||
PlaylistEntry();
|
||||
PlaylistEntry(Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist);
|
||||
|
||||
static pointer getById(Wt::Dbo::Session& session, id_type id);
|
||||
static pointer getById(Wt::Dbo::Session& session, IdType id);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist);
|
||||
|
||||
Reference in New Issue
Block a user