Backend login and register
This commit is contained in:
34
src/Infrastructure/Repositories/UserRepository.cs
Normal file
34
src/Infrastructure/Repositories/UserRepository.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Domain.Entities;
|
||||
using Domain.Interface;
|
||||
using Infrastructure.Context;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Repositories;
|
||||
|
||||
public class UserRepository(ApplicationDbContext applicationDbContext)
|
||||
: GenericRepository<User>(applicationDbContext), IUserRepository
|
||||
{
|
||||
public async Task<User?> GetUserByEmailAsync(string email)
|
||||
{
|
||||
return await DbSet.FirstOrDefaultAsync(u => u.Email == email);
|
||||
}
|
||||
|
||||
public async Task<User?> GetUserByUsernameAsync(string username)
|
||||
{
|
||||
return await DbSet.FirstOrDefaultAsync(u => u.Username == username);
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetUserRolesByEmailAsync(string email)
|
||||
{
|
||||
return await DbSet
|
||||
.Where(ur => ur.Email == email)
|
||||
.SelectMany(ur => ur.UserRoles)
|
||||
.Select(ur => ur.Role!.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<User?> GetUserByIdAsync(int id)
|
||||
{
|
||||
return await DbSet.FindAsync(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user