202a59326b
- Anexo, ContratoBlack, Presupuesto reports (ReportService) - CAEMP (ContratoAbiertoSinSence), CAEMPSNC (ContratoAbiertoConSence) - CC_EMPCSD (ContratoCerradoConDescuento), PropuestaComercial - All endpoints added to ReportController + EmpresaReportController - Fase 1 now 100% complete: 21 controllers, 8 services, 7 repos, 17 reports
94 lines
3.4 KiB
C#
94 lines
3.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<IContratoRepository>(sp =>
|
|
new ContratoRepository(connectionString));
|
|
builder.Services.AddScoped<ICotizacionRepository>(sp =>
|
|
new CotizacionRepository(connectionString));
|
|
builder.Services.AddScoped<IAlumnoRepository>(sp =>
|
|
new AlumnoRepository(connectionString));
|
|
builder.Services.AddScoped<IUsuarioRepository>(sp =>
|
|
new UsuarioRepository(connectionString));
|
|
builder.Services.AddScoped<IInformeRepository>(sp =>
|
|
new InformeRepository(connectionString));
|
|
|
|
builder.Services.AddScoped<LeadService>(sp =>
|
|
new LeadService(connectionString));
|
|
builder.Services.AddScoped<UsuarioService>(sp =>
|
|
new UsuarioService(sp.GetRequiredService<IUsuarioRepository>(), connectionString));
|
|
builder.Services.AddScoped<ContratoService>(sp =>
|
|
new ContratoService(sp.GetRequiredService<IContratoRepository>(), connectionString));
|
|
builder.Services.AddScoped<CotizacionService>(sp =>
|
|
new CotizacionService(sp.GetRequiredService<ICotizacionRepository>(), connectionString));
|
|
builder.Services.AddScoped<AlumnoService>(sp =>
|
|
new AlumnoService(sp.GetRequiredService<IAlumnoRepository>(), connectionString));
|
|
builder.Services.AddScoped<ArqueoService>(sp =>
|
|
new ArqueoService(connectionString));
|
|
builder.Services.AddScoped<InformeService>();
|
|
builder.Services.AddScoped<ReportService>(sp =>
|
|
new ReportService(sp.GetRequiredService<ContratoService>(), sp.GetRequiredService<CotizacionService>(), connectionString));
|
|
builder.Services.AddScoped<EmpresaReportService>(sp =>
|
|
new EmpresaReportService(sp.GetRequiredService<IInformeRepository>(), connectionString));
|
|
|
|
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();
|