51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using AutoMapper;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Modules.Library.WebApi.Models.Views.Dictionary;
|
|
using System.Net;
|
|
|
|
namespace Modules.Library.WebApi.Controllers;
|
|
|
|
[ApiController]
|
|
[ApiExplorerSettings(GroupName = "GenreV1")]
|
|
[Route("Dictionaries/Genre")]
|
|
//[Route("[controller]")]
|
|
[Produces("application/json")]
|
|
[ProducesResponseType(400, StatusCode = 400, Type = typeof(ProblemDetails))]
|
|
[ProducesResponseType(401, StatusCode = 401, Type = typeof(UnauthorizedResult))]
|
|
[Consumes("application/json")]
|
|
//[Authorize]
|
|
public class GenreController : ControllerBase
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IMediator _mediator;
|
|
private readonly ILogger _logger;
|
|
|
|
public GenreController(IMapper mapper, IMediator mediator, ILogger<GenreController> logger)
|
|
{
|
|
_mapper = mapper;
|
|
_mediator = mediator;
|
|
_logger = logger;
|
|
}
|
|
|
|
[HttpGet("GenreList")]
|
|
public async Task<List<Genre>> List() =>
|
|
_mapper.Map<List<Genre>>(await _mediator.Send(new Application.Queries.Dictionaries.Genre.GenreListQuery()));
|
|
|
|
[HttpPost("CreateGenre")]
|
|
[ProducesResponseType(typeof(Guid), (int)HttpStatusCode.OK)]
|
|
public async Task<IActionResult> CreateGenre([FromQuery] string genreName) =>
|
|
Ok(await _mediator.Send(new Application.Commands.Dictionaries.Genre.CreateGenreCommand { Name = genreName }));
|
|
|
|
[HttpPost("EditGenre")]
|
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
|
public async Task<IActionResult> EditGenre([FromQuery] Guid id, [FromQuery]string genreName) =>
|
|
Ok(await _mediator.Send(new Application.Commands.Dictionaries.Genre.SetGenreNameCommand { Id = id, Name = genreName }));
|
|
|
|
[HttpPost("DeleteGenre")]
|
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
|
public async Task<IActionResult> DeleteGenre([FromQuery] Guid id) =>
|
|
Ok(await _mediator.Send(new Application.Commands.Dictionaries.Genre.DeleteGenreCommand { Id = id }));
|
|
}
|