mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
rename dtos to requests
This commit is contained in:
@@ -3,11 +3,14 @@ using Govor.API.Services.AdminsStuff.Interfaces;
|
||||
using Govor.Core.DTOs;
|
||||
using Govor.Core.Repositories.Invaites;
|
||||
using Govor.Core.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers.AdminStuff;
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class InviteUserController : Controller
|
||||
{
|
||||
private readonly IInvitesRepository _repository;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class AuthController : Controller
|
||||
|
||||
[HttpPost("register")]// api/auth/register
|
||||
[RequireHttps]
|
||||
public async Task<IActionResult> Register([FromBody] RegistrationDto registrationDto)
|
||||
public async Task<IActionResult> Register([FromBody] RegistrationRequest registrationRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -32,32 +32,32 @@ public class AuthController : Controller
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var invite = _invitesService.Validate(registrationDto.InviteLink);
|
||||
var invite = _invitesService.Validate(registrationRequest.InviteLink);
|
||||
|
||||
var token = await _accountService.RegistrationAsync(registrationDto.Name, registrationDto.Password, invite);
|
||||
_logger.LogInformation($"Register request for {registrationDto.Name}");
|
||||
var token = await _accountService.RegistrationAsync(registrationRequest.Name, registrationRequest.Password, invite);
|
||||
_logger.LogInformation($"Register request for {registrationRequest.Name}");
|
||||
return Ok(new { token });
|
||||
}
|
||||
catch (UserAlreadyExistException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Registration failed for user {registrationDto.Name}");
|
||||
_logger.LogWarning(ex, $"Registration failed for user {registrationRequest.Name}");
|
||||
return BadRequest("Registration failed: user already exists.");
|
||||
}
|
||||
catch (InviteLinkInvalidException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, $"Invite link invalid: {registrationDto.InviteLink}");
|
||||
_logger.LogWarning(ex, $"Invite link invalid: {registrationRequest.InviteLink}");
|
||||
return BadRequest("Invite link invalid.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error during registration for user {Name}", registrationDto.Name);
|
||||
_logger.LogError(ex, "Unexpected error during registration for user {Name}", registrationRequest.Name);
|
||||
return StatusCode(500, "An unexpected error occurred. Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("login")]// api/auth/login
|
||||
[RequireHttps]
|
||||
public async Task<IActionResult> Login([FromBody] LoginDto userDto)
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequest userRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -66,18 +66,18 @@ public class AuthController : Controller
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var token = await _accountService.LoginAsync(userDto.Name, userDto.Password);
|
||||
_logger.LogInformation($"Login request for {userDto.Name}");
|
||||
var token = await _accountService.LoginAsync(userRequest.Name, userRequest.Password);
|
||||
_logger.LogInformation($"Login request for {userRequest.Name}");
|
||||
return Ok(new { token });
|
||||
}
|
||||
catch (UserNotRegisteredException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Login failed for user {Name}", userDto.Name);
|
||||
_logger.LogWarning(ex, "Login failed for user {Name}", userRequest.Name);
|
||||
return BadRequest("Login failed: user does not exist.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unexpected error during login for user {Name}", userDto.Name);
|
||||
_logger.LogError(ex, "Unexpected error during login for user {Name}", userRequest.Name);
|
||||
return StatusCode(500, "An unexpected error occurred. Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class Program
|
||||
{
|
||||
try
|
||||
{
|
||||
RegistrationDto loginData = new RegistrationDto()
|
||||
RegistrationRequest loginData = new RegistrationRequest()
|
||||
{
|
||||
Name = username,
|
||||
Password = password
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Govor.Core.Infrastructure.Validators;
|
||||
|
||||
namespace Govor.Core.DTOs;
|
||||
namespace Govor.Core.Requests;
|
||||
|
||||
public class LoginDto
|
||||
public class LoginRequest
|
||||
{
|
||||
[Required]
|
||||
[StringLength(UserValidator.MAX_LENGHT_OF_NAME,
|
||||
@@ -2,9 +2,9 @@ using System.ComponentModel.DataAnnotations;
|
||||
using Govor.Core.Infrastructure.Validators;
|
||||
using Govor.Core.Models;
|
||||
|
||||
namespace Govor.Core.DTOs;
|
||||
namespace Govor.Core.Requests;
|
||||
|
||||
public record RegistrationDto
|
||||
public record RegistrationRequest
|
||||
{
|
||||
[Required]
|
||||
[StringLength(UserValidator.MAX_LENGHT_OF_NAME,
|
||||
Reference in New Issue
Block a user