roadie/RoadieApi/Controllers/ArtistController.cs

69 lines
2.4 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Authorization;
2018-11-10 23:26:04 +00:00
using Microsoft.AspNetCore.Identity;
2018-11-02 21:04:49 +00:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
2018-11-06 21:55:31 +00:00
using Roadie.Api.Services;
2018-11-02 21:04:49 +00:00
using Roadie.Library.Caching;
2018-11-14 14:00:08 +00:00
using Roadie.Library.Data;
2018-11-10 23:26:04 +00:00
using Roadie.Library.Identity;
2018-11-14 14:00:08 +00:00
using Roadie.Library.Models.Pagination;
2018-11-02 21:04:49 +00:00
using System;
using System.Net;
2018-11-06 21:55:31 +00:00
using System.Threading.Tasks;
2018-11-14 14:00:08 +00:00
using models = Roadie.Library.Models;
2018-11-02 21:04:49 +00:00
namespace Roadie.Api.Controllers
{
[Produces("application/json")]
[Route("artist")]
[ApiController]
[Authorize]
public class ArtistController : EntityControllerBase
{
private IArtistService ArtistService { get; }
2018-11-10 23:26:04 +00:00
public ArtistController(IArtistService artistService, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration, UserManager<ApplicationUser> userManager)
2018-11-11 20:45:44 +00:00
: base(cacheManager, configuration, userManager)
2018-11-02 21:04:49 +00:00
{
2018-11-05 00:08:37 +00:00
this._logger = logger.CreateLogger("RoadieApi.Controllers.ArtistController");
this.ArtistService = artistService;
2018-11-02 21:04:49 +00:00
}
2018-11-07 04:33:22 +00:00
//[EnableQuery]
//public IActionResult Get()
//{
// return Ok(this._RoadieDbContext.Artists.ProjectToType<models.Artist>());
//}
2018-11-02 21:04:49 +00:00
[HttpGet("{id}")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<ActionResult<Artist>> Get(Guid id, string inc = null)
2018-11-02 21:04:49 +00:00
{
2018-11-14 14:00:08 +00:00
var result = await this.ArtistService.ById(await this.CurrentUserModel(), id, (inc ?? models.Artist.DefaultIncludes).ToLower().Split(","));
2018-11-11 20:45:44 +00:00
if (result == null || result.IsNotFoundResult)
2018-11-07 04:33:22 +00:00
{
return NotFound();
}
if (!result.IsSuccess)
{
return StatusCode((int)HttpStatusCode.InternalServerError);
}
2018-11-02 21:04:49 +00:00
return Ok(result);
}
2018-11-14 14:00:08 +00:00
[HttpPost]
[ProducesResponseType(200)]
public async Task<IActionResult> List(PagedRequest request)
2018-11-14 14:00:08 +00:00
{
var result = await this.ArtistService.List(roadieUser: await this.CurrentUserModel(),
request: request);
2018-11-14 14:00:08 +00:00
if (!result.IsSuccess)
{
return StatusCode((int)HttpStatusCode.InternalServerError);
}
return Ok(result);
}
2018-11-02 21:04:49 +00:00
}
}