roadie/Roadie.Api/Controllers/PlaylistController.cs

63 lines
2.2 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Authorization;
2018-11-15 00:16:25 +00:00
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Roadie.Api.Services;
using Roadie.Library.Caching;
using Roadie.Library.Identity;
2018-12-08 03:10:21 +00:00
using Roadie.Library.Models.Pagination;
using System;
using System.Net;
using System.Threading.Tasks;
using models = Roadie.Library.Models;
2018-11-15 00:16:25 +00:00
namespace Roadie.Api.Controllers
{
[Produces("application/json")]
[Route("playlists")]
2018-11-15 00:16:25 +00:00
[ApiController]
[Authorize]
public class PlaylistController : EntityControllerBase
{
private IPlaylistService PlaylistService { get; }
public PlaylistController(IPlaylistService playlistService, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration, UserManager<ApplicationUser> userManager)
: base(cacheManager, configuration, userManager)
{
2018-11-21 06:34:53 +00:00
this.Logger = logger.CreateLogger("RoadieApi.Controllers.PlaylistController");
2018-11-15 00:16:25 +00:00
this.PlaylistService = playlistService;
}
2018-12-09 17:58:31 +00:00
[HttpGet("{id}")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Get(Guid id, string inc = null)
{
var result = await this.PlaylistService.ById(await this.CurrentUserModel(), id, (inc ?? models.Playlists.Playlist.DefaultIncludes).ToLower().Split(","));
if (result == null || result.IsNotFoundResult)
{
return NotFound();
}
if (!result.IsSuccess)
{
return StatusCode((int)HttpStatusCode.InternalServerError);
}
return Ok(result);
}
2018-12-08 03:10:21 +00:00
[HttpGet]
[ProducesResponseType(200)]
public async Task<IActionResult> List([FromQuery]PagedRequest request, string inc)
{
var result = await this.PlaylistService.List(roadieUser: await this.CurrentUserModel(),
request: request);
if (!result.IsSuccess)
{
return StatusCode((int)HttpStatusCode.InternalServerError);
}
return Ok(result);
}
2018-11-15 00:16:25 +00:00
}
}