Implement Backend API Core (Phase 1)
Complete API layer with Clean Architecture:
- Application DTOs (proposals, line items, customers, users, files, audit, dashboard)
- Service interfaces (IProposalService, ILineItemService, ICustomerService, IAuditService, IS3Service, IJobPublisher)
- FluentValidation validators for all create requests
- Infrastructure service implementations (ProposalService, LineItemService, CustomerService, AuditService, S3Service, SqsJobPublisher, ProposalNumberGenerator)
- Secrets Manager connection string resolver for RDS
- API controllers: Proposals (CRUD + approve/send/revise), LineItems (CRUD + bulk), Customers, Users, Files (presigned upload/download), Admin (dashboard)
- Middleware: GlobalExceptionHandler (ProblemDetails), ValidationFilter (FluentValidation pipeline)
- CurrentUserService (Cognito JWT claims -> User entity, auto-provisioning)
- Full DI configuration in Program.cs with Lambda hosting
- Role-based authorization (dispatchers, admins, sysadmins)
- CORS configured for proposals.seahaven.com + localhost
2026-05-16 18:49:48 -04:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using ProposalSystem.Application.Interfaces;
|
|
|
|
|
using ProposalSystem.Infrastructure.Data;
|
|
|
|
|
|
|
|
|
|
namespace ProposalSystem.Infrastructure.Services;
|
|
|
|
|
|
|
|
|
|
public class ProposalNumberGenerator : IProposalNumberGenerator
|
|
|
|
|
{
|
|
|
|
|
private readonly ProposalDbContext _db;
|
|
|
|
|
|
|
|
|
|
public ProposalNumberGenerator(ProposalDbContext db)
|
|
|
|
|
{
|
|
|
|
|
_db = db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<string> GenerateAsync(CancellationToken ct = default)
|
|
|
|
|
{
|
|
|
|
|
var year = DateTime.UtcNow.Year;
|
|
|
|
|
var prefix = $"SHI-{year}-";
|
|
|
|
|
|
2026-05-20 18:51:31 -04:00
|
|
|
// Advisory lock prevents concurrent number generation within the same transaction
|
|
|
|
|
await _db.Database.ExecuteSqlRawAsync(
|
|
|
|
|
"SELECT pg_advisory_xact_lock(hashtext('proposal_number_gen'))", ct);
|
|
|
|
|
|
Implement Backend API Core (Phase 1)
Complete API layer with Clean Architecture:
- Application DTOs (proposals, line items, customers, users, files, audit, dashboard)
- Service interfaces (IProposalService, ILineItemService, ICustomerService, IAuditService, IS3Service, IJobPublisher)
- FluentValidation validators for all create requests
- Infrastructure service implementations (ProposalService, LineItemService, CustomerService, AuditService, S3Service, SqsJobPublisher, ProposalNumberGenerator)
- Secrets Manager connection string resolver for RDS
- API controllers: Proposals (CRUD + approve/send/revise), LineItems (CRUD + bulk), Customers, Users, Files (presigned upload/download), Admin (dashboard)
- Middleware: GlobalExceptionHandler (ProblemDetails), ValidationFilter (FluentValidation pipeline)
- CurrentUserService (Cognito JWT claims -> User entity, auto-provisioning)
- Full DI configuration in Program.cs with Lambda hosting
- Role-based authorization (dispatchers, admins, sysadmins)
- CORS configured for proposals.seahaven.com + localhost
2026-05-16 18:49:48 -04:00
|
|
|
var lastNumber = await _db.Proposals
|
|
|
|
|
.Where(p => p.ProposalNumber.StartsWith(prefix))
|
2026-05-20 18:51:31 -04:00
|
|
|
.Where(p => !p.ProposalNumber.Contains("-R"))
|
Implement Backend API Core (Phase 1)
Complete API layer with Clean Architecture:
- Application DTOs (proposals, line items, customers, users, files, audit, dashboard)
- Service interfaces (IProposalService, ILineItemService, ICustomerService, IAuditService, IS3Service, IJobPublisher)
- FluentValidation validators for all create requests
- Infrastructure service implementations (ProposalService, LineItemService, CustomerService, AuditService, S3Service, SqsJobPublisher, ProposalNumberGenerator)
- Secrets Manager connection string resolver for RDS
- API controllers: Proposals (CRUD + approve/send/revise), LineItems (CRUD + bulk), Customers, Users, Files (presigned upload/download), Admin (dashboard)
- Middleware: GlobalExceptionHandler (ProblemDetails), ValidationFilter (FluentValidation pipeline)
- CurrentUserService (Cognito JWT claims -> User entity, auto-provisioning)
- Full DI configuration in Program.cs with Lambda hosting
- Role-based authorization (dispatchers, admins, sysadmins)
- CORS configured for proposals.seahaven.com + localhost
2026-05-16 18:49:48 -04:00
|
|
|
.OrderByDescending(p => p.ProposalNumber)
|
|
|
|
|
.Select(p => p.ProposalNumber)
|
|
|
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
|
|
|
|
|
|
int nextSequence = 1;
|
|
|
|
|
if (lastNumber != null)
|
|
|
|
|
{
|
|
|
|
|
var sequencePart = lastNumber[prefix.Length..];
|
|
|
|
|
if (int.TryParse(sequencePart, out var current))
|
|
|
|
|
{
|
|
|
|
|
nextSequence = current + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $"{prefix}{nextSequence:D4}";
|
|
|
|
|
}
|
|
|
|
|
}
|