Skip to content

Commit 2422a1e

Browse files
Merge pull request #14 from ScriptSage001/master
Improved Code Quality
2 parents a985e76 + ad70771 commit 2422a1e

86 files changed

Lines changed: 69475 additions & 753 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/qodana_code_quality.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ jobs:
2121
- name: 'Qodana Scan'
2222
uses: JetBrains/qodana-action@v2024.1
2323
with:
24-
args: --apply-fixes
24+
args: -b qodana.sarif.json,--apply-fixes
2525
pr-mode: false
2626
push-fixes: pull-request
2727
env:
2828
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
29+
GITHUB_TOKEN: ${{ secrets.QGITHUB_TOKEN }}

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
<h1 align="center" id="title">Shortify.NET</h1>
1+
<h1 align="center" id="title">Shortify.NET (In-Progress)</h1>
22

33
<p align="center"><img src="https://socialify.git.ci/ScriptSage001/Shortify.NET/image?description=1&amp;descriptionEditable=A%20powerful%20.NET%208%20URL%20shortener%20with%20JWT%20auth%2C%20analytics%2C%20and%20caching%2C%20designed%20for%20scalability%20and%20security.&amp;font=Raleway&amp;language=1&amp;name=1&amp;owner=1&amp;pattern=Plus&amp;theme=Dark" alt="project-image"></p>
44

55
<p id="description">A powerful .NET 8 URL shortener with JWT auth analytics and caching designed for scalability and security.</p>
66

