diff --git a/src/lms/ui/LmsApplication.cpp b/src/lms/ui/LmsApplication.cpp index 6662d59a..aba96fab 100644 --- a/src/lms/ui/LmsApplication.cpp +++ b/src/lms/ui/LmsApplication.cpp @@ -277,7 +277,10 @@ LmsApplication::finalize() Wt::WLink LmsApplication::createArtistLink(Database::Artist::pointer artist) { - return Wt::WLink {Wt::LinkType::InternalPath, "/artist/" + std::to_string(artist.id())}; + if (const auto mbid {artist->getMBID()}) + return Wt::WLink {Wt::LinkType::InternalPath, "/artist/mbid/" + std::string {mbid->getAsString()}}; + else + return Wt::WLink {Wt::LinkType::InternalPath, "/artist/" + std::to_string(artist.id())}; } std::unique_ptr @@ -298,7 +301,10 @@ LmsApplication::createArtistAnchor(Database::Artist::pointer artist, bool addTex Wt::WLink LmsApplication::createReleaseLink(Database::Release::pointer release) { - return Wt::WLink {Wt::LinkType::InternalPath, "/release/" + std::to_string(release.id())}; + if (const auto mbid {release->getMBID()}) + return Wt::WLink {Wt::LinkType::InternalPath, "/release/mbid/" + std::string {mbid->getAsString()}}; + else + return Wt::WLink {Wt::LinkType::InternalPath, "/release/" + std::to_string(release.id())}; } std::unique_ptr diff --git a/src/lms/ui/LmsApplicationException.hpp b/src/lms/ui/LmsApplicationException.hpp index 61ef2dbd..0671a6c4 100644 --- a/src/lms/ui/LmsApplicationException.hpp +++ b/src/lms/ui/LmsApplicationException.hpp @@ -34,19 +34,19 @@ class LmsApplicationException : public LmsException class ArtistNotFoundException : public LmsApplicationException { public: - ArtistNotFoundException(Database::IdType artistId) : LmsApplicationException {Wt::WString::tr("Lms.Error.artist-not-found").arg(artistId)} {} + ArtistNotFoundException() : LmsApplicationException {Wt::WString::tr("Lms.Error.artist-not-found")} {} }; class ReleaseNotFoundException : public LmsApplicationException { public: - ReleaseNotFoundException(Database::IdType releaseId) : LmsApplicationException {Wt::WString::tr("Lms.Error.release-not-found").arg(releaseId)} {} + ReleaseNotFoundException() : LmsApplicationException {Wt::WString::tr("Lms.Error.release-not-found")} {} }; class UserNotFoundException : public LmsApplicationException { public: - UserNotFoundException(Database::IdType userId) : LmsApplicationException {Wt::WString::tr("Lms.Error.user-not-found").arg(userId)} {} + UserNotFoundException() : LmsApplicationException {Wt::WString::tr("Lms.Error.user-not-found")} {} }; class UserNotAllowedException : public LmsApplicationException diff --git a/src/lms/ui/admin/UserView.cpp b/src/lms/ui/admin/UserView.cpp index 4d76dfd4..2d4c7ab6 100644 --- a/src/lms/ui/admin/UserView.cpp +++ b/src/lms/ui/admin/UserView.cpp @@ -84,7 +84,7 @@ class UserModel : public Wt::WFormModel // Update user Database::User::pointer user {Database::User::getById(LmsApp->getDbSession(), *_userId)}; if (!user) - throw UserNotFoundException {*_userId}; + throw UserNotFoundException {}; if (_authPasswordService && !valueText(PasswordField).empty()) _authPasswordService->setPassword(LmsApp->getDbSession(), user.id(), valueText(PasswordField).toUTF8()); @@ -117,7 +117,7 @@ class UserModel : public Wt::WFormModel const Database::User::pointer user {Database::User::getById(LmsApp->getDbSession(), *_userId)}; if (!user) - throw UserNotFoundException {*_userId}; + throw UserNotFoundException {}; else if (user == LmsApp->getUser()) throw UserNotAllowedException {}; } @@ -215,7 +215,7 @@ UserView::refreshView() const Database::User::pointer user {Database::User::getById(LmsApp->getDbSession(), *userId)}; if (!user) - throw UserNotFoundException {*userId}; + throw UserNotFoundException {}; t->bindString("title", Wt::WString::tr("Lms.Admin.User.user-edit").arg(user->getLoginName()), Wt::TextFormat::Plain); t->setCondition("if-has-last-login", true); diff --git a/src/lms/ui/explore/ArtistView.cpp b/src/lms/ui/explore/ArtistView.cpp index 79dbfc9f..68b428d6 100644 --- a/src/lms/ui/explore/ArtistView.cpp +++ b/src/lms/ui/explore/ArtistView.cpp @@ -64,6 +64,26 @@ Artist::Artist(Filters* filters) refreshView(); } +static +std::optional +extractArtistIdFromInternalPath() +{ + if (wApp->internalPathMatches("/artist/mbid/")) + { + const auto mbid {UUID::fromString(wApp->internalPathNextPart("/artist/mbid/"))}; + if (mbid) + { + auto transaction {LmsApp->getDbSession().createSharedTransaction()}; + if (const Database::Artist::pointer artist {Database::Artist::getByMBID(LmsApp->getDbSession(), *mbid)}) + return artist.id(); + } + + return std::nullopt; + } + + return StringUtils::readAs(wApp->internalPathNextPart("/artist/")); +} + void Artist::refreshView() { @@ -72,9 +92,9 @@ Artist::refreshView() clear(); - const auto artistId {StringUtils::readAs(wApp->internalPathNextPart("/artist/"))}; + const auto artistId {extractArtistIdFromInternalPath()}; if (!artistId) - throw ArtistNotFoundException {*artistId}; + throw ArtistNotFoundException {}; const auto similarArtistIds {Service::get()->getSimilarArtists(LmsApp->getDbSession(), *artistId, @@ -85,7 +105,7 @@ Artist::refreshView() const Database::Artist::pointer artist {Database::Artist::getById(LmsApp->getDbSession(), *artistId)}; if (!artist) - throw ArtistNotFoundException {*artistId}; + throw ArtistNotFoundException {}; refreshLinks(artist); refreshSimilarArtists(similarArtistIds); diff --git a/src/lms/ui/explore/ReleaseView.cpp b/src/lms/ui/explore/ReleaseView.cpp index 35ee0e4d..cc6d0f23 100644 --- a/src/lms/ui/explore/ReleaseView.cpp +++ b/src/lms/ui/explore/ReleaseView.cpp @@ -67,6 +67,27 @@ Release::Release(Filters* filters) refreshView(); } +static +std::optional +extractReleaseIdFromInternalPath() +{ + if (wApp->internalPathMatches("/release/mbid/")) + { + const auto mbid {UUID::fromString(wApp->internalPathNextPart("/release/mbid/"))}; + if (mbid) + { + auto transaction {LmsApp->getDbSession().createSharedTransaction()}; + if (const Database::Release::pointer release {Database::Release::getByMBID(LmsApp->getDbSession(), *mbid)}) + return release.id(); + } + + return std::nullopt; + } + + return StringUtils::readAs(wApp->internalPathNextPart("/release/")); +} + + void Release::refreshView() { @@ -75,9 +96,9 @@ Release::refreshView() clear(); - const auto releaseId {StringUtils::readAs(wApp->internalPathNextPart("/release/"))}; + const auto releaseId {extractReleaseIdFromInternalPath()}; if (!releaseId) - throw ReleaseNotFoundException {*releaseId}; + throw ReleaseNotFoundException {}; auto similarReleasesIds {Service::get()->getSimilarReleases(LmsApp->getDbSession(), *releaseId, 6)}; @@ -85,7 +106,7 @@ Release::refreshView() const Database::Release::pointer release {Database::Release::getById(LmsApp->getDbSession(), *releaseId)}; if (!release) - throw ReleaseNotFoundException {*releaseId}; + throw ReleaseNotFoundException {}; refreshCopyright(release); refreshLinks(release);