Files
KArtSell.Aegis/src/KArtSell.Modules.ModelOperations/Features/ApproveModel/Handler.cs
T
kjh2064 74ddd95a05
ci / backend (push) Failing after 0s
ci / static (push) Failing after 6s
ci / backend (pull_request) Failing after 1s
ci / static (pull_request) Failing after 7s
Build & Test with Secrets / build (pull_request) Failing after 1s
ci / frontend (push) Failing after 48s
Build & Test with Secrets / security-scan (pull_request) Successful in 5s
Build & Test with Secrets / frontend (pull_request) Failing after 1m23s
ci / frontend (pull_request) Failing after 1m32s
Build & Test with Secrets / notification (pull_request) Failing after 2s
테스트 DB 계약과 실행 안전성 정렬
2026-08-02 17:37:12 +09:00

51 lines
1.7 KiB
C#

using Dapper;
using KArtSell.BuildingBlocks.Data;
using KArtSell.BuildingBlocks.Time;
namespace KArtSell.Modules.ModelOperations.Features.ApproveModel;
public sealed class Handler(IDbConnectionFactory connectionFactory, IClock clock)
{
public async Task<Response> HandleAsync(Request request, Guid approverUserId, CancellationToken ct)
{
await using var connection = await connectionFactory.OpenAsync(ct);
// Verify approval exists and is Pending
var existing = await connection.QuerySingleOrDefaultAsync<(Guid Id, string Status)?>("""
SELECT id, status FROM model_operations.approval_queue WHERE run_id = @RunId
""",
new { request.RunId });
if (!existing.HasValue)
throw new InvalidOperationException($"Approval not found for run {request.RunId}");
if (existing.Value.Status != "Pending")
throw new InvalidOperationException($"Approval status is {existing.Value.Status}, not Pending");
// Update approval status (trigger will set approved_at)
var now = MarketTime.SeoulDateTime(clock.UtcNow);
await connection.ExecuteAsync("""
UPDATE model_operations.approval_queue
SET
status = 'Approved',
approved_by = @ApprovedBy,
approval_reason = @ApprovalReason,
approved_at = @ApprovedAt
WHERE run_id = @RunId
""",
new
{
request.RunId,
ApprovedBy = approverUserId,
request.ApprovalReason,
ApprovedAt = now
});
return new Response(
existing.Value.Id,
request.RunId,
"Approved",
now);
}
}