Implemented Subsonic's user rating for tracks, albums and artists, fixes #511

This commit is contained in:
emeric
2024-08-30 19:40:15 +02:00
parent cd0e88d28d
commit 29d0610eb2
30 changed files with 991 additions and 5 deletions
+3
View File
@@ -11,6 +11,9 @@ add_library(lmsdatabase SHARED
impl/TrackArtistLink.cpp
impl/TrackFeatures.cpp
impl/TrackList.cpp
impl/RatedArtist.cpp
impl/RatedRelease.cpp
impl/RatedTrack.cpp
impl/Release.cpp
impl/ScanSettings.cpp
impl/Session.cpp
+43 -1
View File
@@ -35,7 +35,7 @@ namespace lms::db
{
namespace
{
static constexpr Version LMS_DATABASE_VERSION{ 63 };
static constexpr Version LMS_DATABASE_VERSION{ 64 };
}
VersionInfo::VersionInfo()
@@ -673,6 +673,47 @@ SELECT
session.getDboSession()->execute("UPDATE scan_settings SET scan_version = scan_version + 1");
}
void migrateFromV63(Session& session)
{
// Add a rated entities
session.getDboSession()->execute(R"(CREATE TABLE IF NOT EXISTS "rated_artist" (
"id" integer primary key autoincrement,
"version" integer not null,
"rating" integer not null,
"last_updated" text,
"artist_id" bigint,
"user_id" bigint,
constraint "fk_rated_artist_artist" foreign key ("artist_id") references "artist" ("id") on delete cascade deferrable initially deferred,
constraint "fk_rated_artist_user" foreign key ("user_id") references "user" ("id") on delete cascade deferrable initially deferred
))");
session.getDboSession()->execute(R"(CREATE TABLE IF NOT EXISTS "rated_release" (
"id" integer primary key autoincrement,
"version" integer not null,
"rating" integer not null,
"last_updated" text,
"release_id" bigint,
"user_id" bigint,
constraint "fk_rated_release_release" foreign key ("release_id") references "release" ("id") on delete cascade deferrable initially deferred,
constraint "fk_rated_release_user" foreign key ("user_id") references "user" ("id") on delete cascade deferrable initially deferred
))");
session.getDboSession()->execute(R"(CREATE TABLE IF NOT EXISTS "rated_track" (
"id" integer primary key autoincrement,
"version" integer not null,
"rating" bigint not null,
"last_updated" text,
"track_id" bigint,
"user_id" bigint,
constraint "fk_rated_track_track" foreign key ("track_id") references "track" ("id") on delete cascade deferrable initially deferred,
constraint "fk_rated_track_user" foreign key ("user_id") references "user" ("id") on delete cascade deferrable initially deferred
))");
// Drop badly named index, will be recreated
session.getDboSession()->execute("DROP INDEX IF EXISTS listen_user_backend_date_time");
}
bool doDbMigration(Session& session)
{
static const std::string outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
@@ -712,6 +753,7 @@ SELECT
{ 60, migrateFromV60 },
{ 61, migrateFromV61 },
{ 62, migrateFromV62 },
{ 63, migrateFromV63 },
};
bool migrationPerformed{};
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2021 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/>.
*/
#include "database/RatedArtist.hpp"
#include <Wt/Dbo/WtSqlTraits.h>
#include "database/Artist.hpp"
#include "database/Session.hpp"
#include "database/User.hpp"
#include "IdTypeTraits.hpp"
#include "Utils.hpp"
namespace lms::db
{
RatedArtist::RatedArtist(ObjectPtr<Artist> artist, ObjectPtr<User> user)
: _artist{ getDboPtr(artist) }
, _user{ getDboPtr(user) }
{
}
RatedArtist::pointer RatedArtist::create(Session& session, ObjectPtr<Artist> artist, ObjectPtr<User> user)
{
return session.getDboSession()->add(std::unique_ptr<RatedArtist>{ new RatedArtist{ artist, user } });
}
std::size_t RatedArtist::getCount(Session& session)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<int>("SELECT COUNT(*) FROM rated_artist"));
}
RatedArtist::pointer RatedArtist::find(Session& session, RatedArtistId id)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<RatedArtist>().where("id = ?").bind(id));
}
RatedArtist::pointer RatedArtist::find(Session& session, ArtistId artistId, UserId userId)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<RatedArtist>().where("artist_id = ?").bind(artistId).where("user_id = ?").bind(userId));
}
void RatedArtist::find(Session& session, const FindParameters& params, std::function<void(const pointer&)> func)
{
session.checkReadTransaction();
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<RatedArtist>>("SELECT r_a FROM rated_artist r_a") };
if (params.user.isValid())
query.where("r_a.user_id = ?").bind(params.user);
utils::forEachQueryRangeResult(query, params.range, func);
}
void RatedArtist::setLastUpdated(const Wt::WDateTime& lastUpdated)
{
_lastUpdated = utils::normalizeDateTime(lastUpdated);
}
} // namespace lms::db
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2021 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/>.
*/
#include "database/RatedRelease.hpp"
#include <Wt/Dbo/WtSqlTraits.h>
#include "database/Release.hpp"
#include "database/Session.hpp"
#include "database/User.hpp"
#include "IdTypeTraits.hpp"
#include "Utils.hpp"
namespace lms::db
{
RatedRelease::RatedRelease(ObjectPtr<Release> release, ObjectPtr<User> user)
: _release{ getDboPtr(release) }
, _user{ getDboPtr(user) }
{
}
RatedRelease::pointer RatedRelease::create(Session& session, ObjectPtr<Release> release, ObjectPtr<User> user)
{
return session.getDboSession()->add(std::unique_ptr<RatedRelease>{ new RatedRelease{ release, user } });
}
std::size_t RatedRelease::getCount(Session& session)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<int>("SELECT COUNT(*) FROM rated_release"));
}
RatedRelease::pointer RatedRelease::find(Session& session, RatedReleaseId id)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<RatedRelease>().where("id = ?").bind(id));
}
RatedRelease::pointer RatedRelease::find(Session& session, ReleaseId releaseId, UserId userId)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<RatedRelease>().where("release_id = ?").bind(releaseId).where("user_id = ?").bind(userId));
}
void RatedRelease::find(Session& session, const FindParameters& params, std::function<void(const pointer&)> func)
{
session.checkReadTransaction();
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<RatedRelease>>("SELECT r_r FROM rated_release r_r") };
if (params.user.isValid())
query.where("r_r.user_id = ?").bind(params.user);
utils::forEachQueryRangeResult(query, params.range, func);
}
void RatedRelease::setLastUpdated(const Wt::WDateTime& lastUpdated)
{
_lastUpdated = utils::normalizeDateTime(lastUpdated);
}
} // namespace lms::db
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2021 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/>.
*/
#include "database/RatedTrack.hpp"
#include <Wt/Dbo/WtSqlTraits.h>
#include "database/Session.hpp"
#include "database/Track.hpp"
#include "database/User.hpp"
#include "IdTypeTraits.hpp"
#include "Utils.hpp"
namespace lms::db
{
RatedTrack::RatedTrack(ObjectPtr<Track> track, ObjectPtr<User> user)
: _track{ getDboPtr(track) }
, _user{ getDboPtr(user) }
{
}
RatedTrack::pointer RatedTrack::create(Session& session, ObjectPtr<Track> track, ObjectPtr<User> user)
{
return session.getDboSession()->add(std::unique_ptr<RatedTrack>{ new RatedTrack{ track, user } });
}
std::size_t RatedTrack::getCount(Session& session)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<int>("SELECT COUNT(*) FROM rated_track"));
}
RatedTrack::pointer RatedTrack::find(Session& session, RatedTrackId id)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<RatedTrack>().where("id = ?").bind(id));
}
RatedTrack::pointer RatedTrack::find(Session& session, TrackId trackId, UserId userId)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<RatedTrack>().where("track_id = ?").bind(trackId).where("user_id = ?").bind(userId));
}
void RatedTrack::find(Session& session, const FindParameters& params, std::function<void(const pointer&)> func)
{
session.checkReadTransaction();
auto query{ session.getDboSession()->query<Wt::Dbo::ptr<RatedTrack>>("SELECT r_t FROM rated_track r_t") };
if (params.user.isValid())
query.where("r_t.user_id = ?").bind(params.user);
utils::forEachQueryRangeResult(query, params.range, func);
}
void RatedTrack::setLastUpdated(const Wt::WDateTime& lastUpdated)
{
_lastUpdated = utils::normalizeDateTime(lastUpdated);
}
} // namespace lms::db
+11 -1
View File
@@ -30,6 +30,9 @@
#include "database/Image.hpp"
#include "database/Listen.hpp"
#include "database/MediaLibrary.hpp"
#include "database/RatedArtist.hpp"
#include "database/RatedRelease.hpp"
#include "database/RatedTrack.hpp"
#include "database/Release.hpp"
#include "database/ScanSettings.hpp"
#include "database/StarredArtist.hpp"
@@ -98,6 +101,9 @@ namespace lms::db
_session.mapClass<Image>("image");
_session.mapClass<Listen>("listen");
_session.mapClass<MediaLibrary>("media_library");
_session.mapClass<RatedArtist>("rated_artist");
_session.mapClass<RatedRelease>("rated_release");
_session.mapClass<RatedTrack>("rated_track");
_session.mapClass<Release>("release");
_session.mapClass<ReleaseType>("release_type");
_session.mapClass<ScanSettings>("scan_settings");
@@ -194,10 +200,14 @@ namespace lms::db
_session.execute("CREATE INDEX IF NOT EXISTS listen_backend_idx ON listen(backend)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_id_idx ON listen(id)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_user_backend_idx ON listen(user_id,backend)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_user_backend_date_time ON listen(user_id, backend, date_time DESC)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_user_backend_date_time_idx ON listen(user_id, backend, date_time DESC)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_track_user_backend_idx ON listen(track_id,user_id,backend)");
_session.execute("CREATE INDEX IF NOT EXISTS listen_user_track_backend_date_time_idx ON listen(user_id,track_id,backend,date_time)");
_session.execute("CREATE INDEX IF NOT EXISTS rated_artist_user_artist_idx ON rated_artist(user_id,artist_id)");
_session.execute("CREATE INDEX IF NOT EXISTS rated_release_user_release_idx ON rated_release(user_id,release_id)");
_session.execute("CREATE INDEX IF NOT EXISTS rated_track_user_track_idx ON rated_track(user_id,track_id)");
_session.execute("CREATE INDEX IF NOT EXISTS release_id_idx ON release(id)");
_session.execute("CREATE INDEX IF NOT EXISTS release_name_idx ON release(name)");
_session.execute("CREATE INDEX IF NOT EXISTS release_name_nocase_idx ON release(name COLLATE NOCASE)");
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 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/>.
*/
#pragma once
#include <Wt/Dbo/Dbo.h>
#include <Wt/WDateTime.h>
#include "database/ArtistId.hpp"
#include "database/Object.hpp"
#include "database/RatedArtistId.hpp"
#include "database/Types.hpp"
#include "database/UserId.hpp"
namespace lms::db
{
class Artist;
class Session;
class User;
class RatedArtist final : public Object<RatedArtist, RatedArtistId>
{
public:
RatedArtist() = default;
struct FindParameters
{
UserId user; // and this user
std::optional<Range> range;
FindParameters& setUser(UserId _user)
{
user = _user;
return *this;
}
FindParameters& setRange(std::optional<Range> _range)
{
range = _range;
return *this;
}
};
// Search utility
static std::size_t getCount(Session& session);
static pointer find(Session& session, RatedArtistId id);
static pointer find(Session& session, ArtistId artistId, UserId userId);
static void find(Session& session, const FindParameters& findParams, std::function<void(const pointer&)> func);
// Accessors
ObjectPtr<Artist> getArtist() const { return _artist; }
ObjectPtr<User> getUser() const { return _user; }
Rating getRating() const { return _rating; }
const Wt::WDateTime& getLastUpdated() const { return _lastUpdated; }
// Setters
void setRating(Rating rating) { _rating = rating; }
void setLastUpdated(const Wt::WDateTime& lastUpdated);
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _rating, "rating");
Wt::Dbo::field(a, _lastUpdated, "last_updated");
Wt::Dbo::belongsTo(a, _artist, "artist", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _user, "user", Wt::Dbo::OnDeleteCascade);
}
private:
friend class Session;
RatedArtist(ObjectPtr<Artist> artist, ObjectPtr<User> user);
static pointer create(Session& session, ObjectPtr<Artist> artist, ObjectPtr<User> user);
Rating _rating{};
Wt::WDateTime _lastUpdated; // when it was rated for the last time
Wt::Dbo::ptr<Artist> _artist;
Wt::Dbo::ptr<User> _user;
};
} // namespace lms::db
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 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/>.
*/
#pragma once
#include "database/IdType.hpp"
LMS_DECLARE_IDTYPE(RatedArtistId)
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 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/>.
*/
#pragma once
#include <Wt/Dbo/Dbo.h>
#include <Wt/WDateTime.h>
#include "database/Object.hpp"
#include "database/RatedReleaseId.hpp"
#include "database/ReleaseId.hpp"
#include "database/Types.hpp"
#include "database/UserId.hpp"
namespace lms::db
{
class Release;
class Session;
class User;
class RatedRelease final : public Object<RatedRelease, RatedReleaseId>
{
public:
RatedRelease() = default;
struct FindParameters
{
UserId user; // and this user
std::optional<Range> range;
FindParameters& setUser(UserId _user)
{
user = _user;
return *this;
}
FindParameters& setRange(std::optional<Range> _range)
{
range = _range;
return *this;
}
};
// Search utility
static std::size_t getCount(Session& session);
static pointer find(Session& session, RatedReleaseId id);
static pointer find(Session& session, ReleaseId releaseId, UserId userId);
static void find(Session& session, const FindParameters& findParams, std::function<void(const pointer&)> func);
// Accessors
ObjectPtr<Release> getRelease() const { return _release; }
ObjectPtr<User> getUser() const { return _user; }
Rating getRating() const { return _rating; }
const Wt::WDateTime& getLastUpdated() const { return _lastUpdated; }
// Setters
void setRating(Rating rating) { _rating = rating; }
void setLastUpdated(const Wt::WDateTime& lastUpdated);
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _rating, "rating");
Wt::Dbo::field(a, _lastUpdated, "last_updated");
Wt::Dbo::belongsTo(a, _release, "release", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _user, "user", Wt::Dbo::OnDeleteCascade);
}
private:
friend class Session;
RatedRelease(ObjectPtr<Release> release, ObjectPtr<User> user);
static pointer create(Session& session, ObjectPtr<Release> release, ObjectPtr<User> user);
Rating _rating{};
Wt::WDateTime _lastUpdated; // when it was rated for the last time
Wt::Dbo::ptr<Release> _release;
Wt::Dbo::ptr<User> _user;
};
} // namespace lms::db
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 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/>.
*/
#pragma once
#include "database/IdType.hpp"
LMS_DECLARE_IDTYPE(RatedReleaseId)
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 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/>.
*/
#pragma once
#include <Wt/Dbo/Dbo.h>
#include <Wt/WDateTime.h>
#include "database/Object.hpp"
#include "database/RatedTrackId.hpp"
#include "database/TrackId.hpp"
#include "database/Types.hpp"
#include "database/UserId.hpp"
namespace lms::db
{
class Track;
class Session;
class User;
class RatedTrack final : public Object<RatedTrack, RatedTrackId>
{
public:
RatedTrack() = default;
struct FindParameters
{
UserId user; // and this user
std::optional<Range> range;
FindParameters& setUser(UserId _user)
{
user = _user;
return *this;
}
FindParameters& setRange(std::optional<Range> _range)
{
range = _range;
return *this;
}
};
// Search utility
static std::size_t getCount(Session& session);
static pointer find(Session& session, RatedTrackId id);
static pointer find(Session& session, TrackId trackId, UserId userId);
static void find(Session& session, const FindParameters& findParams, std::function<void(const pointer&)> func);
// Accessors
ObjectPtr<Track> getTrack() const { return _track; }
ObjectPtr<User> getUser() const { return _user; }
Rating getRating() const { return _rating; }
const Wt::WDateTime& getLastUpdated() const { return _lastUpdated; }
// Setters
void setRating(Rating rating) { _rating = rating; }
void setLastUpdated(const Wt::WDateTime& lastUpdated);
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _rating, "rating");
Wt::Dbo::field(a, _lastUpdated, "last_updated");
Wt::Dbo::belongsTo(a, _track, "track", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _user, "user", Wt::Dbo::OnDeleteCascade);
}
private:
friend class Session;
RatedTrack(ObjectPtr<Track> track, ObjectPtr<User> user);
static pointer create(Session& session, ObjectPtr<Track> track, ObjectPtr<User> user);
Rating _rating{};
Wt::WDateTime _lastUpdated; // when it was rated for the last time
Wt::Dbo::ptr<Track> _track;
Wt::Dbo::ptr<User> _user;
};
} // namespace lms::db
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2024 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/>.
*/
#pragma once
#include "database/IdType.hpp"
LMS_DECLARE_IDTYPE(RatedTrackId)
@@ -22,7 +22,6 @@
#include <Wt/Dbo/Dbo.h>
#include <Wt/WDateTime.h>
#include "core/EnumSet.hpp"
#include "database/Object.hpp"
#include "database/StarredTrackId.hpp"
#include "database/TrackId.hpp"
@@ -196,6 +196,8 @@ namespace lms::db
void visitAllowedAudioBitrates(std::function<void(Bitrate)>);
bool isAudioBitrateAllowed(Bitrate bitrate);
using Rating = int;
enum class ScrobblingBackend
{
Internal = 0,
+3
View File
@@ -8,6 +8,9 @@ add_executable(test-database
Image.cpp
Listen.cpp
Migration.cpp
RatedArtist.cpp
RatedRelease.cpp
RatedTrack.cpp
Release.cpp
StarredArtist.cpp
StarredRelease.cpp
+6
View File
@@ -23,6 +23,9 @@
#include "database/Db.hpp"
#include "database/Directory.hpp"
#include "database/Image.hpp"
#include "database/RatedArtist.hpp"
#include "database/RatedRelease.hpp"
#include "database/RatedTrack.hpp"
#include "database/StarredArtist.hpp"
#include "database/StarredRelease.hpp"
#include "database/StarredTrack.hpp"
@@ -335,6 +338,9 @@ VALUES
EXPECT_FALSE(Directory::find(session, DirectoryId{}));
EXPECT_FALSE(Image::find(session, ImageId{}));
EXPECT_FALSE(Listen::find(session, ListenId{}));
EXPECT_FALSE(RatedArtist::find(session, RatedArtistId{}));
EXPECT_FALSE(RatedRelease::find(session, RatedReleaseId{}));
EXPECT_FALSE(RatedTrack::find(session, RatedTrackId{}));
EXPECT_FALSE(Release::find(session, ReleaseId{}));
EXPECT_FALSE(StarredArtist::find(session, StarredArtistId{}));
EXPECT_FALSE(StarredRelease::find(session, StarredReleaseId{}));
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2021 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/>.
*/
#include "database/RatedArtist.hpp"
#include "Common.hpp"
namespace lms::db::tests
{
using ScopedRatedArtist = ScopedEntity<db::RatedArtist>;
TEST_F(DatabaseFixture, RatedArtist)
{
ScopedArtist artist{ session, "MyArtist" };
ScopedUser user{ session, "MyUser" };
ScopedUser user2{ session, "MyUser2" };
{
auto transaction{ session.createReadTransaction() };
auto starredArtist{ RatedArtist::find(session, artist->getId(), user->getId()) };
EXPECT_FALSE(starredArtist);
EXPECT_EQ(RatedArtist::getCount(session), 0);
auto artists{ Artist::findIds(session, Artist::FindParameters{}) };
EXPECT_EQ(artists.results.size(), 1);
}
ScopedRatedArtist ratedArtist{ session, artist.lockAndGet(), user.lockAndGet() };
{
auto transaction{ session.createReadTransaction() };
auto gotArtist{ RatedArtist::find(session, artist->getId(), user->getId()) };
EXPECT_EQ(gotArtist->getId(), ratedArtist->getId());
EXPECT_EQ(gotArtist->getRating(), 0);
EXPECT_EQ(RatedArtist::getCount(session), 1);
}
}
} // namespace lms::db::tests
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2021 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/>.
*/
#include "database/RatedRelease.hpp"
#include "Common.hpp"
namespace lms::db::tests
{
using ScopedRatedRelease = ScopedEntity<db::RatedRelease>;
TEST_F(DatabaseFixture, RatedRelease)
{
ScopedRelease release{ session, "MyRelease" };
ScopedUser user{ session, "MyUser" };
ScopedUser user2{ session, "MyUser2" };
{
auto transaction{ session.createReadTransaction() };
auto starredRelease{ RatedRelease::find(session, release->getId(), user->getId()) };
EXPECT_FALSE(starredRelease);
EXPECT_EQ(RatedRelease::getCount(session), 0);
auto releases{ Release::findIds(session, Release::FindParameters{}) };
EXPECT_EQ(releases.results.size(), 1);
}
ScopedRatedRelease ratedRelease{ session, release.lockAndGet(), user.lockAndGet() };
{
auto transaction{ session.createReadTransaction() };
auto gotRelease{ RatedRelease::find(session, release->getId(), user->getId()) };
EXPECT_EQ(gotRelease->getId(), ratedRelease->getId());
EXPECT_EQ(gotRelease->getRating(), 0);
EXPECT_EQ(RatedRelease::getCount(session), 1);
}
}
} // namespace lms::db::tests
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2021 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/>.
*/
#include "database/RatedTrack.hpp"
#include "Common.hpp"
namespace lms::db::tests
{
using ScopedRatedTrack = ScopedEntity<db::RatedTrack>;
TEST_F(DatabaseFixture, RatedTrack)
{
ScopedTrack track{ session };
ScopedUser user{ session, "MyUser" };
ScopedUser user2{ session, "MyUser2" };
{
auto transaction{ session.createReadTransaction() };
auto starredTrack{ RatedTrack::find(session, track->getId(), user->getId()) };
EXPECT_FALSE(starredTrack);
EXPECT_EQ(RatedTrack::getCount(session), 0);
auto tracks{ Track::findIds(session, Track::FindParameters{}) };
EXPECT_EQ(tracks.results.size(), 1);
}
ScopedRatedTrack ratedTrack{ session, track.lockAndGet(), user.lockAndGet() };
{
auto transaction{ session.createReadTransaction() };
auto gotTrack{ RatedTrack::find(session, track->getId(), user->getId()) };
EXPECT_EQ(gotTrack->getId(), ratedTrack->getId());
EXPECT_EQ(gotTrack->getRating(), 0);
EXPECT_EQ(RatedTrack::getCount(session), 1);
}
}
} // namespace lms::db::tests