using AutoMapper; using Bit.Core.Auth.Repositories; using Bit.Infrastructure.EntityFramework.Auth.Models; using Bit.Infrastructure.EntityFramework.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace Bit.Infrastructure.EntityFramework.Auth.Repositories; public class WebAuthnCredentialRepository : Repository, IWebAuthnCredentialRepository { public WebAuthnCredentialRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) : base(serviceScopeFactory, mapper, (context) => context.WebAuthnCredentials) { } public async Task GetByIdAsync(Guid id, Guid userId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var query = dbContext.WebAuthnCredentials.Where(d => d.Id == id && d.UserId == userId); var cred = await query.FirstOrDefaultAsync(); return Mapper.Map(cred); } } public async Task> GetManyByUserIdAsync(Guid userId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var query = dbContext.WebAuthnCredentials.Where(d => d.UserId == userId); var creds = await query.ToListAsync(); return Mapper.Map>(creds); } } }