using Flawless.Communication.Shared; using Flawless.Server.Models; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace Flawless.Server.Services; public class AppDbContext(DbContextOptions options) : IdentityDbContext, Guid>(options) { public DbSet RefreshTokens { get; set; } public DbSet Repositories { get; set; } public async ValueTask<(bool existed, bool authorized)> CheckRepositoryExistedAuthorizedAsync( AppUser owner, string name, AppUser user, RepositoryRole role) { var r = await Repositories .FirstOrDefaultAsync(r => r.Name == name && r.Owner == owner); var existed = r != null; var authorized = existed && (r!.Owner == owner || r.Members.Any(m => m.User == owner && m.Role >= role)); return (existed, authorized); } }