mirror of
https://github.com/sphildreth/roadie
synced 2024-11-22 12:13:10 +00:00
Playlist work
This commit is contained in:
parent
7716013a2a
commit
bc5da0f95f
4 changed files with 60 additions and 1 deletions
|
@ -61,6 +61,9 @@ namespace Roadie.Library
|
|||
[JsonIgnore]
|
||||
public bool IsNotFoundResult { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsAccessDeniedResult { get; set; }
|
||||
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
public IEnumerable<string> Messages
|
||||
|
|
|
@ -17,6 +17,8 @@ namespace Roadie.Api.Services
|
|||
|
||||
Task<OperationResult<Playlist>> ById(User roadieUser, Guid id, IEnumerable<string> includes = null);
|
||||
|
||||
Task<OperationResult<bool>> DeletePlaylist(User user, Guid id);
|
||||
|
||||
Task<PagedResult<PlaylistList>> List(PagedRequest request, User roadieUser = null);
|
||||
|
||||
Task<OperationResult<bool>> ReorderPlaylist(data.Playlist playlist);
|
||||
|
|
|
@ -95,10 +95,43 @@ namespace Roadie.Api.Services
|
|||
|
||||
await base.UpdatePlaylistCounts(playlist.Id, now);
|
||||
|
||||
sw.Stop();
|
||||
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
IsSuccess = result,
|
||||
Data = result
|
||||
Data = result,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> DeletePlaylist(User user, Guid id)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var playlist = this.DbContext.Playlists.FirstOrDefault(x => x.RoadieId == id);
|
||||
if (playlist == null)
|
||||
{
|
||||
return new OperationResult<bool>(true, string.Format("Playlist Not Found [{0}]", id));
|
||||
}
|
||||
if(!user.IsAdmin || user.Id != playlist.UserId)
|
||||
{
|
||||
this.Logger.LogWarning("User `{0}` attempted to delete Playlist `{1}`", user, playlist);
|
||||
return new OperationResult<bool>("Access Denied")
|
||||
{
|
||||
IsAccessDeniedResult = true
|
||||
};
|
||||
}
|
||||
this.DbContext.Playlists.Remove(playlist);
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
this.Logger.LogInformation("User `{0}` deleted Playlist `{1}]`", user, playlist);
|
||||
this.CacheManager.ClearRegion(playlist.CacheRegion);
|
||||
sw.Stop();
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = true,
|
||||
OperationTime = sw.ElapsedMilliseconds
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -75,5 +75,26 @@ namespace Roadie.Api.Controllers
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("delete/{id}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> DeletePlaylist(Guid id)
|
||||
{
|
||||
var result = await this.PlaylistService.DeletePlaylist(await this.CurrentUserModel(), id);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if(result != null && result.IsAccessDeniedResult)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Forbidden);
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue