Merge branch 'Sec_14_Seguridad_ASP.NET/64_Creacion_Controllers' into dev

This commit is contained in:
Alejandro Sarmiento
2024-02-19 21:17:54 +01:00
3 changed files with 41 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
using CleanArchitecture.Application.Contracts.Identity;
using CleanArchitecture.Application.Models.Identity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity.Data;
using Microsoft.AspNetCore.Mvc;
namespace CleanArchitecture.API.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class AccountController : ControllerBase
{
private readonly IAuthService authService;
public AccountController(IAuthService _authService)
{
authService = _authService;
}
[HttpPost("login")]
public async Task<ActionResult<AuthResponse>> Login([FromBody] AuthRequest request)
{
var response = await authService.Login(request);
return Ok(response);
}
[HttpPost("register")]
public async Task<ActionResult<RegistrationResponse>> Register([FromBody] RegistrationRequest request)
{
var response = await authService.Register(request);
return Ok(response);
}
}
}

View File

@@ -2,6 +2,7 @@
using CleanArchitecture.Application.Features.Streamers.Commands.DeleteStreamer; using CleanArchitecture.Application.Features.Streamers.Commands.DeleteStreamer;
using CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer; using CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Net; using System.Net;
@@ -19,14 +20,16 @@ namespace CleanArchitecture.API.Controllers
} }
[HttpPost(Name = "CreateStreamer")] [HttpPost(Name = "CreateStreamer")]
[Authorize(Roles = "Administrator")]
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
public async Task<ActionResult<int>> CreateStreamer([FromBody] CreateStreamerCommand command) public async Task<ActionResult<int>> CreateStreamer([FromBody] CreateStreamerCommand command)
{ {
var response = await mediator.Send(command); var response = await mediator.Send(command);
return Ok(response); return Ok(new { StreamerId = response });
} }
[HttpPut(Name = "UpdateStreamer")] [HttpPut(Name = "UpdateStreamer")]
[Authorize(Roles = "Administrator")]
[ProducesResponseType((int)HttpStatusCode.NoContent)] [ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesDefaultResponseType] [ProducesDefaultResponseType]
@@ -37,6 +40,7 @@ namespace CleanArchitecture.API.Controllers
} }
[HttpDelete("{id}", Name = "DeleteStreamer")] [HttpDelete("{id}", Name = "DeleteStreamer")]
[Authorize(Roles = "Administrator")]
[ProducesResponseType((int)HttpStatusCode.NoContent)] [ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesDefaultResponseType] [ProducesDefaultResponseType]

View File

@@ -1,5 +1,6 @@
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList; using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Net; using System.Net;
@@ -18,6 +19,7 @@ namespace CleanArchitecture.API.Controllers
} }
[HttpGet("{username}", Name = "GetVideo")] [HttpGet("{username}", Name = "GetVideo")]
[Authorize]
[ProducesResponseType(typeof(IEnumerable<VideosVm>), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<VideosVm>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<IEnumerable<VideosVm>>> GetVideosByUserName(string username) public async Task<ActionResult<IEnumerable<VideosVm>>> GetVideosByUserName(string username)
{ {