4ad0f9e493
## Backend — Service Layer & Repository Refactoring ### Neue Services (21 neue Dateien) **Interfaces & Implementierungen:** - `IOpenClawGatewayClient` — Interface für OpenClawGatewayClient (DIP-Fix: DashboardController hing an konkreter Klasse) - `IAgentConfigService` / `AgentConfigService` — Agent-Config-File-I/O aus AgentsController extrahiert - `IProjectService` / `ProjectService` — Projekt-CRUD + Activity-Logging (SRP) - `ITaskService` / `TaskService` — Task-State-Machine, Approve/Reject, Dashboard-Operationen (eliminiert Duplikation zwischen TasksController und DashboardController) - `IDashboardService` / `DashboardService` — Queue-Aggregation, Priority-Normalisierung, Gateway-Delegation - `IOperationsService` / `OperationsService` — Metriken-Berechnung aus OperationsController - `ITeamService` / `TeamService` — IDENTITY.md-Lesen aus TeamController - `IMemoryService` / `MemoryService` — File-I/O aus MemoryController - `IIncidentService` / `IncidentService` — File-Parsing (Regex-Source-Generatoren) aus IncidentsController - `IDocService` / `DocService` — Directory-Scan aus DocsController - `ICalendarService` / `CalendarService` — Gateway-HTTP-Calls + Fallback-Daten aus CalendarController ### Repository-Fixes **IUserRepository / UserRepository:** - `SaveChangesAsync` entfernt (leaky abstraction — Caller sollten nie SaveChanges steuern) - `RevokeTokenAsync(tokenHash)` — atomares Token-Revoke inkl. SaveChanges - `RevokeFamilyAsync(familyId)` — Batch-Revoke einer Token-Familie inkl. SaveChanges - `RemoveExpiredTokensAsync` speichert jetzt selbst (war vorher dependent auf nachfolgenden Save) ### AuthService-Fixes - `GetUserAsync`: unnötiges `Task.Run` entfernt → direkt `_users.GetByIdAsync().AsTask()` - `RevokeAsync`: delegiert jetzt an `IUserRepository.RevokeTokenAsync` - `RefreshAsync`: Token-Reuse-Detection delegiert an `IUserRepository.RevokeFamilyAsync` ### Bug-Fix - `OpenClawGatewayClient.ReadAgentGoalAsync`: pre-existing `CS1656` behoben (`reader` war `using`-Variable und wurde neu zugewiesen — in `reader2` umbenannt) ### Controller (16 Stück — alle slim) Alle Controller reduziert auf: Input validieren → Service aufrufen → HTTP-Result zurückgeben. Kein Business-Logic, kein File-I/O, keine direkte Repository-Nutzung (außer AgentsController für Activity-Log). **Program.cs — neue Registrierungen:** - `AddHttpClient<IOpenClawGatewayClient, OpenClawGatewayClient>` (war vorher konkrete Klasse) - Scoped: IDashboardService, IProjectService, ITaskService, IOperationsService, ITeamService, ICalendarService - Singleton: IAgentConfigService, IMemoryService, IIncidentService, IDocService --- ## Frontend — Dashboard V2 Components **AgentDetailModal.vue, IrisChat.vue, TaskStrip.vue:** - V2 Design-System: Dark Space Theme, Glass-Panels, Gradient-Akzente - Stores (agents, chat, tasks) nutzen Service + Mapper-Pattern - NexusLayout, FlowBoard, Topbar — Layoutfixes für fullHeight-Route-Meta Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
103 lines
3.8 KiB
C#
103 lines
3.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Nexus.Api.Data;
|
|
using Nexus.Api.DTOs;
|
|
using Nexus.Api.Services;
|
|
|
|
namespace Nexus.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/v1/tasks")]
|
|
public class TasksController(ITaskService taskService) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IResult> GetAll(CancellationToken ct)
|
|
=> Results.Ok(await taskService.GetAllAsync(ct));
|
|
|
|
[HttpPost]
|
|
public async Task<IResult> Create([FromBody] CreateTaskRequest request, CancellationToken ct)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Title))
|
|
return Results.ValidationProblem(new Dictionary<string, string[]> { ["title"] = ["Title is required."] });
|
|
|
|
var task = await taskService.CreateAsync(request, ct);
|
|
return Results.Created($"/api/v1/tasks/{task.Id}", task);
|
|
}
|
|
|
|
[HttpGet("pending-approval")]
|
|
public async Task<IResult> GetPendingApproval(CancellationToken ct)
|
|
{
|
|
var pending = await taskService.GetPendingApprovalAsync(ct);
|
|
return Results.Ok(pending.Select(x => new { x.Id, x.Title, x.State, x.Priority, x.ProjectId, x.UpdatedAt }));
|
|
}
|
|
|
|
[HttpPost("{id:guid}/approve")]
|
|
public async Task<IResult> Approve(Guid id, CancellationToken ct)
|
|
{
|
|
var result = await taskService.ApproveAsync(id, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => Results.NotFound(),
|
|
TaskOperationOutcome.InvalidState => Results.Problem(
|
|
title: "Approval denied",
|
|
detail: "Only tasks in 'In progress' or 'Blocked' state can be approved.",
|
|
statusCode: StatusCodes.Status403Forbidden),
|
|
_ => Results.Ok(result.Task)
|
|
};
|
|
}
|
|
|
|
[HttpPost("{id:guid}/reject")]
|
|
public async Task<IResult> Reject(Guid id, CancellationToken ct)
|
|
{
|
|
var result = await taskService.RejectAsync(id, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => Results.NotFound(),
|
|
TaskOperationOutcome.InvalidState => Results.Problem(
|
|
title: "Rejection denied",
|
|
detail: "Only tasks in 'In progress' or 'Blocked' state can be rejected.",
|
|
statusCode: StatusCodes.Status403Forbidden),
|
|
_ => Results.Ok(result.Task)
|
|
};
|
|
}
|
|
|
|
[HttpPatch("{id:guid}/state")]
|
|
public async Task<IResult> UpdateState(Guid id, [FromBody] UpdateTaskStateRequest request, CancellationToken ct)
|
|
{
|
|
if (!TaskStateHelper.IsValidState(request.State))
|
|
return Results.ValidationProblem(new Dictionary<string, string[]> { ["state"] = ["Unsupported task state."] });
|
|
|
|
var result = await taskService.UpdateStateAsync(id, request.State, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => Results.NotFound(),
|
|
_ => Results.Ok(result.Task)
|
|
};
|
|
}
|
|
|
|
[HttpPatch("{id:guid}")]
|
|
public async Task<IResult> Update(Guid id, [FromBody] UpdateTaskRequest request, CancellationToken ct)
|
|
{
|
|
var result = await taskService.UpdateAsync(id, request, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => Results.NotFound(),
|
|
_ => Results.Ok(result.Task)
|
|
};
|
|
}
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
public async Task<IResult> Delete(Guid id, CancellationToken ct)
|
|
{
|
|
var result = await taskService.DeleteAsync(id, ct);
|
|
return result.Outcome switch
|
|
{
|
|
TaskOperationOutcome.NotFound => Results.NotFound(),
|
|
TaskOperationOutcome.InvalidState => Results.Problem(
|
|
title: "Task deletion denied",
|
|
detail: "Only tasks in 'Done' or 'Backlog' state can be deleted.",
|
|
statusCode: StatusCodes.Status403Forbidden),
|
|
_ => Results.NoContent()
|
|
};
|
|
}
|
|
}
|