roadie/RoadieApi/Controllers/ArtistController.cs

75 lines
2.6 KiB
C#
Raw Normal View History

2018-11-02 16:04:49 -05:00
using Mapster;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
2018-11-05 20:41:51 -06:00
using Microsoft.EntityFrameworkCore;
2018-11-02 16:04:49 -05:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
2018-11-06 15:55:31 -06:00
using Roadie.Api.Services;
2018-11-02 16:04:49 -05:00
using Roadie.Library.Caching;
using Roadie.Library.Data;
using System;
2018-11-06 15:55:31 -06:00
using System.Collections.Generic;
2018-11-02 16:04:49 -05:00
using System.Linq;
2018-11-06 15:55:31 -06:00
using System.Threading.Tasks;
2018-11-05 20:41:51 -06:00
using models = Roadie.Library.Models;
2018-11-02 16:04:49 -05:00
namespace Roadie.Api.Controllers
{
[Produces("application/json")]
[Route("artist")]
[ApiController]
[Authorize]
public class ArtistController : EntityControllerBase
{
2018-11-06 15:55:31 -06:00
private readonly IArtistService _artistService;
private IArtistService ArtistService
{
get
{
return this._artistService;
}
}
public ArtistController(IArtistService artistService, IRoadieDbContext RoadieDbContext, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration)
2018-11-04 14:33:37 -06:00
: base(RoadieDbContext, cacheManager, configuration)
2018-11-02 16:04:49 -05:00
{
2018-11-04 18:08:37 -06:00
this._logger = logger.CreateLogger("RoadieApi.Controllers.ArtistController");
2018-11-06 15:55:31 -06:00
this._artistService = artistService;
2018-11-02 16:04:49 -05:00
}
[EnableQuery]
public IActionResult Get()
{
2018-11-03 16:21:36 -05:00
return Ok(this._RoadieDbContext.Artists.ProjectToType<models.Artist>());
2018-11-02 16:04:49 -05:00
}
[HttpGet("{id}")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
2018-11-06 15:55:31 -06:00
public async Task<IActionResult> Get(Guid id)
2018-11-02 16:04:49 -05:00
{
2018-11-06 15:55:31 -06:00
//var key = id.ToString();
//var result = this._cacheManager.Get<models.Artist>(key, () =>
//{
// var d = this._RoadieDbContext.Artists
// .Include(x => x.AssociatedArtists).Include("AssociatedArtists.AssociatedArtist")
// .FirstOrDefault(x => x.RoadieId == id);
// if (d != null)
// {
// // var info = d.AssociatedArtists.Adapt<models.AssociatedArtistInfo>();
// return d.Adapt<models.Artist>();
// }
// return null;
//}, key);
//if (result == null)
//{
// return NotFound();
//}
//return Ok(result);
2018-11-02 16:04:49 -05:00
var key = id.ToString();
2018-11-06 15:55:31 -06:00
var result = await this.ArtistService.ArtistById(null, id, new List<string> { "stats", "images", "associatedartists", "collections", "playlists", "contributions", "labels", "releases" });
2018-11-02 16:04:49 -05:00
return Ok(result);
}
}
}