30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using TileServer.Application.Accounts;
|
|
using TileServer.Domain.Accounts;
|
|
using TileServer.Infrastructure.Data;
|
|
|
|
namespace TileServer.Infrastructure.Accounts;
|
|
|
|
public sealed class UserRepository(AppDbContext db) : IUserRepository
|
|
{
|
|
public Task<User?> FindByIdAsync(Guid id, CancellationToken ct)
|
|
=> db.Users.FirstOrDefaultAsync(x => x.Id == id, ct);
|
|
|
|
public Task<User?> FindByYandexIdAsync(string yandexId, CancellationToken ct)
|
|
=> db.Users.FirstOrDefaultAsync(x => x.YandexId == yandexId, ct);
|
|
|
|
public Task<User?> FindBySlugAsync(string slug, CancellationToken ct)
|
|
=> db.Users.FirstOrDefaultAsync(x => x.Slug == slug, ct);
|
|
|
|
public Task<bool> SlugExistsAsync(string slug, Guid? exceptUserId, CancellationToken ct)
|
|
=> exceptUserId is null
|
|
? db.Users.AnyAsync(x => x.Slug == slug, ct)
|
|
: db.Users.AnyAsync(x => x.Slug == slug && x.Id != exceptUserId, ct);
|
|
|
|
public async Task AddAsync(User user, CancellationToken ct)
|
|
=> await db.Users.AddAsync(user, ct).ConfigureAwait(false);
|
|
|
|
public Task SaveChangesAsync(CancellationToken ct)
|
|
=> db.SaveChangesAsync(ct);
|
|
}
|