roadie/RoadieApi/Controllers/ArtistController.cs
Steven Hildreth 0344d1e604 WIP
2018-11-10 17:26:04 -06:00

57 lines
No EOL
1.8 KiB
C#

using Microsoft.AspNetCore.Authorization;
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;
using Roadie.Library.Models;
using System;
using System.Net;
using System.Threading.Tasks;
namespace Roadie.Api.Controllers
{
[Produces("application/json")]
[Route("artist")]
[ApiController]
[Authorize]
public class ArtistController : EntityControllerBase
{
private IArtistService ArtistService { get; }
private UserManager<ApplicationUser> UserManager { get; }
public ArtistController(IArtistService artistService, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration, UserManager<ApplicationUser> userManager)
: base(cacheManager, configuration)
{
this._logger = logger.CreateLogger("RoadieApi.Controllers.ArtistController");
this.ArtistService = artistService;
this.UserManager = userManager;
}
//[EnableQuery]
//public IActionResult Get()
//{
// return Ok(this._RoadieDbContext.Artists.ProjectToType<models.Artist>());
//}
[HttpGet("{id}")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<ActionResult<Artist>> Get(Guid id, string inc = null)
{
var result = await this.ArtistService.ArtistById(null, id, (inc ?? Artist.DefaultIncludes).ToLower().Split(","));
if (result == null)
{
return NotFound();
}
if (!result.IsSuccess)
{
return StatusCode((int)HttpStatusCode.InternalServerError);
}
return Ok(result);
}
}
}