2018-11-02 21:04:49 +00:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNet.OData;
|
|
|
|
|
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.EntityFrameworkCore;
|
|
|
|
|
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;
|
|
|
|
|
using Roadie.Library.Data;
|
2018-11-11 20:45:44 +00:00
|
|
|
|
using Roadie.Library.Identity;
|
2018-11-12 00:28:37 +00:00
|
|
|
|
using Roadie.Library.Models.Pagination;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2018-11-12 00:28:37 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-11-06 02:41:51 +00:00
|
|
|
|
using models = Roadie.Library.Models;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
|
|
|
|
|
namespace Roadie.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Produces("application/json")]
|
|
|
|
|
[Route("release")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class ReleaseController : EntityControllerBase
|
|
|
|
|
{
|
2018-11-12 00:28:37 +00:00
|
|
|
|
private IReleaseService ReleaseService { get; }
|
|
|
|
|
|
|
|
|
|
public ReleaseController(IReleaseService releaseService, 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
|
|
|
|
{
|
|
|
|
|
this._logger = logger.CreateLogger("RoadieApi.Controllers.ReleaseController"); ;
|
2018-11-12 00:28:37 +00:00
|
|
|
|
this.ReleaseService = releaseService;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 04:33:22 +00:00
|
|
|
|
//[EnableQuery]
|
|
|
|
|
//public IActionResult Get()
|
|
|
|
|
//{
|
|
|
|
|
// return Ok(this._RoadieDbContext.Releases.ProjectToType<models.Releases.Release>());
|
|
|
|
|
//}
|
2018-11-02 21:04:49 +00:00
|
|
|
|
|
2018-11-07 04:33:22 +00:00
|
|
|
|
//[HttpGet("{id}")]
|
|
|
|
|
//[ProducesResponseType(200)]
|
|
|
|
|
//[ProducesResponseType(404)]
|
|
|
|
|
//public IActionResult Get(Guid id)
|
|
|
|
|
//{
|
|
|
|
|
// var key = id.ToString();
|
|
|
|
|
// var result = this._cacheManager.Get<models.Releases.Release>(key, () =>
|
|
|
|
|
// {
|
|
|
|
|
// var d = this._RoadieDbContext
|
|
|
|
|
// .Releases
|
|
|
|
|
// .Include(x => x.Artist)
|
|
|
|
|
// .Include(x => x.Labels).Include("Labels.Label")
|
|
|
|
|
// .Include(x => x.Medias).Include("Medias.Tracks")
|
|
|
|
|
// .Include(x => x.Genres).Include("Genres.Genre")
|
|
|
|
|
// .Include(x => x.Collections).Include("Collections.Collection")
|
|
|
|
|
// .FirstOrDefault(x => x.RoadieId == id);
|
|
|
|
|
// if (d != null)
|
|
|
|
|
// {
|
|
|
|
|
// return d.Adapt<models.Releases.Release>();
|
|
|
|
|
// }
|
|
|
|
|
// return null;
|
|
|
|
|
// }, key);
|
|
|
|
|
// if (result == null)
|
|
|
|
|
// {
|
|
|
|
|
// return NotFound();
|
|
|
|
|
// }
|
|
|
|
|
// return Ok(result);
|
|
|
|
|
//}
|
2018-11-12 00:28:37 +00:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> List(PagedRequest request, string inc)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.ReleaseService.ReleaseList(user: await this.CurrentUserModel(),
|
|
|
|
|
request: request,
|
|
|
|
|
includes: (inc ?? models.Releases.Release.DefaultIncludes).ToLower().Split(","));
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("random")]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> RandomList(PagedRequest request, string inc)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.ReleaseService.ReleaseList(user: await this.CurrentUserModel(),
|
|
|
|
|
request: request,
|
|
|
|
|
doRandomize: true,
|
|
|
|
|
includes: (inc ?? models.Releases.Release.DefaultIncludes).ToLower().Split(","));
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-11-02 21:04:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|