2018-11-14 23:18:02 +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-14 23:18:02 +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-14 23:18:02 +00:00
|
|
|
|
using Roadie.Library.Models.Pagination;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
|
|
|
|
|
namespace Roadie.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Produces("application/json")]
|
|
|
|
|
[Route("label")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class LabelController : EntityControllerBase
|
|
|
|
|
{
|
2018-11-14 23:18:02 +00:00
|
|
|
|
private ILabelService LabelService { get; }
|
|
|
|
|
|
|
|
|
|
public LabelController(ILabelService labelService, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration, UserManager<ApplicationUser> userManager)
|
|
|
|
|
: base(cacheManager, configuration, userManager)
|
2018-11-02 21:04:49 +00:00
|
|
|
|
{
|
2018-11-14 23:18:02 +00:00
|
|
|
|
this._logger = logger.CreateLogger("RoadieApi.Controllers.LabelController");
|
|
|
|
|
this.LabelService = labelService;
|
2018-11-02 21:04:49 +00:00
|
|
|
|
}
|
2018-11-14 23:18:02 +00:00
|
|
|
|
|
2018-11-07 04:33:22 +00:00
|
|
|
|
//[EnableQuery]
|
|
|
|
|
//public IActionResult Get()
|
|
|
|
|
//{
|
|
|
|
|
// return Ok(this._RoadieDbContext.Labels.ProjectToType<models.Label>());
|
|
|
|
|
//}
|
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.Label>(key, () =>
|
|
|
|
|
// {
|
|
|
|
|
// var d = this._RoadieDbContext.Labels.FirstOrDefault(x => x.RoadieId == id);
|
|
|
|
|
// if (d != null)
|
|
|
|
|
// {
|
|
|
|
|
// return d.Adapt<models.Label>();
|
|
|
|
|
// }
|
|
|
|
|
// return null;
|
|
|
|
|
// }, key);
|
|
|
|
|
// if (result == null)
|
|
|
|
|
// {
|
|
|
|
|
// return NotFound();
|
|
|
|
|
// }
|
|
|
|
|
// return Ok(result);
|
|
|
|
|
//}
|
2018-11-14 23:18:02 +00:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(200)]
|
|
|
|
|
public async Task<IActionResult> List(PagedRequest request)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.LabelService.List(roadieUser: await this.CurrentUserModel(),
|
|
|
|
|
request: request);
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return StatusCode((int)HttpStatusCode.InternalServerError);
|
|
|
|
|
}
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2018-11-02 21:04:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|