using Microsoft.EntityFrameworkCore; using RecNet.Domain.Common; using RecNet.Domain.Profiles; namespace RecNet.Infrastructure.Persistence.Repositories; public class ProfileRepository(DatabaseContext dbContext) : IProfileRepository { public Task GetByIdAsync( Guid profileId, CancellationToken ct = default) => dbContext.Profiles .FirstOrDefaultAsync(x => x.ProfileId == profileId, ct); public Task GetByIdWithSettingsAsync( Guid profileId, CancellationToken ct = default) => dbContext.Profiles .Include(x => x.Settings) .FirstOrDefaultAsync(x => x.ProfileId == profileId, ct); public Task GetAvatarByProfileIdAsync( Guid profileId, CancellationToken ct = default) => dbContext.Profiles .AsNoTracking() .Where(x => x.ProfileId == profileId) .Select(x => x.Avatar) .FirstOrDefaultAsync(ct); public async Task> GetSettingsByProfileIdAsync( Guid profileId, CancellationToken ct = default) => await dbContext.PlayerSettings .AsNoTracking() .Where(x => x.UserId == profileId) .ToListAsync(ct); public async Task> GetByIdsAsync( List profileIds, CancellationToken ct = default) => await dbContext.Profiles .Where(x => profileIds.Contains(x.ProfileId)) .ToListAsync(ct); public Task GetByPlatform( PlatformType platform, string platformId, CancellationToken ct = default) => dbContext.Profiles .FirstOrDefaultAsync(x => x.Platform == platform && x.PlatformId == platformId, ct); public Task GetProfileTokenVersion( Guid profileId, CancellationToken ct = default) => dbContext.Profiles .AsNoTracking() .Where(x => x.ProfileId == profileId) .Select(x => x.TokenVersion) .FirstOrDefaultAsync(ct); public async Task AddAsync( Profile profile, CancellationToken ct = default) => await dbContext.Profiles.AddAsync(profile, ct); public Task SaveChangesAsync(CancellationToken ct = default) => dbContext.SaveChangesAsync(ct); }