diff --git a/Roadie.Api.Services/ServiceBase.cs b/Roadie.Api.Services/ServiceBase.cs index fe00827..1220cdd 100644 --- a/Roadie.Api.Services/ServiceBase.cs +++ b/Roadie.Api.Services/ServiceBase.cs @@ -499,8 +499,7 @@ namespace Roadie.Api.Services }; } - protected async Task> ToggleArtistFavorite(Guid artistId, ApplicationUser user, - bool isFavorite) + protected async Task> ToggleArtistFavorite(Guid artistId, ApplicationUser user, bool isFavorite) { var artist = DbContext.Artists .Include(x => x.Genres) @@ -536,8 +535,7 @@ namespace Roadie.Api.Services }; } - protected async Task> ToggleReleaseDisliked(Guid releaseId, ApplicationUser user, - bool isDisliked) + protected async Task> ToggleReleaseDisliked(Guid releaseId, ApplicationUser user, bool isDisliked) { var release = DbContext.Releases .Include(x => x.Artist) @@ -547,9 +545,11 @@ namespace Roadie.Api.Services .Include("Medias.Tracks") .Include("Medias.Tracks.TrackArtist") .FirstOrDefault(x => x.RoadieId == releaseId); - if (release == null) return new OperationResult(true, $"Invalid Release Id [{releaseId}]"); - var userRelease = - DbContext.UserReleases.FirstOrDefault(x => x.ReleaseId == release.Id && x.UserId == user.Id); + if (release == null) + { + return new OperationResult(true, $"Invalid Release Id [{releaseId}]"); + } + var userRelease = DbContext.UserReleases.FirstOrDefault(x => x.ReleaseId == release.Id && x.UserId == user.Id); if (userRelease == null) { userRelease = new data.UserRelease @@ -590,9 +590,11 @@ namespace Roadie.Api.Services .Include("Medias.Tracks") .Include("Medias.Tracks.TrackArtist") .FirstOrDefault(x => x.RoadieId == releaseId); - if (release == null) return new OperationResult(true, $"Invalid Release Id [{releaseId}]"); - var userRelease = - DbContext.UserReleases.FirstOrDefault(x => x.ReleaseId == release.Id && x.UserId == user.Id); + if (release == null) + { + return new OperationResult(true, $"Invalid Release Id [{releaseId}]"); + } + var userRelease = DbContext.UserReleases.FirstOrDefault(x => x.ReleaseId == release.Id && x.UserId == user.Id); if (userRelease == null) { userRelease = new data.UserRelease @@ -622,8 +624,7 @@ namespace Roadie.Api.Services }; } - protected async Task> ToggleTrackDisliked(Guid trackId, ApplicationUser user, - bool isDisliked) + protected async Task> ToggleTrackDisliked(Guid trackId, ApplicationUser user, bool isDisliked) { var track = DbContext.Tracks .Include(x => x.ReleaseMedia) @@ -631,7 +632,10 @@ namespace Roadie.Api.Services .Include(x => x.ReleaseMedia.Release.Artist) .Include(x => x.TrackArtist) .FirstOrDefault(x => x.RoadieId == trackId); - if (track == null) return new OperationResult(true, $"Invalid Track Id [{trackId}]"); + if (track == null) + { + return new OperationResult(true, $"Invalid Track Id [{trackId}]"); + } var userTrack = DbContext.UserTracks.FirstOrDefault(x => x.TrackId == track.Id && x.UserId == user.Id); if (userTrack == null) { @@ -663,8 +667,7 @@ namespace Roadie.Api.Services }; } - protected async Task> ToggleTrackFavorite(Guid trackId, ApplicationUser user, - bool isFavorite) + protected async Task> ToggleTrackFavorite(Guid trackId, ApplicationUser user, bool isFavorite) { var track = DbContext.Tracks .Include(x => x.ReleaseMedia) @@ -672,7 +675,10 @@ namespace Roadie.Api.Services .Include(x => x.ReleaseMedia.Release.Artist) .Include(x => x.TrackArtist) .FirstOrDefault(x => x.RoadieId == trackId); - if (track == null) return new OperationResult(true, $"Invalid Track Id [{trackId}]"); + if (track == null) + { + return new OperationResult(true, $"Invalid Track Id [{trackId}]"); + } var userTrack = DbContext.UserTracks.FirstOrDefault(x => x.TrackId == track.Id && x.UserId == user.Id); if (userTrack == null) { @@ -697,6 +703,8 @@ namespace Roadie.Api.Services CacheManager.ClearRegion(track.ReleaseMedia.Release.CacheRegion); CacheManager.ClearRegion(track.ReleaseMedia.Release.Artist.CacheRegion); + Logger.LogDebug($"ToggleTrackFavorite: User `{ user }`, Track `{ track }`, isFavorite: [{ isFavorite }]"); + return new OperationResult { IsSuccess = true, diff --git a/Roadie.Api.Services/SubsonicService.cs b/Roadie.Api.Services/SubsonicService.cs index f38e2f1..2d28406 100644 --- a/Roadie.Api.Services/SubsonicService.cs +++ b/Roadie.Api.Services/SubsonicService.cs @@ -2340,13 +2340,13 @@ namespace Roadie.Api.Services }; } - private async Task> ToggleArtistStar(Guid artistId, ApplicationUser user, - bool starred) + private async Task> ToggleArtistStar(Guid artistId, ApplicationUser user, bool starred) { var r = await ToggleArtistFavorite(artistId, user, starred); if (r.IsNotFoundResult) - return new subsonic.SubsonicOperationResult(subsonic.ErrorCodes.TheRequestedDataWasNotFound, - $"Invalid Artist Id [{artistId}]"); + { + return new subsonic.SubsonicOperationResult(subsonic.ErrorCodes.TheRequestedDataWasNotFound, $"Invalid Artist Id [{artistId}]"); + } return new subsonic.SubsonicOperationResult { IsSuccess = r.IsSuccess, @@ -2354,13 +2354,13 @@ namespace Roadie.Api.Services }; } - private async Task> ToggleReleaseStar(Guid releaseId, - ApplicationUser user, bool starred) + private async Task> ToggleReleaseStar(Guid releaseId, ApplicationUser user, bool starred) { var r = await ToggleReleaseFavorite(releaseId, user, starred); if (r.IsNotFoundResult) - return new subsonic.SubsonicOperationResult(subsonic.ErrorCodes.TheRequestedDataWasNotFound, - $"Invalid Release Id [{releaseId}]"); + { + return new subsonic.SubsonicOperationResult(subsonic.ErrorCodes.TheRequestedDataWasNotFound, $"Invalid Release Id [{releaseId}]"); + } return new subsonic.SubsonicOperationResult { IsSuccess = r.IsSuccess, @@ -2368,13 +2368,13 @@ namespace Roadie.Api.Services }; } - private async Task> ToggleTrackStar(Guid trackId, ApplicationUser user, - bool starred) + private async Task> ToggleTrackStar(Guid trackId, ApplicationUser user, bool starred) { var r = await ToggleTrackFavorite(trackId, user, starred); if (r.IsNotFoundResult) - return new subsonic.SubsonicOperationResult(subsonic.ErrorCodes.TheRequestedDataWasNotFound, - $"Invalid Track Id [{trackId}]"); + { + return new subsonic.SubsonicOperationResult(subsonic.ErrorCodes.TheRequestedDataWasNotFound, $"Invalid Track Id [{trackId}]"); + } return new subsonic.SubsonicOperationResult { IsSuccess = r.IsSuccess, diff --git a/Roadie.Api.Services/UserService.cs b/Roadie.Api.Services/UserService.cs index a32aff4..c7a1466 100644 --- a/Roadie.Api.Services/UserService.cs +++ b/Roadie.Api.Services/UserService.cs @@ -172,9 +172,15 @@ namespace Roadie.Api.Services public async Task> SetArtistBookmark(Guid artistId, User roadieUser, bool isBookmarked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } var artist = GetArtist(artistId); - if (artist == null) return new OperationResult(true, $"Invalid Artist [{artistId}]"); + if (artist == null) + { + return new OperationResult(true, $"Invalid Artist [{artistId}]"); + } var result = await SetBookmark(user, BookmarkType.Artist, artist.Id, isBookmarked); CacheManager.ClearRegion(artist.CacheRegion); @@ -189,21 +195,30 @@ namespace Roadie.Api.Services public async Task> SetArtistDisliked(Guid artistId, User roadieUser, bool isDisliked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await ToggleArtistDisliked(artistId, user, isDisliked); } public async Task> SetArtistFavorite(Guid artistId, User roadieUser, bool isFavorite) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await ToggleArtistFavorite(artistId, user, isFavorite); } public async Task> SetArtistRating(Guid artistId, User roadieUser, short rating) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await base.SetArtistRating(artistId, user, rating); } @@ -211,9 +226,15 @@ namespace Roadie.Api.Services bool isBookmarked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } var collection = GetCollection(collectionId); - if (collection == null) return new OperationResult(true, $"Invalid Collection [{collectionId}]"); + if (collection == null) + { + return new OperationResult(true, $"Invalid Collection [{collectionId}]"); + } var result = await SetBookmark(user, BookmarkType.Collection, collection.Id, isBookmarked); CacheManager.ClearRegion(collection.CacheRegion); @@ -228,9 +249,15 @@ namespace Roadie.Api.Services public async Task> SetLabelBookmark(Guid labelId, User roadieUser, bool isBookmarked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } var label = GetLabel(labelId); - if (label == null) return new OperationResult(true, $"Invalid Label [{labelId}]"); + if (label == null) + { + return new OperationResult(true, $"Invalid Label [{labelId}]"); + } var result = await SetBookmark(user, BookmarkType.Label, label.Id, isBookmarked); CacheManager.ClearRegion(label.CacheRegion); @@ -246,9 +273,15 @@ namespace Roadie.Api.Services bool isBookmarked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } var playlist = GetPlaylist(playlistId); - if (playlist == null) return new OperationResult(true, $"Invalid Playlist [{playlistId}]"); + if (playlist == null) + { + return new OperationResult(true, $"Invalid Playlist [{playlistId}]"); + } var result = await SetBookmark(user, BookmarkType.Playlist, playlist.Id, isBookmarked); CacheManager.ClearRegion(playlist.CacheRegion); @@ -263,9 +296,15 @@ namespace Roadie.Api.Services public async Task> SetReleaseBookmark(Guid releaseid, User roadieUser, bool isBookmarked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } var release = GetRelease(releaseid); - if (release == null) return new OperationResult(true, $"Invalid Release [{releaseid}]"); + if (release == null) + { + return new OperationResult(true, $"Invalid Release [{releaseid}]"); + } var result = await SetBookmark(user, BookmarkType.Release, release.Id, isBookmarked); CacheManager.ClearRegion(release.CacheRegion); @@ -280,30 +319,45 @@ namespace Roadie.Api.Services public async Task> SetReleaseDisliked(Guid releaseId, User roadieUser, bool isDisliked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await ToggleReleaseDisliked(releaseId, user, isDisliked); } public async Task> SetReleaseFavorite(Guid releaseId, User roadieUser, bool isFavorite) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await ToggleReleaseFavorite(releaseId, user, isFavorite); } public async Task> SetReleaseRating(Guid releaseId, User roadieUser, short rating) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await base.SetReleaseRating(releaseId, user, rating); } public async Task> SetTrackBookmark(Guid trackId, User roadieUser, bool isBookmarked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } var track = GetTrack(trackId); - if (track == null) return new OperationResult(true, $"Invalid Track [{trackId}]"); + if (track == null) + { + return new OperationResult(true, $"Invalid Track [{trackId}]"); + } var result = await SetBookmark(user, BookmarkType.Track, track.Id, isBookmarked); CacheManager.ClearRegion(track.CacheRegion); @@ -318,14 +372,20 @@ namespace Roadie.Api.Services public async Task> SetTrackDisliked(Guid trackId, User roadieUser, bool isDisliked) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await ToggleTrackDisliked(trackId, user, isDisliked); } public async Task> SetTrackFavorite(Guid trackId, User roadieUser, bool isFavorite) { var user = GetUser(roadieUser.UserId); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } return await ToggleTrackFavorite(trackId, user, isFavorite); } @@ -337,7 +397,10 @@ namespace Roadie.Api.Services sw.Stop(); timings.Add("GetUser", sw.ElapsedMilliseconds); - if (user == null) return new OperationResult(true, $"Invalid User [{roadieUser}]"); + if (user == null) + { + return new OperationResult(true, $"Invalid User [{roadieUser}]"); + } sw.Start(); var result = await base.SetTrackRating(trackId, user, rating); sw.Stop(); @@ -353,7 +416,10 @@ namespace Roadie.Api.Services string token) { var user = DbContext.Users.FirstOrDefault(x => x.RoadieId == userId); - if (user == null) return new OperationResult(true, $"User Not Found [{userId}]"); + if (user == null) + { + return new OperationResult(true, $"User Not Found [{userId}]"); + } if (integrationName == "lastfm") return await UpdateLastFMSessionKey(user, token); throw new NotImplementedException(); } diff --git a/Roadie.Api/appsettings.Development.json b/Roadie.Api/appsettings.Development.json index c700fd0..aa5f1ad 100644 --- a/Roadie.Api/appsettings.Development.json +++ b/Roadie.Api/appsettings.Development.json @@ -21,7 +21,7 @@ "Name": "Console", "Args": { "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", - "restrictedToMinimumLevel": "Information" + "restrictedToMinimumLevel": "Verbose" } }, {