using Microsoft.EntityFrameworkCore; using api.Data; using api.Domain; using api.Repositories; public class PersonRepository(AppDbContext context) : IPersonRepository { private readonly AppDbContext _context = context; public async Task> GetAllAsync() { return await _context.Persons.ToListAsync(); } public async Task AddAsync(Person person) { await _context.Persons.AddAsync(person); await _context.SaveChangesAsync(); } public async Task GetByUsernameAsync(string username) { return await _context.Persons.FindAsync(username) ?? throw new KeyNotFoundException("User does not exist"); } public async Task UpdateAsync(Person person) { _context.Persons.Update(person); await _context.SaveChangesAsync(); } public async Task DeleteAsync(string username) { Person person = await _context.Persons.FindAsync(username) ?? throw new KeyNotFoundException("User does not exist");; _context.Persons.Remove(person); await _context.SaveChangesAsync(); } }