rename dtos to requests

This commit is contained in:
Artemy
2025-06-24 21:43:35 +07:00
parent 76094af15b
commit 06cee5caae
5 changed files with 20 additions and 17 deletions
@@ -3,11 +3,14 @@ using Govor.API.Services.AdminsStuff.Interfaces;
using Govor.Core.DTOs; using Govor.Core.DTOs;
using Govor.Core.Repositories.Invaites; using Govor.Core.Repositories.Invaites;
using Govor.Core.Requests; using Govor.Core.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Govor.API.Controllers.AdminStuff; namespace Govor.API.Controllers.AdminStuff;
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController]
[Authorize]
public class InviteUserController : Controller public class InviteUserController : Controller
{ {
private readonly IInvitesRepository _repository; private readonly IInvitesRepository _repository;
+12 -12
View File
@@ -23,7 +23,7 @@ public class AuthController : Controller
[HttpPost("register")]// api/auth/register [HttpPost("register")]// api/auth/register
[RequireHttps] [RequireHttps]
public async Task<IActionResult> Register([FromBody] RegistrationDto registrationDto) public async Task<IActionResult> Register([FromBody] RegistrationRequest registrationRequest)
{ {
try try
{ {
@@ -32,32 +32,32 @@ public class AuthController : Controller
return BadRequest(ModelState); 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); var token = await _accountService.RegistrationAsync(registrationRequest.Name, registrationRequest.Password, invite);
_logger.LogInformation($"Register request for {registrationDto.Name}"); _logger.LogInformation($"Register request for {registrationRequest.Name}");
return Ok(new { token }); return Ok(new { token });
} }
catch (UserAlreadyExistException ex) 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."); return BadRequest("Registration failed: user already exists.");
} }
catch (InviteLinkInvalidException ex) catch (InviteLinkInvalidException ex)
{ {
_logger.LogWarning(ex, $"Invite link invalid: {registrationDto.InviteLink}"); _logger.LogWarning(ex, $"Invite link invalid: {registrationRequest.InviteLink}");
return BadRequest("Invite link invalid."); return BadRequest("Invite link invalid.");
} }
catch (Exception ex) 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."); return StatusCode(500, "An unexpected error occurred. Please try again later.");
} }
} }
[HttpPost("login")]// api/auth/login [HttpPost("login")]// api/auth/login
[RequireHttps] [RequireHttps]
public async Task<IActionResult> Login([FromBody] LoginDto userDto) public async Task<IActionResult> Login([FromBody] LoginRequest userRequest)
{ {
try try
{ {
@@ -66,18 +66,18 @@ public class AuthController : Controller
return BadRequest(ModelState); return BadRequest(ModelState);
} }
var token = await _accountService.LoginAsync(userDto.Name, userDto.Password); var token = await _accountService.LoginAsync(userRequest.Name, userRequest.Password);
_logger.LogInformation($"Login request for {userDto.Name}"); _logger.LogInformation($"Login request for {userRequest.Name}");
return Ok(new { token }); return Ok(new { token });
} }
catch (UserNotRegisteredException ex) 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."); return BadRequest("Login failed: user does not exist.");
} }
catch (Exception ex) 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."); return StatusCode(500, "An unexpected error occurred. Please try again later.");
} }
} }
+1 -1
View File
@@ -74,7 +74,7 @@ class Program
{ {
try try
{ {
RegistrationDto loginData = new RegistrationDto() RegistrationRequest loginData = new RegistrationRequest()
{ {
Name = username, Name = username,
Password = password Password = password
@@ -1,9 +1,9 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Govor.Core.Infrastructure.Validators; using Govor.Core.Infrastructure.Validators;
namespace Govor.Core.DTOs; namespace Govor.Core.Requests;
public class LoginDto public class LoginRequest
{ {
[Required] [Required]
[StringLength(UserValidator.MAX_LENGHT_OF_NAME, [StringLength(UserValidator.MAX_LENGHT_OF_NAME,
@@ -2,9 +2,9 @@ using System.ComponentModel.DataAnnotations;
using Govor.Core.Infrastructure.Validators; using Govor.Core.Infrastructure.Validators;
using Govor.Core.Models; using Govor.Core.Models;
namespace Govor.Core.DTOs; namespace Govor.Core.Requests;
public record RegistrationDto public record RegistrationRequest
{ {
[Required] [Required]
[StringLength(UserValidator.MAX_LENGHT_OF_NAME, [StringLength(UserValidator.MAX_LENGHT_OF_NAME,