Skip to content

Commit 5e39181

Browse files
committed
code style improvements
1 parent 45b2091 commit 5e39181

File tree

12 files changed

+34
-52
lines changed

12 files changed

+34
-52
lines changed

CheckDrive.Api/CheckDrive.Api/Controllers/Authorization/AuthController.cs CheckDrive.Api/CheckDrive.Api/Controllers/Auth/AuthController.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using CheckDrive.Application.Constants;
2-
using CheckDrive.Application.DTOs.Identity;
3-
using CheckDrive.Application.Interfaces;
4-
using CheckDrive.Application.Interfaces.Authorization;
5-
using Microsoft.AspNetCore.Authorization;
1+
using CheckDrive.Application.DTOs.Identity;
2+
using CheckDrive.Application.Interfaces.Auth;
63
using Microsoft.AspNetCore.Mvc;
74

8-
namespace CheckDrive.Api.Controllers.Authorization;
5+
namespace CheckDrive.Api.Controllers.Auth;
96

107
[Route("api/auth")]
118
[ApiController]
@@ -22,6 +19,7 @@ public AuthController(IAuthService authService)
2219
public async Task<IActionResult> LoginAsync([FromBody] LoginDto request)
2320
{
2421
var token = await _authService.LoginAsync(request);
22+
2523
return Ok(token);
2624
}
2725
}

CheckDrive.Api/CheckDrive.Api/Extensions/DependencyInjection.cs

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using CheckDrive.Infrastructure.Persistence;
2-
using FluentEmail.MailKitSmtp;
31
using CheckDrive.Application.Extensions;
42
using CheckDrive.Infrastructure.Configurations;
53
using CheckDrive.Infrastructure.Extensions;
@@ -11,7 +9,6 @@
119
using Newtonsoft.Json.Converters;
1210
using Newtonsoft.Json.Serialization;
1311
using System.Text;
14-
using Microsoft.AspNetCore.Identity;
1512
using CheckDrive.Api.Filters;
1613

1714
namespace CheckDrive.Api.Extensions;

CheckDrive.Api/CheckDrive.Api/Helpers/CustomJsonFormatter.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Serilog.Formatting;
33
using System.Text.Json;
44

