2018-11-15 04:11:25 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2018-11-11 20:45:44 +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-12 00:28:37 +00:00
|
|
|
|
using Roadie.Api.Services;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
using Roadie.Library.Caching;
|
2018-11-11 20:45:44 +00:00
|
|
|
|
using Roadie.Library.Identity;
|
2018-11-17 02:14:32 +00:00
|
|
|
|
using Roadie.Library.Models;
|
2018-11-12 00:28:37 +00:00
|
|
|
|
using Roadie.Library.Models.Pagination;
|
2018-11-17 02:14:32 +00:00
|
|
|
|
using System;
|
2018-11-12 00:28:37 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-11-17 02:14:32 +00:00
|
|
|
|
using models = Roadie.Library.Models;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
|
|
|
|
|
namespace Roadie.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Produces("application/json")]
|
2018-11-18 16:40:52 +00:00
|
|
|
|
[Route("tracks")]
|
2018-11-02 21:04:49 +00:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class TrackController : EntityControllerBase
|
|
|
|
|
{
|
2018-11-12 00:28:37 +00:00
|
|
|
|
private ITrackService TrackService { get; }
|
|
|
|
|
|
|
|
|
|
public TrackController(ITrackService trackService, 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-12 00:28:37 +00:00
|
|
|
|
this._logger = logger.CreateLogger("RoadieApi.Controllers.TrackController");
|
|
|
|
|
this.TrackService = trackService;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 04:33:22 +00:00
|
|
|
|
//[EnableQuery]
|
|
|
|
|
//public IActionResult Get()
|
|
|
|
|
//{
|
|
|
|
|
// return Ok(this._RoadieDbContext.Tracks.ProjectToType<models.Track>());
|
|
|
|
|
//}
|
2018-11-02 21:04:49 +00:00
|
|
|
|
|
2018-11-17 02:14:32 +00:00
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
[ProducesResponseType(404)]
|
|
|
|
|
public async Task<IActionResult> Get(Guid id, string inc = null)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.TrackService.ById(await this.CurrentUserModel(), id, (inc ?? models.Track.DefaultIncludes).ToLower().Split(","));
|
|
|
|
|
if (result == null || result.IsNotFoundResult)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-11-12 00:28:37 +00:00
|
|
|
|
|
2018-11-18 16:40:52 +00:00
|
|
|
|
[HttpGet]
|
2018-11-12 00:28:37 +00:00
|
|
|
|
[ProducesResponseType(200)]
|
2018-11-18 16:40:52 +00:00
|
|
|
|
public async Task<IActionResult> List([FromQuery]PagedRequest request, string inc)
|
2018-11-12 00:28:37 +00:00
|
|
|
|
{
|
2018-11-15 00:16:25 +00:00
|
|
|
|
var result = await this.TrackService.List(roadieUser: await this.CurrentUserModel(),
|
|
|
|
|
request: request);
|
2018-11-12 00:28:37 +00:00
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-11-02 21:04:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|