Skip to content

Commit

Permalink
style: format code with dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
raczu committed Jun 4, 2024
1 parent 14e3333 commit 26348f0
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Common/IAssemblyMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace ReasnAPI.Validators;

public interface IAssemblyMarker
{

}
6 changes: 3 additions & 3 deletions Server/ReasnAPI/ReasnAPI/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public IActionResult Login(
{
validator.ValidateAndThrow(request);
var user = _authService.Login(request);

var tokenPayload = _tokenService.GenerateToken(user);
return Ok(tokenPayload);
}

[HttpPost("register")]
public IActionResult Register(
[FromBody] RegisterRequest request,
Expand All @@ -43,7 +43,7 @@ public IActionResult Register(
action: nameof(UsersController.GetUserByUsername),
controller: "Users",
values: new { username = user.Username });

return Created(location, user.ToDto());
}
}
14 changes: 7 additions & 7 deletions Server/ReasnAPI/ReasnAPI/Exceptions/ServiceExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace ReasnAPI.Exceptions;
public class ServiceExceptionHandler : IExceptionHandler
{
private readonly IProblemDetailsService _problemDetailsService;

public ServiceExceptionHandler(IProblemDetailsService problemDetailsService)
{
_problemDetailsService = problemDetailsService;
}

public async ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
Exception exception,
Expand All @@ -23,31 +23,31 @@ public async ValueTask<bool> TryHandleAsync(
{
Detail = exception.Message
};

switch (exception)
{
case BadRequestException:
httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1";
problemDetails.Title = "A bad request was made";
break;

case NotFoundException:
httpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4";
problemDetails.Title = "A resource was not found";
break;

case VerificationException:
httpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1";
problemDetails.Title = "A verification error occurred";
break;

default:
return false;
}

return await _problemDetailsService.TryWriteAsync(new ProblemDetailsContext
{
HttpContext = httpContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace ReasnAPI.Exceptions;
public class ValidationExceptionHandler : IExceptionHandler
{
private readonly IProblemDetailsService _problemDetailsService;

public ValidationExceptionHandler(IProblemDetailsService problemDetailsService)
{
_problemDetailsService = problemDetailsService;
}

public async ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
Exception exception,
Expand Down
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Mappers/AddressMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static AddressDto ToDto(this Address address)
ZipCode = address.ZipCode
};
}

public static List<AddressDto> ToDtoList(this IEnumerable<Address> addresses)
{
return addresses.Select(ToDto).ToList();
Expand Down
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Mappers/InterestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static InterestDto ToDto(this Interest interest)
Name = interest.Name
};
}

public static List<InterestDto> ToDtoList(this IEnumerable<Interest> interests)
{
return interests.Select(ToDto).ToList();
Expand Down
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Mappers/UserInterestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static UserInterestDto ToDto(this UserInterest userInterest)
Level = userInterest.Level
};
}

public static List<UserInterestDto> ToDtoList(this IEnumerable<UserInterest> userInterests)
{
return userInterests.Select(ToDto).ToList();
Expand Down
6 changes: 4 additions & 2 deletions Server/ReasnAPI/ReasnAPI/Models/DTOs/UserDto.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using ReasnAPI.Models.Enums;

namespace ReasnAPI.Models.DTOs {
public class UserDto {
namespace ReasnAPI.Models.DTOs
{
public class UserDto
{
public string Username { get; set; } = null!;
public string Name { get; set; } = null!;
public string Surname { get; set; } = null!;
Expand Down
6 changes: 3 additions & 3 deletions Server/ReasnAPI/ReasnAPI/Models/Enums/EventStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public enum EventStatus
{
Completed,
Inprogress,
Approved,
Completed,
Inprogress,
Approved,
WaitingForApproval
}
8 changes: 4 additions & 4 deletions Server/ReasnAPI/ReasnAPI/Models/Enums/UserRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace ReasnAPI.Models.Enums;
public enum UserRole
{
[PgName("User")]
User,
User,

[PgName("Organizer")]
Organizer,
Organizer,

[PgName("Admin")]
Admin
}
14 changes: 7 additions & 7 deletions Server/ReasnAPI/ReasnAPI/Services/Authentication/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ public AuthService(ReasnContext context)

public User Login(LoginRequest request)
{
var user = _context.Users.FirstOrDefault(u =>
var user = _context.Users.FirstOrDefault(u =>
u.Email.ToUpper() == request.Email.ToUpper());

if (user is null)
{
throw new NotFoundException("Not found user related with provided email");
}

var result = _hasher.VerifyHashedPassword(
user, user.Password, request.Password);

if (result != PasswordVerificationResult.Success)
{
throw new VerificationException("Provided password is incorrect");
}

return user;
}

public User Register(RegisterRequest request)
{
var userAlreadyExists = _context.Users.Any(u =>
Expand All @@ -50,7 +50,7 @@ public User Register(RegisterRequest request)
throw new BadRequestException(
"User with provided email or username already exists");
}

var user = new User
{
Name = request.Name,
Expand All @@ -70,10 +70,10 @@ public User Register(RegisterRequest request)
}
};
_context.Users.Add(user);

user.Password = _hasher.HashPassword(user, request.Password);
_context.SaveChanges();

return user;
}
}
12 changes: 6 additions & 6 deletions Server/ReasnAPI/ReasnAPI/Services/Authentication/TokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ namespace ReasnAPI.Services.Authentication;
public class TokenService
{
private readonly IConfiguration _configuration;
public TokenService(IConfiguration configuration) =>

public TokenService(IConfiguration configuration) =>
_configuration = configuration;

public TokenPayload GenerateToken(User user)
{
var tokenHandler = new JwtSecurityTokenHandler();
var tokenLifetime = TimeSpan.FromHours(
_configuration.GetValue<int>("JwtSettings:DurationInHours"));

var key = Encoding.UTF8.GetBytes(_configuration["JwtSettings:Key"]!);
var issuer = _configuration["JwtSettings:Issuer"]!;
var audiences = _configuration.GetSection("JwtSettings:Audiences")
.Get<IEnumerable<string>>()!;

var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new []
Subject = new ClaimsIdentity(new[]
{
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class BadRequestException : Exception
public BadRequestException() { }

public BadRequestException(string message) : base(message) { }
public BadRequestException(string message, Exception inner) : base(message, inner) { }

public BadRequestException(string message, Exception inner) : base(message, inner) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class NotFoundException : Exception
public NotFoundException() { }

public NotFoundException(string message) : base(message) { }

public NotFoundException(string message, Exception inner) : base(message, inner) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class VerificationException : Exception
public VerificationException() { }

public VerificationException(string message) : base(message) { }
public VerificationException(string message, Exception inner) : base(message, inner) { }

public VerificationException(string message, Exception inner) : base(message, inner) { }
}

0 comments on commit 26348f0

Please sign in to comment.