5+
namespace CheckDrive.Api.Helpers;
6+
57
public class CustomJsonFormatter : ITextFormatter
68
{
79
public void Format(LogEvent logEvent, TextWriter output)

CheckDrive.Api/CheckDrive.Api/Program.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CheckDrive.Api.Extensions;
2+
using CheckDrive.Api.Helpers;
23
using Microsoft.AspNetCore.CookiePolicy;
34
using Serilog;
45

CheckDrive.Api/CheckDrive.Application/Constants/Roles.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace CheckDrive.Application.Constants;
22

3-
public class Roles
3+
public static class Roles
44
{
55
public const string Administrator = nameof(Administrator);
66
public const string Driver = nameof(Driver);

CheckDrive.Api/CheckDrive.Application/Extensions/DependencyInjection.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using CheckDrive.Application.Interfaces.Authorization;
2-
using CheckDrive.Application.Interfaces.Review;
3-
using CheckDrive.Application.Services.Authorization;
4-
using CheckDrive.Application.Interfaces;
1+
using CheckDrive.Application.Interfaces.Review;
2+
using CheckDrive.Application.Interfaces;
53
using CheckDrive.Application.Services;
64
using CheckDrive.Application.Services.Review;
7-
using Microsoft.Extensions.Configuration;
85
using Microsoft.Extensions.DependencyInjection;
6+
using CheckDrive.Application.Interfaces.Auth;
7+
using CheckDrive.Application.Services.Auth;
98

109
namespace CheckDrive.Application.Extensions;
1110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using CheckDrive.Application.DTOs.Identity;
2+
3+
namespace CheckDrive.Application.Interfaces.Auth;
4+
5+
public interface IAuthService
6+
{
7+
Task<string> LoginAsync(LoginDto request);
8+
}

CheckDrive.Api/CheckDrive.Application/Interfaces/Authorization/IJwtTokenGenerator.cs CheckDrive.Api/CheckDrive.Application/Interfaces/Auth/IJwtTokenGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Identity;
22

3-
namespace CheckDrive.Application.Interfaces.Authorization;
3+
namespace CheckDrive.Application.Interfaces.Auth;
44

55
public interface IJwtTokenGenerator
66
{

CheckDrive.Api/CheckDrive.Application/Interfaces/Authorization/IAuthService.cs

-9
This file was deleted.

CheckDrive.Api/CheckDrive.Application/Services/Authorization/AuthService.cs CheckDrive.Api/CheckDrive.Application/Services/Auth/AuthService.cs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using CheckDrive.Application.DTOs.Identity;
2-
using CheckDrive.Application.Interfaces.Authorization;
2+
using CheckDrive.Application.Interfaces.Auth;
33
using CheckDrive.Domain.Exceptions;
44
using Microsoft.AspNetCore.Identity;
55

6-
namespace CheckDrive.Application.Services.Authorization;
6+
namespace CheckDrive.Application.Services.Auth;
77

88
internal sealed class AuthService : IAuthService
99
{
@@ -16,27 +16,18 @@ public AuthService(IJwtTokenGenerator jwtTokenGenerator, UserManager<IdentityUse
1616
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
1717
}
1818

19-
public async Task<string> LoginAsync(LoginDto loginDto)
19+
public async Task<string> LoginAsync(LoginDto request)
2020
{
21-
if (loginDto is null)
22-
{
23-
throw new ArgumentNullException(nameof(loginDto));
24-
}
21+
ArgumentNullException.ThrowIfNull(request);
2522

26-
var user = await _userManager.FindByNameAsync(loginDto.UserName);
23+
var user = await _userManager.FindByNameAsync(request.UserName);
2724

28-
if (user is null)
25+
if (user is null || !await _userManager.CheckPasswordAsync(user, request.Password))
2926
{
3027
throw new InvalidLoginAttemptException("Invalid email or password");
3128
}
3229

33-
if (!await _userManager.CheckPasswordAsync(user, loginDto.Password))
34-
{
35-
throw new InvalidLoginAttemptException("Invalid email or password");
36-
}
37-
3830
var roles = await _userManager.GetRolesAsync(user);
39-
4031
var token = _jwtTokenGenerator.GenerateToken(user, roles);
4132

4233
return token;

CheckDrive.Api/CheckDrive.Infrastructure/Extensions/DependencyInjection.cs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using CheckDrive.Domain.Interfaces;
2-
using CheckDrive.Application.Interfaces;
2+
using CheckDrive.Application.Interfaces;
33
using CheckDrive.Infrastructure.Configurations;
44
using CheckDrive.Infrastructure.Email;
55
using CheckDrive.Infrastructure.Persistence;
@@ -9,8 +9,8 @@
99
using Microsoft.EntityFrameworkCore;
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.Extensions.DependencyInjection;
12-
using CheckDrive.Application.Interfaces.Authorization;
1312
using CheckDrive.Infrastructure.Helpers;
13+
using CheckDrive.Application.Interfaces.Auth;
1414

1515
namespace CheckDrive.Infrastructure.Extensions;
1616

@@ -20,7 +20,7 @@ public static IServiceCollection RegisterInfrastructure(this IServiceCollection
2020
{
2121
AddPersistence(services, configuration);
2222
AddConfigurations(services, configuration);
23-
AddFluentEmail(services, configuration);
23+
AddEmail(services, configuration);
2424
AddServices(services);
2525
AddIdentity(services);
2626

@@ -49,14 +49,9 @@ private static void AddConfigurations(IServiceCollection services, IConfiguratio
4949
.Bind(configuration.GetSection(SmsConfigurations.SectionName))
5050
.ValidateDataAnnotations()
5151
.ValidateOnStart();
52-
53-
services.AddOptions<JwtOptions>()
54-
.Bind(configuration.GetSection(JwtOptions.SectionName))
55-
.ValidateDataAnnotations()
56-
.ValidateOnStart();
5752
}
5853

59-
private static void AddFluentEmail(IServiceCollection services, IConfiguration configuration)
54+
private static void AddEmail(IServiceCollection services, IConfiguration configuration)
6055
{
6156
var emailSettings = configuration
6257
.GetSection(EmailConfigurations.SectionName)

CheckDrive.Api/CheckDrive.Infrastructure/Helpers/JwtTokenGenerator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CheckDrive.Application.Interfaces.Authorization;
1+
using CheckDrive.Application.Interfaces.Auth;
22
using CheckDrive.Infrastructure.Configurations;
33
using Microsoft.AspNetCore.Identity;
44
using Microsoft.Extensions.Options;
@@ -13,7 +13,7 @@ internal sealed class JwtTokenGenerator : IJwtTokenGenerator
1313
{
1414
private readonly JwtOptions _options;
1515

16-
public JwtTokenGenerator(IOptions<JwtOptions> options )
16+
public JwtTokenGenerator(IOptions<JwtOptions> options)
1717
{
1818
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));
1919
}
@@ -46,7 +46,7 @@ private static List<Claim> GetClaims(IdentityUser user, IList<string> roles)
4646
{
4747
var claims = new List<Claim>()
4848
{
49-
new(ClaimTypes.NameIdentifier, user.Id.ToString()),
49+
new (ClaimTypes.NameIdentifier, user.Id.ToString()),
5050
};
5151

5252
foreach (var role in roles)

0 commit comments

Comments
 (0)