using AutoMapper; using Bit.Core.Dirt.Enums; using Bit.Core.Dirt.Repositories; using Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries; using Bit.Infrastructure.EntityFramework.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using OrganizationIntegration = Bit.Core.Dirt.Entities.OrganizationIntegration; namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories; public class OrganizationIntegrationRepository : Repository, IOrganizationIntegrationRepository { public OrganizationIntegrationRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationIntegrations) { } public async Task> GetManyByOrganizationAsync(Guid organizationId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var query = new OrganizationIntegrationReadManyByOrganizationIdQuery(organizationId); return await query.Run(dbContext).ToListAsync(); } } public async Task GetByTeamsConfigurationTenantIdTeamId( string tenantId, string teamId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var query = new OrganizationIntegrationReadByTeamsConfigurationTenantIdTeamIdQuery(tenantId: tenantId, teamId: teamId); return await query.Run(dbContext).SingleOrDefaultAsync(); } } public async Task GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); var query = new OrganizationIntegrationReadByOrganizationIdTypeQuery(organizationId, type); return await query.Run(dbContext).SingleOrDefaultAsync(); } } }