7+
<h3>Code Quality</h3>
8+
9+
[![Qodana](https://github.com/ScriptSage001/Shortify.NET/actions/workflows/qodana_code_quality.yml/badge.svg)](https://github.com/ScriptSage001/Shortify.NET/actions/workflows/qodana_code_quality.yml)
10+
711
<h2>🚀 Swagger UI</h2>
812

913
[https://shortify-net.onrender.com/swagger/index.html](https://shortify-net.onrender.com/swagger/index.html)

Shortify.NET.API/BaseApiController.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ namespace Shortify.NET.API
99
/// Base ApiController with Genric Features
1010
/// </summary>
1111
[ApiController]
12-
public abstract class BaseApiController : ControllerBase
12+
public abstract class BaseApiController(IApiService apiService)
13+
: ControllerBase
1314
{
14-
protected readonly IApiService _apiService;
15-
16-
protected BaseApiController(IApiService apiService)
17-
{
18-
this._apiService = apiService;
19-
}
15+
protected readonly IApiService _apiService = apiService;
2016

2117
/// <summary>
2218
/// Handles Failure Scenarios to Genarate

Shortify.NET.API/Contracts/RegisterUserRequest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
public sealed record RegisterUserRequest(
44
string UserName,
55
string Email,
6-
string Password);
6+
string Password,
7+
string ConfirmPassword,
8+
string ValidateOtpToken);
79
}

Shortify.NET.API/Controllers/AuthController.cs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515
namespace Shortify.NET.API.Controllers
1616
{
1717
[Route("api/[controller]")]
18-
public class AuthController : BaseApiController
18+
public class AuthController(IApiService apiService)
19+
: BaseApiController(apiService)
1920
{
20-
private readonly MapperProfiles _mapper;
21-
22-
public AuthController(IApiService apiService) : base(apiService)
23-
{
24-
_mapper = new MapperProfiles();
25-
}
21+
private readonly MapperProfiles _mapper = new();
2622

2723
#region Public Endpoints
2824

2925
#region Register
30-
26+
3127
/// <summary>
3228
/// Registers a new user.
3329
/// </summary>
@@ -40,11 +36,6 @@ public AuthController(IApiService apiService) : base(apiService)
4036
[ProducesErrorResponseType(typeof(ProblemDetails))]
4137
public async Task<IActionResult> RegisterUser([FromBody] RegisterUserRequest request, CancellationToken cancellationToken)
4238
{
43-
if (request is null)
44-
{
45-
return HandleNullOrEmptyRequest();
46-
}
47-
4839
RegisterUserCommand command = _mapper.RegisterUserRequestToCommand(request);
4940

5041
var response = await _apiService.SendAsync(command, cancellationToken);
@@ -70,11 +61,6 @@ public async Task<IActionResult> RegisterUser([FromBody] RegisterUserRequest req
7061
[ProducesErrorResponseType(typeof(ProblemDetails))]
7162
public async Task<IActionResult> LoginUser([FromBody] LoginUserRequest request, CancellationToken cancellationToken)
7263
{
73-
if (request is null)
74-
{
75-
return HandleNullOrEmptyRequest();
76-
}
77-
7864
LoginUserCommand command = _mapper.LoginUserRequestToCommand(request);
7965

8066
var response = await _apiService.SendAsync(command, cancellationToken);
@@ -96,11 +82,6 @@ public async Task<IActionResult> LoginUser([FromBody] LoginUserRequest request,
9682
[ProducesErrorResponseType(typeof(ProblemDetails))]
9783
public async Task<IActionResult> LoginUsingOtp([FromBody] LoginUsingOtpRequest request, CancellationToken cancellationToken)
9884
{
99-
if (request is null)
100-
{
101-
return HandleNullOrEmptyRequest();
102-
}
103-
10485
LoginUsingOtpCommand command = _mapper.LoginUsingOtpRequestToCommand(request);
10586

10687
var response = await _apiService.SendAsync(command, cancellationToken);
@@ -127,11 +108,6 @@ public async Task<IActionResult> LoginUsingOtp([FromBody] LoginUsingOtpRequest r
127108
[ProducesErrorResponseType(typeof(ProblemDetails))]
128109
public async Task<IActionResult> ResetPassword([FromBody] ResetPasswordRequest request, CancellationToken cancellationToken = default)
129110
{
130-
if (request is null)
131-
{
132-
return HandleNullOrEmptyRequest();
133-
}
134-
135111
string userId = GetUser();
136112

137113
if (string.IsNullOrWhiteSpace(userId))
@@ -161,11 +137,6 @@ public async Task<IActionResult> ResetPassword([FromBody] ResetPasswordRequest r
161137
[ProducesErrorResponseType(typeof(ProblemDetails))]
162138
public async Task<IActionResult> ResetPasswordUsingOtp([FromBody] ResetPasswordUsingOtpRequest request, CancellationToken cancellationToken = default)
163139
{
164-
if (request is null)
165-
{
166-
return HandleNullOrEmptyRequest();
167-
}
168-
169140
ResetPasswordUsingOtpCommand command = _mapper.ResetPasswordUsingOtpRequestToCommand(request);
170141

171142
var response = await _apiService.SendAsync(command, cancellationToken);
@@ -194,11 +165,6 @@ public async Task<IActionResult> ResetPasswordUsingOtp([FromBody] ResetPasswordU
194165
[ProducesErrorResponseType(typeof(ProblemDetails))]
195166
public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenRequest request, CancellationToken cancellationToken = default)
196167
{
197-
if (request is null)
198-
{
199-
return HandleNullOrEmptyRequest();
200-
}
201-
202168
RefreshTokenCommand command = _mapper.RefreshTokenRequestToCommand(request);
203169

204170
var response = await _apiService.SendAsync(command, cancellationToken);
@@ -252,11 +218,6 @@ public async Task<IActionResult> RevokeRefreshToken(CancellationToken cancellati
252218
[ProducesErrorResponseType(typeof(ProblemDetails))]
253219
public async Task<IActionResult> GetTokenByClientSecret([FromBody] ClientCredentials clientCredentials, CancellationToken cancellationToken = default)
254220
{
255-
if (clientCredentials is null)
256-
{
257-
HandleNullOrEmptyRequest();
258-
}
259-
260221
GenerateTokenByClientSecretCommand command = _mapper.ClientCredentialsToGenerateTokenByClientSecretCommand(clientCredentials);
261222

262223
var response = await _apiService.SendAsync(command, cancellationToken);

Shortify.NET.API/Controllers/MonitorController.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
namespace Shortify.NET.API.Controllers
55
{
66
[Route("api/[controller]")]
7-
public class MonitorController : BaseApiController
7+
public class MonitorController(IApiService apiService)
8+
: BaseApiController(apiService)
89
{
9-
public MonitorController(IApiService apiService)
10-
: base(apiService)
11-
{
12-
}
1310

1411
#region Public Endpoints
1512

Shortify.NET.API/Controllers/OtpController.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
namespace Shortify.NET.API.Controllers
99
{
1010
[Route("api/[controller]")]
11-
public class OtpController : BaseApiController
11+
public class OtpController(IApiService apiService)
12+
: BaseApiController(apiService)
1213
{
13-
public OtpController(IApiService apiService) : base(apiService)
14-
{
15-
}
1614

1715
#region Public Endpoints
1816

@@ -36,7 +34,7 @@ public async Task<IActionResult> SendOtpForEmailVerification(string email, Cance
3634
return HandleNullOrEmptyRequest();
3735
}
3836

39-
var command = new SendOtpCommand(email, OTPType.VerifyEmail);
37+
var command = new SendOtpCommand(email, OtpType.VerifyEmail);
4038

4139
var response = await _apiService.SendAsync(command, cancellationToken);
4240

@@ -63,7 +61,7 @@ public async Task<IActionResult> SendOtpForLogin(string email, CancellationToken
6361
return HandleNullOrEmptyRequest();
6462
}
6563

66-
var command = new SendOtpCommand(email, OTPType.Login);
64+
var command = new SendOtpCommand(email, OtpType.Login);
6765

6866
var response = await _apiService.SendAsync(command, cancellationToken);
6967

@@ -90,7 +88,7 @@ public async Task<IActionResult> SendOtpToResetPassword(string email, Cancellati
9088
return HandleNullOrEmptyRequest();
9189
}
9290

93-
var command = new SendOtpCommand(email, OTPType.ResetPassword);
91+
var command = new SendOtpCommand(email, OtpType.ResetPassword);
9492

9593
var response = await _apiService.SendAsync(command, cancellationToken);
9694

@@ -116,11 +114,6 @@ public async Task<IActionResult> SendOtpToResetPassword(string email, Cancellati
116114
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
117115
public async Task<IActionResult> ValidateOtp(ValidateOtpRequest request, CancellationToken cancellationToken = default)
118116
{
119-
if (request is null )
120-
{
121-
return HandleNullOrEmptyRequest();
122-
}
123-
124117
var command = new ValidateOtpCommand(request.Email, request.Otp);
125118

126119
var response = await _apiService.SendAsync(command, cancellationToken);

Shortify.NET.API/Controllers/ShortController.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111

1212
namespace Shortify.NET.API.Controllers
1313
{
14-
public class ShortController : BaseApiController
14+
public class ShortController(IApiService apiService)
15+
: BaseApiController(apiService)
1516
{
16-
private readonly MapperProfiles _mapper;
17-
18-
public ShortController(IApiService apiService)
19-
: base(apiService)
20-
{
21-
_mapper = new MapperProfiles();
22-
}
17+
private readonly MapperProfiles _mapper = new();
2318

2419
#region Public Endpoints
2520

@@ -36,7 +31,7 @@ public ShortController(IApiService apiService)
3631
[ProducesErrorResponseType(typeof(ProblemDetails))]
3732
public async Task<IActionResult> ShortenUrl([FromBody] ShortenUrlRequest request, CancellationToken cancellationToken = default)
3833
{
39-
if (request is null || string.IsNullOrWhiteSpace(request.Url))
34+
if (string.IsNullOrWhiteSpace(request.Url))
4035
{
4136
return HandleNullOrEmptyRequest();
4237
}

Shortify.NET.API/Controllers/UserController.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ namespace Shortify.NET.API.Controllers
99
{
1010
[Route("api/[controller]")]
1111
[Authorize]
12-
public class UserController : BaseApiController
12+
public class UserController(IApiService apiService)
13+
: BaseApiController(apiService)
1314
{
14-
private readonly MapperProfiles _mapper;
15-
16-
public UserController(IApiService apiService) : base(apiService)
17-
{
18-
_mapper = new MapperProfiles();
19-
}
15+
private readonly MapperProfiles _mapper = new();
2016

2117
#region Public Endpoints
2218

Shortify.NET.API/Mappers/MapperProfiles.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Org.BouncyCastle.Bcpg;
2-
using Riok.Mapperly.Abstractions;
1+
using Riok.Mapperly.Abstractions;
32
using Shortify.NET.API.Contracts;
43
using Shortify.NET.Applicaion.Otp.Commands.LoginUsingOtp;
54
using Shortify.NET.Applicaion.Shared.Models;
@@ -13,13 +12,8 @@
1312

1413
namespace Shortify.NET.API.Mappers
1514
{
16-
public partial interface IMapperProfiles
17-
{
18-
ResetPasswordCommand ResetPasswordRequestToCommand(ResetPasswordRequest request, string userId);
19-
}
20-
2115
[Mapper]
22-
public partial class MapperProfiles : IMapperProfiles
16+
public partial class MapperProfiles
2317
{
2418
public partial RegisterUserCommand RegisterUserRequestToCommand(RegisterUserRequest request);
2519

0 commit comments

Comments
 (0)