mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 06:58:57 +00:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using ProposalSystem.Domain.Entities;
|
||
|
|
using ProposalSystem.Infrastructure.Data;
|
||
|
|
|
||
|
|
namespace ProposalSystem.Api.Controllers;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/generated-pdfs")]
|
||
|
|
[Authorize]
|
||
|
|
public class GeneratedPdfsController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly ProposalDbContext _db;
|
||
|
|
|
||
|
|
public GeneratedPdfsController(ProposalDbContext db)
|
||
|
|
{
|
||
|
|
_db = db;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<IActionResult> Create([FromBody] CreateGeneratedPdfRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var proposal = await _db.Proposals.FindAsync(new object[] { request.ProposalId }, ct);
|
||
|
|
if (proposal == null) return NotFound();
|
||
|
|
|
||
|
|
var pdf = new GeneratedPdf
|
||
|
|
{
|
||
|
|
Id = Guid.NewGuid(),
|
||
|
|
ProposalId = request.ProposalId,
|
||
|
|
Revision = proposal.CurrentRevision,
|
||
|
|
S3Key = request.S3Key,
|
||
|
|
GeneratedAt = DateTime.UtcNow,
|
||
|
|
GeneratedById = Guid.Empty,
|
||
|
|
};
|
||
|
|
|
||
|
|
_db.GeneratedPdfs.Add(pdf);
|
||
|
|
await _db.SaveChangesAsync(ct);
|
||
|
|
|
||
|
|
return Created($"/api/generated-pdfs/{pdf.Id}", new { pdf.Id, pdf.S3Key, pdf.Revision });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public record CreateGeneratedPdfRequest(Guid ProposalId, string S3Key);
|