2025-01-24 19:17:26 -03:00
|
|
|
using Core.Interfaces;
|
|
|
|
|
using Core.Services;
|
|
|
|
|
using Google.Authenticator;
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
|
using Models.Interfaces;
|
|
|
|
|
using Models.Models;
|
|
|
|
|
using Models.Repositories;
|
|
|
|
|
using phronCare.API.Models;
|
|
|
|
|
using Services.Models;
|
|
|
|
|
using Services.Services;
|
|
|
|
|
using Services.Interfaces;
|
|
|
|
|
using System.Text;
|
2025-04-20 19:58:17 -03:00
|
|
|
using Infrastructure.Repositories.Patients;
|
2025-04-27 02:19:29 -03:00
|
|
|
using PhronCare.Core.Services.Sales;
|
|
|
|
|
using PhronCare.Core.Data.Repositories.Sales;
|
2025-01-24 19:17:26 -03:00
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2025-03-22 01:19:48 -03:00
|
|
|
|
|
|
|
|
#region AppSetting configuration
|
|
|
|
|
// Asegurar que el archivo appsettings.json se cargue correctamente
|
2025-01-28 18:56:36 -03:00
|
|
|
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
|
|
|
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
2025-03-22 01:19:48 -03:00
|
|
|
#endregion
|
2025-01-24 19:17:26 -03:00
|
|
|
|
2025-03-22 01:19:48 -03:00
|
|
|
#region DbContext Identity Configuration and Operational
|
2025-01-24 19:17:26 -03:00
|
|
|
var configuration = builder.Configuration;
|
2025-03-22 01:19:48 -03:00
|
|
|
builder.Services.AddDbContext<phronCareDbContext>(options => options.UseSqlServer(configuration.GetConnectionString("phronCareDB"))); // DB Seguridad
|
2025-01-24 19:17:26 -03:00
|
|
|
builder.Services.AddDbContext<PhronCareOperationsHubContext>(options =>
|
2025-03-22 01:19:48 -03:00
|
|
|
options.UseSqlServer(configuration.GetConnectionString("PhronCareOperationsHubConnection"))); // DB Operacional
|
2025-04-03 15:49:04 -03:00
|
|
|
#endregion
|
2025-01-24 19:17:26 -03:00
|
|
|
|
2025-04-03 15:49:04 -03:00
|
|
|
#region Repositorios y Servicios
|
|
|
|
|
builder.Services.AddScoped<ITicketDom, TicketService>();
|
2025-04-04 14:58:44 -03:00
|
|
|
builder.Services.AddScoped<ITicketRepository, TicketRepository>();
|
2025-04-18 02:01:12 -03:00
|
|
|
|
2025-04-03 15:49:04 -03:00
|
|
|
builder.Services.AddScoped<IAccountTypeDom, AccountTypeService>();
|
2025-04-04 14:58:44 -03:00
|
|
|
builder.Services.AddScoped<IPhSAccountTypeRepository, PhSAccountTypeRepository>();
|
2025-04-18 02:01:12 -03:00
|
|
|
|
2025-04-10 19:09:51 -03:00
|
|
|
builder.Services.AddScoped<ITaxConditionDom, TaxConditionService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSTaxConditionRepository, PhOhTaxConditionRepository>();
|
2025-04-18 02:01:12 -03:00
|
|
|
|
2025-04-03 21:49:59 -03:00
|
|
|
builder.Services.AddScoped<IDocumentTypeDom, DocumentTypeService>();
|
2025-04-04 14:58:44 -03:00
|
|
|
builder.Services.AddScoped<IPhSDocumentTypeRepository, PhSDocumentTypeRepository>();
|
2025-04-18 02:01:12 -03:00
|
|
|
|
2025-04-04 14:58:44 -03:00
|
|
|
builder.Services.AddScoped<ICustomerDom, CustomerService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSCustomerRepository, PhSCustomerRepository>();
|
2025-04-18 02:01:12 -03:00
|
|
|
|
|
|
|
|
builder.Services.AddScoped<IProductDom, ProductService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSProductRepository, PhSProductRepository>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddScoped<ICustomerDom, CustomerService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSCustomerRepository, PhSCustomerRepository>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddScoped<IProductCategoryDom, ProductCategoryService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSProductCategoryRepository, PhSProductCategoryRepository>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddScoped<IBusinessUnitDom, BusinessUnitService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSBusinessUnitRepository, PhSBusinessUnitRepository>();
|
|
|
|
|
|
2025-04-20 19:58:17 -03:00
|
|
|
builder.Services.AddScoped<IPatientDom, PatientService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSPatientRepository, PhSPatientRepository>();
|
|
|
|
|
|
2025-04-24 20:03:42 -03:00
|
|
|
builder.Services.AddScoped<IProfessionalSpecialtyDom, ProfessionalSpecialtyService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSProfessionalSpecialtyRepository, PhSProfessionalSpecialtyRepository>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddScoped<IProfessionalDom, ProfessionalService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSProfessionalRepository, PhSProfessionalRepository>();
|
|
|
|
|
|
2025-04-20 19:58:17 -03:00
|
|
|
builder.Services.AddScoped<IInstitutionDom, InstitutionService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSInstitutionRepository, PhSInstitutionRepository>();
|
2025-04-28 14:38:00 -03:00
|
|
|
|
|
|
|
|
builder.Services.AddScoped<IPeopleDom, PeopleService>();
|
|
|
|
|
builder.Services.AddScoped<IPhSPeopleRepository, PhSPeopleRepository>();
|
|
|
|
|
|
2025-04-27 02:19:29 -03:00
|
|
|
builder.Services.AddScoped<IQuoteDom, QuoteService>();
|
2025-04-28 14:38:00 -03:00
|
|
|
|
2025-04-27 02:19:29 -03:00
|
|
|
builder.Services.AddScoped<IPhSQuoteHeaderRepository, PhSQuoteHeaderRepository>();
|
|
|
|
|
builder.Services.AddScoped<IPhSQuoteDetailRepository, PhSQuoteDetailRepository>();
|
|
|
|
|
builder.Services.AddScoped<IPhSQuoteRoleRepository, PhSQuoteRoleRepository>();
|
|
|
|
|
builder.Services.AddScoped<IPhSFormSeriesRepository, PhSFormSeriesRepository>();
|
|
|
|
|
|
2025-01-24 19:17:26 -03:00
|
|
|
#endregion
|
2025-03-22 01:19:48 -03:00
|
|
|
|
2025-01-24 19:17:26 -03:00
|
|
|
#region Require Confirmed Email
|
2025-03-22 01:19:48 -03:00
|
|
|
builder.Services.Configure<IdentityOptions>(opts => opts.SignIn.RequireConfirmedEmail = true);
|
2025-01-24 19:17:26 -03:00
|
|
|
#endregion
|
2025-03-22 01:19:48 -03:00
|
|
|
|
|
|
|
|
#region Security Identity EF Configuration
|
2025-01-24 19:17:26 -03:00
|
|
|
builder.Services.AddIdentity<IdentityUser, IdentityRole>()
|
|
|
|
|
.AddEntityFrameworkStores<phronCareDbContext>()
|
|
|
|
|
.AddDefaultTokenProviders();
|
|
|
|
|
builder.Services.Configure<DataProtectionTokenProviderOptions>( opts => opts.TokenLifespan=TimeSpan.FromHours(10));
|
2025-03-22 01:19:48 -03:00
|
|
|
builder.Services.AddSingleton<TwoFactorAuthenticator>();
|
|
|
|
|
#endregion
|
2025-01-24 19:17:26 -03:00
|
|
|
|
|
|
|
|
#region Authentication Service
|
|
|
|
|
|
|
|
|
|
builder.Services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
}).AddJwtBearer(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Audience = configuration["JWT:ValidAudience"];
|
|
|
|
|
options.RequireHttpsMetadata = false;
|
|
|
|
|
options.SaveToken = true;
|
|
|
|
|
options.IncludeErrorDetails = true;
|
|
|
|
|
options.TokenValidationParameters = new TokenValidationParameters
|
|
|
|
|
{
|
|
|
|
|
ValidateIssuer = true,
|
|
|
|
|
ValidateAudience = true,
|
|
|
|
|
ValidateIssuerSigningKey = true,
|
|
|
|
|
ValidIssuer = configuration["JWT:ValidIssuer"],
|
|
|
|
|
ValidAudience = configuration["JWT:ValidAudience"],
|
|
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(configuration["JWT:Secret"])),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Email Configuration
|
|
|
|
|
var emailConfig = configuration.GetSection("EmailConfiguration").Get<EmailConfiguration>();
|
2025-01-28 18:56:36 -03:00
|
|
|
if (emailConfig == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("La configuración del correo electrónico no se encontró o es inválida.");
|
|
|
|
|
}
|
2025-01-24 19:17:26 -03:00
|
|
|
builder.Services.AddSingleton(emailConfig);
|
|
|
|
|
builder.Services.AddScoped<IEmailService, EmailService>();
|
|
|
|
|
#endregion
|
|
|
|
|
|
2025-03-22 01:19:48 -03:00
|
|
|
#region Swagger Configuration
|
2025-01-24 19:17:26 -03:00
|
|
|
builder.Services.AddSwaggerGen(option =>
|
|
|
|
|
{
|
|
|
|
|
option.SwaggerDoc("v1", new OpenApiInfo { Title = "phronCARE API - SaludLAB", Version = "v1" });
|
|
|
|
|
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
|
|
|
|
{
|
|
|
|
|
In = ParameterLocation.Header,
|
|
|
|
|
Description = "Por favor, ingrese un token valido",
|
|
|
|
|
Name = "Authorization",
|
|
|
|
|
Type = SecuritySchemeType.Http,
|
|
|
|
|
BearerFormat = "JWT",
|
|
|
|
|
Scheme = "Bearer"
|
|
|
|
|
});
|
|
|
|
|
option.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
new OpenApiSecurityScheme
|
|
|
|
|
{
|
|
|
|
|
Reference = new OpenApiReference
|
|
|
|
|
{
|
|
|
|
|
Type=ReferenceType.SecurityScheme,
|
|
|
|
|
Id="Bearer"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new string[]{}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
#endregion
|
|
|
|
|
|
2025-03-22 01:19:48 -03:00
|
|
|
#region CORS sin cambios
|
2025-01-31 15:03:49 -03:00
|
|
|
// builder.Services.AddCors(p => p.AddPolicy("CORS", builder =>
|
|
|
|
|
// {
|
|
|
|
|
// builder
|
|
|
|
|
// .AllowAnyOrigin()
|
|
|
|
|
// .AllowAnyMethod()
|
|
|
|
|
// .AllowAnyHeader();
|
|
|
|
|
// }));
|
|
|
|
|
builder.Services.AddCors(options =>
|
2025-01-24 19:17:26 -03:00
|
|
|
{
|
2025-02-03 16:12:07 -03:00
|
|
|
|
2025-01-31 15:03:49 -03:00
|
|
|
options.AddPolicy("CORS", policy =>
|
|
|
|
|
{
|
2025-02-03 16:12:07 -03:00
|
|
|
/*
|
|
|
|
|
Version para despliegue
|
|
|
|
|
*/
|
|
|
|
|
// policy
|
|
|
|
|
// .WithOrigins("http://dev.biodec.saludlab.com.ar", "http://phroncareUI:80", "http://192.168.10.110:9002")
|
|
|
|
|
// .AllowAnyMethod()
|
|
|
|
|
// .AllowAnyHeader()
|
|
|
|
|
// .AllowCredentials();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Version para desarrollo
|
|
|
|
|
*/
|
|
|
|
|
policy.WithOrigins("*").AllowAnyHeader().AllowAnyMethod();
|
2025-01-31 15:03:49 -03:00
|
|
|
});
|
|
|
|
|
});
|
2025-01-24 19:17:26 -03:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
|
2025-04-29 09:26:01 -03:00
|
|
|
Console.WriteLine($"JWT Issuer: {configuration["JWT:ValidIssuer"]}");
|
|
|
|
|
Console.WriteLine($"JWT Audience: {configuration["JWT:ValidAudience"]}");
|
|
|
|
|
|
2025-01-24 19:17:26 -03:00
|
|
|
var app = builder.Build();
|
|
|
|
|
|
2025-04-03 17:31:07 -03:00
|
|
|
//if (app.Environment.IsDevelopment())
|
|
|
|
|
//{
|
2025-01-24 19:17:26 -03:00
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
2025-04-03 17:31:07 -03:00
|
|
|
//}
|
2025-01-24 19:17:26 -03:00
|
|
|
|
|
|
|
|
app.UseCors("CORS");
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
2025-01-31 15:03:49 -03:00
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
app.MapControllers();
|
2025-03-22 01:19:48 -03:00
|
|
|
|
2025-01-24 19:17:26 -03:00
|
|
|
app.Run();
|