mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
dislike work
This commit is contained in:
parent
cf52c8fb67
commit
f46fb8c3b4
4 changed files with 122 additions and 3 deletions
|
@ -143,6 +143,19 @@ namespace Roadie.Api.Controllers
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("setArtistDisliked/{artistId}/{isDisliked}")]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> SetArtistDisliked(Guid artistId, bool isDisliked)
|
||||
{
|
||||
var result = await this.UserService.SetArtistDisliked(artistId, await this.CurrentUserModel(), isDisliked);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
this.CacheManager.ClearRegion(EntityControllerBase.ControllerCacheRegionUrn);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("setReleaseFavorite/{releaseId}/{isFavorite}")]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> SetReleaseFavorite(Guid releaseId, bool isFavorite)
|
||||
|
@ -156,6 +169,19 @@ namespace Roadie.Api.Controllers
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("setReleaseDisliked/{releaseId}/{isDisliked}")]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> SetReleaseDisliked(Guid releaseId, bool isDisliked)
|
||||
{
|
||||
var result = await this.UserService.SetReleaseDisliked(releaseId, await this.CurrentUserModel(), isDisliked);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
this.CacheManager.ClearRegion(EntityControllerBase.ControllerCacheRegionUrn);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("setArtistBookmark/{artistId}/{isBookmarked}")]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> SetArtistBookmark(Guid artistId, bool isBookmarked)
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace Roadie.Api.Services
|
|||
Task<OperationResult<bool>> SetArtistBookmark(Guid artistId, User roadieUser, bool isBookmarked);
|
||||
|
||||
Task<OperationResult<bool>> SetArtistFavorite(Guid artistId, User roadieUser, bool isFavorite);
|
||||
Task<OperationResult<bool>> SetArtistDisliked(Guid artistId, User roadieUser, bool isDisliked);
|
||||
|
||||
Task<OperationResult<short>> SetArtistRating(Guid artistId, User roadieUser, short rating);
|
||||
|
||||
|
@ -30,6 +31,7 @@ namespace Roadie.Api.Services
|
|||
Task<OperationResult<bool>> SetReleaseBookmark(Guid releaseid, User roadieUser, bool isBookmarked);
|
||||
|
||||
Task<OperationResult<bool>> SetReleaseFavorite(Guid releaseId, User roadieUser, bool isFavorite);
|
||||
Task<OperationResult<bool>> SetReleaseDisliked(Guid releaseId, User roadieUser, bool isDisliked);
|
||||
|
||||
Task<OperationResult<short>> SetReleaseRating(Guid releaseId, User roadieUser, short rating);
|
||||
|
||||
|
|
|
@ -426,7 +426,7 @@ namespace Roadie.Api.Services
|
|||
{
|
||||
userArtist = new data.UserArtist
|
||||
{
|
||||
IsFavorite = true,
|
||||
IsFavorite = isFavorite,
|
||||
UserId = user.Id,
|
||||
ArtistId = artist.Id
|
||||
};
|
||||
|
@ -449,6 +449,77 @@ namespace Roadie.Api.Services
|
|||
};
|
||||
}
|
||||
|
||||
protected async Task<OperationResult<bool>> ToggleArtistDisliked(Guid artistId, ApplicationUser user, bool isDisliked)
|
||||
{
|
||||
var artist = this.GetArtist(artistId);
|
||||
if (artist == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid Artist Id [{ artistId }]");
|
||||
}
|
||||
var userArtist = this.DbContext.UserArtists.FirstOrDefault(x => x.ArtistId == artist.Id && x.UserId == user.Id);
|
||||
if (userArtist == null)
|
||||
{
|
||||
userArtist = new data.UserArtist
|
||||
{
|
||||
IsDisliked = isDisliked,
|
||||
UserId = user.Id,
|
||||
ArtistId = artist.Id
|
||||
};
|
||||
this.DbContext.UserArtists.Add(userArtist);
|
||||
}
|
||||
else
|
||||
{
|
||||
userArtist.IsDisliked = isDisliked;
|
||||
userArtist.LastUpdated = DateTime.UtcNow;
|
||||
}
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
|
||||
this.CacheManager.ClearRegion(user.CacheRegion);
|
||||
this.CacheManager.ClearRegion(artist.CacheRegion);
|
||||
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = true
|
||||
};
|
||||
}
|
||||
|
||||
protected async Task<OperationResult<bool>> ToggleReleaseDisliked(Guid releaseId, ApplicationUser user, bool isDisliked)
|
||||
{
|
||||
var release = this.GetRelease(releaseId);
|
||||
if (release == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid Release Id [{ releaseId }]");
|
||||
}
|
||||
var userRelease = this.DbContext.UserReleases.FirstOrDefault(x => x.ReleaseId == release.Id && x.UserId == user.Id);
|
||||
if (userRelease == null)
|
||||
{
|
||||
userRelease = new data.UserRelease
|
||||
{
|
||||
IsDisliked = isDisliked,
|
||||
UserId = user.Id,
|
||||
ReleaseId = release.Id
|
||||
};
|
||||
this.DbContext.UserReleases.Add(userRelease);
|
||||
}
|
||||
else
|
||||
{
|
||||
userRelease.IsDisliked = isDisliked;
|
||||
userRelease.LastUpdated = DateTime.UtcNow;
|
||||
}
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
|
||||
this.CacheManager.ClearRegion(user.CacheRegion);
|
||||
this.CacheManager.ClearRegion(release.CacheRegion);
|
||||
this.CacheManager.ClearRegion(release.Artist.CacheRegion);
|
||||
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = true
|
||||
};
|
||||
}
|
||||
|
||||
protected async Task<OperationResult<bool>> ToggleReleaseFavorite(Guid releaseId, ApplicationUser user, bool isFavorite)
|
||||
{
|
||||
var release = this.GetRelease(releaseId);
|
||||
|
@ -461,7 +532,7 @@ namespace Roadie.Api.Services
|
|||
{
|
||||
userRelease = new data.UserRelease
|
||||
{
|
||||
IsFavorite = true,
|
||||
IsFavorite = isFavorite,
|
||||
UserId = user.Id,
|
||||
ReleaseId = release.Id
|
||||
};
|
||||
|
@ -497,7 +568,7 @@ namespace Roadie.Api.Services
|
|||
{
|
||||
userTrack = new data.UserTrack
|
||||
{
|
||||
IsFavorite = true,
|
||||
IsFavorite = isFavorite,
|
||||
UserId = user.Id,
|
||||
TrackId = track.Id
|
||||
};
|
||||
|
|
|
@ -346,6 +346,16 @@ namespace Roadie.Api.Services
|
|||
return await base.ToggleArtistFavorite(artistId, user, isFavorite);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> SetArtistDisliked(Guid artistId, User roadieUser, bool isDisliked)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid User [{ roadieUser }]");
|
||||
}
|
||||
return await base.ToggleArtistDisliked(artistId, user, isDisliked);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<short>> SetArtistRating(Guid artistId, User roadieUser, short rating)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
|
@ -458,6 +468,16 @@ namespace Roadie.Api.Services
|
|||
return await base.ToggleReleaseFavorite(releaseId, user, isFavorite);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> SetReleaseDisliked(Guid releaseId, User roadieUser, bool isDisliked)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
if (user == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, $"Invalid User [{ roadieUser }]");
|
||||
}
|
||||
return await base.ToggleReleaseDisliked(releaseId, user, isDisliked);
|
||||
}
|
||||
|
||||
public async Task<OperationResult<short>> SetReleaseRating(Guid releaseId, User roadieUser, short rating)
|
||||
{
|
||||
var user = this.GetUser(roadieUser.UserId);
|
||||
|
|
Loading…
Reference in a new issue