feat(proj): init
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user