refactor: Clean Architecture mit Repository Pattern, Controllern und DTOs
- 15 Controller-Klassen ersetzen Minimal APIs in Program.cs - Repository Pattern mit Interfaces + Implementierungen (Project, Task, Activity, User) - AuthService verwendet jetzt IUserRepository statt direktem DbContext-Zugriff - SecurityHeadersMiddleware als eigenständige Middleware-Klasse - PathSecurityHelper als gemeinsamer Helper für Pfadvalidierung - DTOs in eigenem Namespace Nexus.Api.DTOs - EF-Entities in Nexus.Api.Data (vorher Nexus.Api.Domain) - Program.cs auf DI-Registrierung + Middleware reduziert - Alle 43 Endpoints unverändert erhalten - Build + 3/3 Tests erfolgreich
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nexus.Api.Data;
|
||||
|
||||
namespace Nexus.Api.Repositories;
|
||||
|
||||
public sealed class ProjectRepository(NexusDbContext db) : IProjectRepository
|
||||
{
|
||||
public Task<List<Project>> GetAllAsync(CancellationToken ct = default)
|
||||
=> db.Projects.AsNoTracking().OrderByDescending(x => x.UpdatedAt).ToListAsync(ct);
|
||||
|
||||
public ValueTask<Project?> GetByIdAsync(Guid id, CancellationToken ct = default)
|
||||
=> db.Projects.FindAsync([id], ct);
|
||||
|
||||
public async Task<Project> AddAsync(Project project, CancellationToken ct = default)
|
||||
{
|
||||
db.Projects.Add(project);
|
||||
await db.SaveChangesAsync(ct);
|
||||
return project;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(Project project, CancellationToken ct = default)
|
||||
{
|
||||
project.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(Project project, CancellationToken ct = default)
|
||||
{
|
||||
db.Projects.Remove(project);
|
||||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public Task<bool> HasTasksAsync(Guid projectId, CancellationToken ct = default)
|
||||
=> db.Tasks.AnyAsync(t => t.ProjectId == projectId, ct);
|
||||
}
|
||||
Reference in New Issue
Block a user