Files
rm-ventas/backend/src/Ventas.API/Program.cs
T
Nurfog e1367fc23a feat: questpdf reports for contrato, cotizacion, arqueo
- ReportService with 3 QuestPDF report generators
- Contrato PDF with header, student info, and course table
- Cotización PDF with customer info, total, and detail table
- Arqueo PDF with cashier summary and payment method breakdowns
- ReportController with endpoints for PDF download
- Registered in DI
2026-07-08 09:22:25 -04:00

80 lines
2.4 KiB
C#

using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Ventas.Infrastructure.Data;
using Ventas.Infrastructure.Repositories;
using Ventas.Core.Interfaces;
using Ventas.Services;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("Default")!;
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddDbContext<VentasDbContext>(options =>
options.UseNpgsql(connectionString));
builder.Services.AddScoped<ILeadRepository>(sp =>
new LeadRepository(connectionString));
builder.Services.AddScoped<ILeadQueryRepository>(sp =>
new LeadQueryRepository(connectionString));
builder.Services.AddScoped<LeadService>(sp =>
new LeadService(connectionString));
builder.Services.AddScoped<UsuarioService>(sp =>
new UsuarioService(connectionString));
builder.Services.AddScoped<ContratoService>(sp =>
new ContratoService(connectionString));
builder.Services.AddScoped<CotizacionService>(sp =>
new CotizacionService(connectionString));
builder.Services.AddScoped<AlumnoService>(sp =>
new AlumnoService(connectionString));
builder.Services.AddScoped<InformeService>(sp =>
new InformeService(connectionString));
builder.Services.AddScoped<ReportService>();
var jwtSecret = builder.Configuration["Jwt:Secret"] ?? "default-dev-secret-change-in-production";
var jwtExpiration = int.Parse(builder.Configuration["Jwt:ExpirationMinutes"] ?? "30");
builder.Services.AddScoped<JwtService>(sp =>
new JwtService(jwtSecret, jwtExpiration));
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecret))
};
});
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();