Squashed commit of the following:
commit 997c1138f549766d797f1ba6da26e1e8394387e2 Author: emeric <itmfr@yahoo.fr> Date: Sat Jan 10 17:50:20 2015 +0100 Implemented save, load and delete playlists commit bee08a16b544bb21785c45f083ab7c10e65bfa6e Author: emeric <itmfr@yahoo.fr> Date: Thu Jan 8 23:46:43 2015 +0100 Reworked the database code layout in order to add playlists
This commit is contained in:
@@ -27,12 +27,6 @@
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
// Db types
|
||||
#include "AudioTypes.hpp"
|
||||
#include "VideoTypes.hpp"
|
||||
#include "MediaDirectory.hpp"
|
||||
#include "User.hpp"
|
||||
|
||||
#include "DatabaseHandler.hpp"
|
||||
|
||||
namespace Database {
|
||||
@@ -85,6 +79,8 @@ _dbBackend( db.string() )
|
||||
_session.setConnection(_dbBackend);
|
||||
_session.mapClass<Database::Genre>("genre");
|
||||
_session.mapClass<Database::Track>("track");
|
||||
_session.mapClass<Database::Playlist>("playlist");
|
||||
_session.mapClass<Database::PlaylistEntry>("playlist_entry");
|
||||
_session.mapClass<Database::Video>("video");
|
||||
_session.mapClass<Database::MediaDirectory>("media_directory");
|
||||
_session.mapClass<Database::MediaDirectorySettings>("media_directory_settings");
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
#include <Wt/Auth/Login>
|
||||
#include <Wt/Auth/PasswordService>
|
||||
|
||||
#include "User.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
typedef Wt::Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
|
||||
typedef Wt::Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
|
||||
|
||||
// Session living class handling the database and the login
|
||||
class Handler
|
||||
@@ -44,8 +44,8 @@ class Handler
|
||||
|
||||
Wt::Dbo::Session& getSession() { return _session; }
|
||||
|
||||
User::pointer getCurrentUser(); // get the current user, may return empty
|
||||
User::pointer getUser(const Wt::Auth::User& authUser); // Get or create the given user
|
||||
Wt::Dbo::ptr<User> getCurrentUser(); // get the current user, may return empty
|
||||
Wt::Dbo::ptr<User> getUser(const Wt::Auth::User& authUser); // Get or create the given user
|
||||
|
||||
Wt::Auth::AbstractUserDatabase& getUserDatabase();
|
||||
Wt::Auth::Login& getLogin() { return _login; }
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "MediaDirectory.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
|
||||
@@ -17,22 +17,76 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "AudioTypes.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
Playlist::Playlist()
|
||||
: _public(false)
|
||||
: _isPublic(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Playlist::Playlist(std::string name, Wt::Dbo::ptr<User> user, bool isPublic)
|
||||
: _public(isPublic),
|
||||
Playlist::Playlist(std::string name, bool isPublic, Wt::Dbo::ptr<User> user)
|
||||
: _name(name),
|
||||
_isPublic(isPublic),
|
||||
_user(user)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Playlist::pointer
|
||||
Playlist::create(Wt::Dbo::Session& session, std::string name, bool isPublic, Wt::Dbo::ptr<User> user)
|
||||
{
|
||||
return session.add( new Playlist(name, isPublic, user) );
|
||||
}
|
||||
|
||||
PlaylistEntry::PlaylistEntry()
|
||||
: _pos(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Playlist::pointer
|
||||
Playlist::get(Wt::Dbo::Session& session, std::string name, Wt::Dbo::ptr<User> user)
|
||||
{
|
||||
return session.find<Playlist>().where("name = ? AND user_id = ?").bind(name).bind(user.id());
|
||||
}
|
||||
|
||||
std::vector<Playlist::pointer>
|
||||
Playlist::get(Wt::Dbo::Session& session, Wt::Dbo::ptr<User> user)
|
||||
{
|
||||
Wt::Dbo::collection<Playlist::pointer> res = session.find<Playlist>().where("user_id = ?").bind(user.id()).orderBy("name");
|
||||
|
||||
return std::vector<Playlist::pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
PlaylistEntry::PlaylistEntry(Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist, int pos)
|
||||
: _pos(pos),
|
||||
_track(track),
|
||||
_playlist(playlist)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PlaylistEntry::pointer
|
||||
PlaylistEntry::create(Wt::Dbo::Session& session, Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist, int pos)
|
||||
{
|
||||
return session.add( new PlaylistEntry( track, playlist, pos) );
|
||||
}
|
||||
|
||||
std::vector<Track::id_type>
|
||||
PlaylistEntry::getEntries(Wt::Dbo::Session& session, Playlist::pointer playlist)
|
||||
{
|
||||
typedef Wt::Dbo::collection<pointer> Entries;
|
||||
|
||||
Entries entries = session.find<PlaylistEntry>().where("playlist_id = ?").bind(playlist.id()).orderBy("pos");
|
||||
|
||||
std::vector<Track::id_type> res;
|
||||
for (Entries::iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
res.push_back((*it)->getTrack().id());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DATABASE_PLAYLIST_HPP
|
||||
#define DATABASE_PLAYLIST_HPP
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
|
||||
namespace Database {
|
||||
|
||||
class PlaylistEntry;
|
||||
class User;
|
||||
class Track;
|
||||
|
||||
class Playlist
|
||||
{
|
||||
public:
|
||||
typedef Wt::Dbo::ptr<Playlist> pointer;
|
||||
|
||||
Playlist();
|
||||
Playlist(std::string name, bool isPublic, Wt::Dbo::ptr<User> user);
|
||||
|
||||
// Search utility
|
||||
static pointer get(Wt::Dbo::Session& session, std::string name, Wt::Dbo::ptr<User> user);
|
||||
|
||||
// ordered by name
|
||||
static std::vector<pointer> get(Wt::Dbo::Session& session, Wt::Dbo::ptr<User> user);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, std::string name, bool isPublic, Wt::Dbo::ptr<User> user);
|
||||
|
||||
// Accessors
|
||||
std::string getName() const { return _name; }
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _name, "name");
|
||||
Wt::Dbo::field(a, _isPublic, "public");
|
||||
Wt::Dbo::belongsTo(a, _user, "user", Wt::Dbo::OnDeleteCascade);
|
||||
Wt::Dbo::hasMany(a, _entries, Wt::Dbo::ManyToOne, "playlist");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string _name;
|
||||
bool _isPublic;
|
||||
Wt::Dbo::ptr<User> _user;
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<PlaylistEntry> > _entries;
|
||||
|
||||
};
|
||||
|
||||
class PlaylistEntry
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Wt::Dbo::ptr<PlaylistEntry> pointer;
|
||||
|
||||
PlaylistEntry();
|
||||
PlaylistEntry(Wt::Dbo::ptr<Track> rack, Wt::Dbo::ptr<Playlist> playlist, int position);
|
||||
|
||||
// Search utility
|
||||
|
||||
// Get the position ordered track id list
|
||||
static std::vector<Track::id_type> getEntries(Wt::Dbo::Session& session,Wt::Dbo::ptr<Playlist> playlist);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist, int position);
|
||||
|
||||
// Accesors
|
||||
Wt::Dbo::ptr<Track> getTrack() const { return _track; }
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _pos, "pos");
|
||||
Wt::Dbo::belongsTo(a, _track, "track", Wt::Dbo::OnDeleteCascade);
|
||||
Wt::Dbo::belongsTo(a, _playlist, "playlist", Wt::Dbo::OnDeleteCascade);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
int _pos;
|
||||
Wt::Dbo::ptr<Track> _track;
|
||||
Wt::Dbo::ptr<Playlist> _playlist;
|
||||
};
|
||||
|
||||
} // namespace Database
|
||||
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "SqlQuery.hpp"
|
||||
|
||||
#include "AudioTypes.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ struct SearchFilter
|
||||
};
|
||||
|
||||
class Track;
|
||||
class PlaylistEntry;
|
||||
|
||||
class Genre
|
||||
{
|
||||
@@ -174,6 +175,7 @@ class Track
|
||||
Wt::Dbo::field(a, _fileChecksum, "checksum");
|
||||
Wt::Dbo::field(a, _hasCover, "has_cover");
|
||||
Wt::Dbo::hasMany(a, _genres, Wt::Dbo::ManyToMany, "track_genre", "", Wt::Dbo::OnDeleteCascade);
|
||||
Wt::Dbo::hasMany(a, _playlistEntries, Wt::Dbo::ManyToOne, "track");
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -198,10 +200,15 @@ class Track
|
||||
boost::posix_time::ptime _fileLastWrite;
|
||||
bool _hasCover;
|
||||
|
||||
Wt::Dbo::collection< Genre::pointer > _genres; // Tracks that belong to this genre
|
||||
Wt::Dbo::collection< Genre::pointer > _genres; // Genres that are related to this track
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<PlaylistEntry> > _playlistEntries;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace database
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Emeric Poupon
|
||||
* Copyright (C) 2015 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
@@ -17,23 +17,11 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// header file aimed to ease database class declarations
|
||||
|
||||
#include "AudioTypes.hpp"
|
||||
#include "Track.hpp"
|
||||
#include "Playlist.hpp"
|
||||
#include "Video.hpp"
|
||||
#include "MediaDirectory.hpp"
|
||||
#include "User.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
PlaylistEntry::PlaylistEntry()
|
||||
: _position(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PlaylistEntry::PlaylistEntry(Wt::Dbo::ptr<Track> track, Wt::Dbo::ptr<Playlist> playlist)
|
||||
: _position(0),
|
||||
_track(track),
|
||||
_playlist(playlist)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
@@ -17,13 +17,10 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "User.hpp"
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
|
||||
// must be ordered
|
||||
const std::vector<std::size_t>
|
||||
User::audioBitrates =
|
||||
@@ -140,7 +137,6 @@ User::getMaxVideoBitrate(void) const
|
||||
return videoBitrates.back();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Database
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
#ifndef DATABASE_USER_HPP
|
||||
#define DATABASE_USER_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Auth/Dbo/AuthInfo>
|
||||
|
||||
namespace Database {
|
||||
@@ -28,6 +30,8 @@ namespace Database {
|
||||
class User;
|
||||
typedef Wt::Auth::Dbo::AuthInfo<User> AuthInfo;
|
||||
|
||||
class Playlist;
|
||||
|
||||
class User {
|
||||
|
||||
public:
|
||||
@@ -68,6 +72,7 @@ class User {
|
||||
Wt::Dbo::field(a, _isAdmin, "admin");
|
||||
Wt::Dbo::field(a, _audioBitrate, "audio_bitrate");
|
||||
Wt::Dbo::field(a, _videoBitrate, "video_bitrate");
|
||||
Wt::Dbo::hasMany(a, _playlists, Wt::Dbo::ManyToOne, "user");
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -87,6 +92,8 @@ class User {
|
||||
int _audioBitrate;
|
||||
int _videoBitrate;
|
||||
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Playlist> > _playlists;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Databas'
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "VideoTypes.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user