|
12 | 12 |
|
13 | 13 | namespace TableBooking.Api.Services
|
14 | 14 | {
|
| 15 | + using Microsoft.EntityFrameworkCore; |
| 16 | + using Model; |
| 17 | + |
15 | 18 | public class UserService : IUserService
|
16 | 19 | {
|
17 | 20 | private readonly UserManager<AppUser> _userManager;
|
18 | 21 | private readonly RoleManager<AppRole> _roleManager;
|
19 | 22 | private readonly IConfiguration _configuration;
|
20 | 23 | private readonly string userRoleId = "5ad1268f-f61f-4b1c-b690-cbf8c3d35019";
|
| 24 | + private readonly TableBookingContext _dbContext; |
21 | 25 |
|
22 | 26 | public UserService(
|
23 | 27 | UserManager<AppUser> userManager,
|
24 | 28 | RoleManager<AppRole> roleManager,
|
25 | 29 | IConfiguration configuration,
|
26 |
| - IUnitOfWork unitOfWork) |
| 30 | + IUnitOfWork unitOfWork, |
| 31 | + TableBookingContext dbContext) |
27 | 32 | {
|
28 | 33 | _userManager = userManager;
|
29 | 34 | _roleManager = roleManager;
|
30 | 35 | _configuration = configuration;
|
| 36 | + _dbContext = dbContext; |
31 | 37 | }
|
32 | 38 |
|
33 | 39 | public async Task<IActionResult> Register(UserRegisterDto dto)
|
@@ -82,6 +88,15 @@ public async Task<IActionResult> Login(UserLoginDto dto)
|
82 | 88 | });
|
83 | 89 | }
|
84 | 90 |
|
| 91 | + public async Task<AppUserDto> GetUserInfo(Guid id, CancellationToken cancellationToken) |
| 92 | + { |
| 93 | + var user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == id, cancellationToken); |
| 94 | + |
| 95 | + var userDto = user?.ToDto(); |
| 96 | + |
| 97 | + return userDto ?? new(); |
| 98 | + } |
| 99 | + |
85 | 100 | private JwtSecurityToken GetToken(List<Claim> authClaims)
|
86 | 101 | {
|
87 | 102 | var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"]));
|
|
0 commit comments