Skip to content

Commit

Permalink
refactor: update route naming conventions & delete logout
Browse files Browse the repository at this point in the history
  • Loading branch information
mobinbr committed Aug 27, 2024
1 parent 0b769c6 commit 3a2c958
Show file tree
Hide file tree
Showing 26 changed files with 461 additions and 535 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Application.DTOs.Identity.ChangeRole;

public class ChangeRoleRequest
{
public string UserName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
namespace Application.DTOs.Identity.ChangeRole;

public class ChangeRoleRequest
{
public string UserName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Application.DTOs.Identity.CreateUser;

public class CreateUserRequest
{
public string FirstName { get; set; } = String.Empty;
public string LastName { get; set; } = String.Empty;
public string Email { get; set; } = String.Empty;
public string UserName { get; set; } = String.Empty;
public string Password { get; set; } = String.Empty;
public string Role { get; set; } = String.Empty;
namespace Application.DTOs.Identity.CreateUser;

public class CreateUserRequest
{
public string FirstName { get; set; } = String.Empty;
public string LastName { get; set; } = String.Empty;
public string Email { get; set; } = String.Empty;
public string UserName { get; set; } = String.Empty;
public string Password { get; set; } = String.Empty;
public string Role { get; set; } = String.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace Application.DTOs.Identity.CreateUser;

public class CreateUserResponse
{
public string FirstName { get; set; } = String.Empty;
public string LastName { get; set; } = String.Empty;
public string Email { get; set; } = String.Empty;
public string UserName { get; set; } = String.Empty;
public string Role { get; set; } = String.Empty;
namespace Application.DTOs.Identity.CreateUser;

public class CreateUserResponse
{
public string FirstName { get; set; } = String.Empty;
public string LastName { get; set; } = String.Empty;
public string Email { get; set; } = String.Empty;
public string UserName { get; set; } = String.Empty;
public string Role { get; set; } = String.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Application.DTOs.Identity.LoginUser;

public class LoginUserRequest
{
public string? UserName { get; set; }
public string? Email { get; set; }
public string Password { get; set; } = String.Empty;
namespace Application.DTOs.Identity.LoginUser;

public class LoginUserRequest
{
public string? UserName { get; set; }
public string? Email { get; set; }
public string Password { get; set; } = String.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Application.DTOs.Identity.LoginUser;

public class LoginUserResponse
{
public string FirstName { get; set; } = String.Empty;
public string LastName { get; set; } = String.Empty;
public string Email { get; set; } = String.Empty;
public string UserName { get; set; } = String.Empty;
public string Role { get; set; } = String.Empty;
public string Token { get; set; } = String.Empty;
namespace Application.DTOs.Identity.LoginUser;

public class LoginUserResponse
{
public string FirstName { get; set; } = String.Empty;
public string LastName { get; set; } = String.Empty;
public string Email { get; set; } = String.Empty;
public string UserName { get; set; } = String.Empty;
public string Role { get; set; } = String.Empty;
public string Token { get; set; } = String.Empty;
}
2 changes: 0 additions & 2 deletions src/Application/Interfaces/ITokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ namespace Application.Interfaces;
public interface ITokenService
{
string GenerateToken(AppUser user, string role);
Task<bool> IsTokenInvalidatedAsync(string token);
Task AddInvalidatedTokenAsync(string token);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Application.DTOs;
using Application.DTOs.Identity.ChangeRole;
using Application.DTOs.Identity.CreateUser;
using Application.DTOs.Identity.GetUser;
using Application.DTOs.Identity.LoginUser;

namespace Application.Interfaces.Services;

public interface IIdentityService
{
Task<Result<CreateUserResponse>> SignUpUser(CreateUserRequest createIdentityDto);
Task<Result<LoginUserResponse>> Login(LoginUserRequest loginDto);
Task<Result> ChangeRole(ChangeRoleRequest changeRoleRequest);
Task<List<GetUserResponse>> GetUsersAsync();
Task<Result> Logout(string token);
using Application.DTOs;
using Application.DTOs.Identity.ChangeRole;
using Application.DTOs.Identity.CreateUser;
using Application.DTOs.Identity.GetUser;
using Application.DTOs.Identity.LoginUser;

namespace Application.Interfaces.Services;

public interface IUserService
{
Task<Result<CreateUserResponse>> SignUpUser(CreateUserRequest createIdentityDto);
Task<Result<LoginUserResponse>> Login(LoginUserRequest loginDto);
Task<Result> ChangeRole(ChangeRoleRequest changeRoleRequest);
Task<List<GetUserResponse>> GetUsersAsync();
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
using Application.DTOs.Identity.CreateUser;
using Application.DTOs.Identity.GetUser;
using Application.DTOs.Identity.LoginUser;
using Domain.Entities;

namespace Application.Mappers;

public static class IdentityMapper
{
public static AppUser ToAppUser(this CreateUserRequest createUserRequest)
{
return new AppUser
{
FirstName = createUserRequest.FirstName,
LastName = createUserRequest.LastName,
Email = createUserRequest.Email,
UserName = createUserRequest.UserName
};
}

public static CreateUserResponse ToCreateUserResponse(this AppUser appUser, string role)
{
return new CreateUserResponse
{
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Email = appUser.Email,
UserName = appUser.UserName,
Role = role
};
}

public static LoginUserResponse ToLoginUserResponse(this AppUser appUser, string role, string token)
{
return new LoginUserResponse
{
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Email = appUser.Email,
UserName = appUser.UserName,
Role = role,
Token = token
};
}

public static GetUserResponse ToGetUserResponse(this AppUser appUser, string role)
{
return new GetUserResponse
{
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Email = appUser.Email,
UserName = appUser.UserName,
Role = role
};
}
using Application.DTOs.Identity.CreateUser;
using Application.DTOs.Identity.GetUser;
using Application.DTOs.Identity.LoginUser;
using Domain.Entities;

namespace Application.Mappers;

public static class UserMapper
{
public static AppUser ToAppUser(this CreateUserRequest createUserRequest)
{
return new AppUser
{
FirstName = createUserRequest.FirstName,
LastName = createUserRequest.LastName,
Email = createUserRequest.Email,
UserName = createUserRequest.UserName
};
}

public static CreateUserResponse ToCreateUserResponse(this AppUser appUser, string role)
{
return new CreateUserResponse
{
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Email = appUser.Email,

Check warning on line 27 in src/Application/Mappers/UserMapper.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference assignment.
UserName = appUser.UserName,

Check warning on line 28 in src/Application/Mappers/UserMapper.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference assignment.
Role = role
};
}

public static LoginUserResponse ToLoginUserResponse(this AppUser appUser, string role, string token)
{
return new LoginUserResponse
{
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Email = appUser.Email,

Check warning on line 39 in src/Application/Mappers/UserMapper.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference assignment.
UserName = appUser.UserName,

Check warning on line 40 in src/Application/Mappers/UserMapper.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference assignment.
Role = role,
Token = token
};
}

public static GetUserResponse ToGetUserResponse(this AppUser appUser, string role)
{
return new GetUserResponse
{
FirstName = appUser.FirstName,
LastName = appUser.LastName,
Email = appUser.Email,

Check warning on line 52 in src/Application/Mappers/UserMapper.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference assignment.
UserName = appUser.UserName,

Check warning on line 53 in src/Application/Mappers/UserMapper.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Possible null reference assignment.
Role = role
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

namespace Application.Services.DomainService;

public class IdentityService : IIdentityService
public class UserService : IUserService
{
private readonly IUserManagerRepository _userManagerRepository;
private readonly IRoleManagerRepository _roleManagerRepository;
private readonly ITokenService _tokenService;
public IdentityService(IUserManagerRepository userManagerRepository,
public UserService(IUserManagerRepository userManagerRepository,
IRoleManagerRepository roleManagerRepository,
ITokenService tokenService)
{
Expand Down Expand Up @@ -108,10 +108,4 @@ public async Task<List<GetUserResponse>> GetUsersAsync()

return userWithRoles;
}

public async Task<Result> Logout(string token)
{
await _tokenService.AddInvalidatedTokenAsync(token);
return Result.Ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
namespace Web.Controllers;

[ApiController]
[Route("[controller]/[action]")]
public class AccountController : ControllerBase
[Route("accounts")]
public class AccountsController : ControllerBase
{
private readonly IAccountService _accountService;

public AccountController(IAccountService accountService)
public AccountsController(IAccountService accountService)
{
_accountService = accountService;
}

[HttpPost]
[HttpPost("upload")]
[Authorize]
[RequiresAnyRole(Claims.Role, AppRoles.Admin, AppRoles.DataAdmin)]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
public async Task<IActionResult> ImportAccounts([FromForm] IFormFile file)
public async Task<IActionResult> UploadAccounts([FromForm] IFormFile file)
{
if (file.Length == 0)
return BadRequest("No file uploaded.");
Expand Down
6 changes: 3 additions & 3 deletions src/Web/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Web.Controllers;

[ApiController]
[Route("[controller]/[action]")]
[Route("profile")]
public class ProfileController : ControllerBase
{
private readonly IProfileService _profileService;
Expand All @@ -21,7 +21,7 @@ public ProfileController(IProfileService profileService)
_profileService = profileService;
}

[HttpPut]
[HttpPut("edit-info")]
[Authorize]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
Expand Down Expand Up @@ -63,7 +63,7 @@ public async Task<IActionResult> GetProfileInfo()
return Ok(user.ToProfileInfoDto());
}

[HttpPut]
[HttpPut("change-password")]
[Authorize]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
Expand Down
Loading

0 comments on commit 3a2c958

Please sign in to comment.