Files
TenWholeYears.Server/src/RecNet.Infrastructure/Persistence/Repositories/ProfileRepository.cs
T
2026-06-28 12:46:12 -05:00

73 lines
2.4 KiB
C#

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