mirror of
https://github.com/sphildreth/roadie
synced 2024-11-22 12:13:10 +00:00
SetRatings now return average rating.
This commit is contained in:
parent
1ca2d2e063
commit
df6cfe6fe4
3 changed files with 27 additions and 21 deletions
|
@ -10,8 +10,8 @@ namespace Roadie.Api.Services
|
|||
public interface IUserService
|
||||
{
|
||||
Task<PagedResult<UserList>> List(PagedRequest request);
|
||||
Task<OperationResult<bool>> SetReleaseRating(Guid releaseId, User roadieUser, short rating);
|
||||
Task<OperationResult<bool>> SetArtistRating(Guid artistId, User roadieUser, short rating);
|
||||
Task<OperationResult<bool>> SetTrackRating(Guid trackId, User roadieUser, short rating);
|
||||
Task<OperationResult<short>> SetReleaseRating(Guid releaseId, User roadieUser, short rating);
|
||||
Task<OperationResult<short>> SetArtistRating(Guid artistId, User roadieUser, short rating);
|
||||
Task<OperationResult<short>> SetTrackRating(Guid trackId, User roadieUser, short rating);
|
||||
}
|
||||
}
|
|
@ -220,12 +220,12 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
|
||||
|
||||
protected async Task<OperationResult<bool>> SetArtistRating(Guid artistId, ApplicationUser user, short rating)
|
||||
protected async Task<OperationResult<short>> SetArtistRating(Guid artistId, ApplicationUser user, short rating)
|
||||
{
|
||||
var artist = this.GetArtist(artistId);
|
||||
if (artist == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid Artist Id [{ artistId }]");
|
||||
return new OperationResult<short>(true, $"Invalid Artist Id [{ artistId }]");
|
||||
}
|
||||
var userArtist = user.ArtistRatings.FirstOrDefault(x => x.ArtistId == artist.Id);
|
||||
if (userArtist == null)
|
||||
|
@ -254,19 +254,21 @@ namespace Roadie.Api.Services
|
|||
this.CacheManager.ClearRegion(user.CacheRegion);
|
||||
this.CacheManager.ClearRegion(artist.CacheRegion);
|
||||
|
||||
return new OperationResult<bool>
|
||||
artist = this.GetArtist(artistId);
|
||||
|
||||
return new OperationResult<short>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = true
|
||||
Data = artist.Rating ?? 0
|
||||
};
|
||||
}
|
||||
|
||||
protected async Task<OperationResult<bool>> SetReleaseRating(Guid releaseId, ApplicationUser user, short rating)
|
||||
protected async Task<OperationResult<short>> SetReleaseRating(Guid releaseId, ApplicationUser user, short rating)
|
||||
{
|
||||
var release = this.GetRelease(releaseId);
|
||||
if (release == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid Release Id [{ releaseId }]");
|
||||
return new OperationResult<short>(true, $"Invalid Release Id [{ releaseId }]");
|
||||
}
|
||||
var userRelease = user.ReleaseRatings.FirstOrDefault(x => x.ReleaseId == release.Id);
|
||||
var now = DateTime.UtcNow;
|
||||
|
@ -297,19 +299,21 @@ namespace Roadie.Api.Services
|
|||
this.CacheManager.ClearRegion(release.CacheRegion);
|
||||
this.CacheManager.ClearRegion(release.Artist.CacheRegion);
|
||||
|
||||
return new OperationResult<bool>
|
||||
release = this.GetRelease(releaseId);
|
||||
|
||||
return new OperationResult<short>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = true
|
||||
Data = release.Rating ?? 0
|
||||
};
|
||||
}
|
||||
|
||||
protected async Task<OperationResult<bool>> SetTrackRating(Guid trackId, ApplicationUser user, short rating)
|
||||
protected async Task<OperationResult<short>> SetTrackRating(Guid trackId, ApplicationUser user, short rating)
|
||||
{
|
||||
var track = this.GetTrack(trackId);
|
||||
if (track == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid Track Id [{ trackId }]");
|
||||
return new OperationResult<short>(true, $"Invalid Track Id [{ trackId }]");
|
||||
}
|
||||
var userTrack = user.TrackRatings.FirstOrDefault(x => x.TrackId == track.Id);
|
||||
if (userTrack == null)
|
||||
|
@ -340,10 +344,12 @@ namespace Roadie.Api.Services
|
|||
this.CacheManager.ClearRegion(track.ReleaseMedia.Release.CacheRegion);
|
||||
this.CacheManager.ClearRegion(track.ReleaseMedia.Release.Artist.CacheRegion);
|
||||
|
||||
return new OperationResult<bool>
|
||||
track = this.GetTrack(trackId);
|
||||
|
||||
return new OperationResult<short>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = true
|
||||
Data = track.Rating
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -153,32 +153,32 @@ namespace Roadie.Api.Services
|
|||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> SetArtistRating(Guid artistId, User roadieUser, short rating)
|
||||
public async Task<OperationResult<short>> SetArtistRating(Guid artistId, User roadieUser, short rating)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid User [{ roadieUser }]");
|
||||
return new OperationResult<short>(true, $"Invalid User [{ roadieUser }]");
|
||||
}
|
||||
return await base.SetArtistRating(artistId, user, rating);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> SetReleaseRating(Guid releaseId, User roadieUser, short rating)
|
||||
public async Task<OperationResult<short>> SetReleaseRating(Guid releaseId, User roadieUser, short rating)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid User [{ roadieUser }]");
|
||||
return new OperationResult<short>(true, $"Invalid User [{ roadieUser }]");
|
||||
}
|
||||
return await base.SetReleaseRating(releaseId, user, rating);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> SetTrackRating(Guid trackId, User roadieUser, short rating)
|
||||
public async Task<OperationResult<short>> SetTrackRating(Guid trackId, User roadieUser, short rating)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid User [{ roadieUser }]");
|
||||
return new OperationResult<short>(true, $"Invalid User [{ roadieUser }]");
|
||||
}
|
||||
return await base.SetTrackRating(trackId, user, rating);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue