diff --git a/DocuMed.Api/AppSettings/Production/appsettings.Production.json b/DocuMed.Api/AppSettings/Production/appsettings.Production.json
new file mode 100644
index 0000000..d386c77
--- /dev/null
+++ b/DocuMed.Api/AppSettings/Production/appsettings.Production.json
@@ -0,0 +1,56 @@
+{
+ "ConnectionStrings": {
+ "Postgres": "User ID=postgres;Password=root;Host=localhost;Port=5432;Database=iGarsonDB;",
+ "PostgresServer": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS"
+ },
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "None",
+ "Microsoft.Hosting.Lifetime": "Information",
+ "Microsoft.AspNetCore.SignalR": "Debug",
+ "Microsoft.AspNetCore.Http.Connections": "Debug"
+ }
+ },
+ "SiteSettings": {
+ "BaseUrl": "http://localhost:32769",
+ "UserSetting": {
+ "Username": "Root",
+ "Email": "info@brizco.io",
+ "Password": "root1234",
+ "Phone": "09211111111",
+ "RoleName": "RootAdmin",
+ "FirstName": "همه کاره",
+ "LastName": "سیستم"
+ },
+ "JwtSettings": {
+ "SecretKey": "pg8mt74/bk5yx2mr23Zvsu/81Z2czAycEo9ewcm34AndD8SFDXGqBiYv_YaHosseinYaAli_ABOOOOOOOOOLFAZL_BIMEH_JAD_NASABE_YA_GHARIBAL_GHORABA_@@@@_06/0CZWyAqy2H6Xpjp0npg8mt74/bk5yx2mr23Zvsu/81Z2czAycEo9ewcm34AndD8SFDXGqBiYvACLB0dED9vjy+h5sK1BnB30=",
+ "Issuer": "Brizco",
+ "Audience": "Brizco",
+ "ExpireAddDay": "15"
+ }
+ },
+ "IpRateLimiting": {
+ "EnableEndpointRateLimiting": false,
+ "StackBlockedRequests": false,
+ "RealIpHeader": "X-Real-IP",
+ "ClientIdHeader": "X-ClientId",
+ "HttpStatusCode": 429,
+ "IpWhitelist": [ "127.0.0.1", "::1/10", "192.168.0.0/24" ],
+ "EndpointWhitelist": [ "get:/api/license", "*:/api/status" ],
+ "ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
+ "GeneralRules": [
+ {
+ "Endpoint": "*",
+ "Period": "1m",
+ "Limit": 60
+ },
+ {
+ "Endpoint": "*",
+ "Period": "15m",
+ "Limit": 250
+ }
+ ]
+ },
+ "AllowedHosts": "*"
+}
\ No newline at end of file
diff --git a/DocuMed.Api/appsettings.Development.json b/DocuMed.Api/AppSettings/Production/appsettings.json
similarity index 100%
rename from DocuMed.Api/appsettings.Development.json
rename to DocuMed.Api/AppSettings/Production/appsettings.json
diff --git a/DocuMed.Api/AppSettings/appsettings.Development.json b/DocuMed.Api/AppSettings/appsettings.Development.json
new file mode 100644
index 0000000..980f464
--- /dev/null
+++ b/DocuMed.Api/AppSettings/appsettings.Development.json
@@ -0,0 +1,56 @@
+{
+ "ConnectionStrings": {
+ "Postgres": "User ID=postgres;Password=root;Host=localhost;Port=5432;Database=iGarsonDB;",
+ "PostgresServer": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS",
+ },
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "None",
+ "Microsoft.Hosting.Lifetime": "Information",
+ "Microsoft.AspNetCore.SignalR": "Debug",
+ "Microsoft.AspNetCore.Http.Connections": "Debug"
+ }
+ },
+ "SiteSettings": {
+ "BaseUrl": "http://localhost:32769",
+ "UserSetting": {
+ "Username": "root",
+ "Email": "info@documed.ir",
+ "Password": "i1nLGN86rU/HQgzC",
+ "Phone": "09211111111",
+ "RoleName": "RootAdmin",
+ "FirstName": "همه کاره",
+ "LastName": "سیستم"
+ },
+ "JwtSettings": {
+ "SecretKey": "YaHosseinYaAli_pg8mt74/bk5yx2mr23Zvsu/81Z2czAycEo9ewcm34AndD8SFDXGqBiYv_ABOOOOOOOOOLFAZL_BIMEH_JAD_NASABE_pg8mt74/bk5yx2mr23Zvsu/81Z2czAycEo9ewcm34AndD8SFDXGqBiYv_YA_GHARIBAL_GHORABA_@@@@_06/0CZWyAqy2H6Xpjp0npg8mt74/bk5yx2mr23Zvsu/81Z2czAycEo9ewcm34AndD8SFDXGqBiYvACLB0dED9vjy+h5sK1BnB30=",
+ "Issuer": "Brizco",
+ "Audience": "Brizco",
+ "ExpireAddDay": "15"
+ }
+ },
+ "IpRateLimiting": {
+ "EnableEndpointRateLimiting": false,
+ "StackBlockedRequests": false,
+ "RealIpHeader": "X-Real-IP",
+ "ClientIdHeader": "X-ClientId",
+ "HttpStatusCode": 429,
+ "IpWhitelist": [ "127.0.0.1", "::1/10", "192.168.0.0/24" ],
+ "EndpointWhitelist": [ "get:/api/license", "*:/api/status" ],
+ "ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
+ "GeneralRules": [
+ {
+ "Endpoint": "*",
+ "Period": "1m",
+ "Limit": 60
+ },
+ {
+ "Endpoint": "*",
+ "Period": "15m",
+ "Limit": 250
+ }
+ ]
+ },
+ "AllowedHosts": "*"
+}
\ No newline at end of file
diff --git a/DocuMed.Api/appsettings.json b/DocuMed.Api/AppSettings/appsettings.json
similarity index 100%
rename from DocuMed.Api/appsettings.json
rename to DocuMed.Api/AppSettings/appsettings.json
diff --git a/DocuMed.Api/DocuMed.Api.csproj b/DocuMed.Api/DocuMed.Api.csproj
index 3102210..586307d 100644
--- a/DocuMed.Api/DocuMed.Api.csproj
+++ b/DocuMed.Api/DocuMed.Api.csproj
@@ -53,4 +53,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DocuMed.Api/Program.cs b/DocuMed.Api/Program.cs
index df2434c..b6665e2 100644
--- a/DocuMed.Api/Program.cs
+++ b/DocuMed.Api/Program.cs
@@ -1,23 +1,96 @@
+using DocuMed.Api.WebFramework.MiddleWares;
+
var builder = WebApplication.CreateBuilder(args);
+builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
+builder.Host.UseSerilog();
+LoggerConfig.ConfigureSerilog();
+string env = builder.Environment.IsDevelopment() == true ? "Development" : "Production";
+builder.Host.UseContentRoot(Directory.GetCurrentDirectory());
+
+if (builder.Environment.IsDevelopment())
+ builder.Configuration
+ .AddJsonFile($"AppSettings/appsettings.json")
+ .AddJsonFile($"AppSettings/appsettings.{env}.json");
+
+if (builder.Environment.IsProduction())
+ builder.Configuration
+ .AddJsonFile($"AppSettings/Production/appsettings.{env}.json");
+var configuration = builder.Configuration;
+var siteSetting = configuration.GetSection(nameof(SiteSettings)).Get();
+builder.Services.Configure(configuration.GetSection(nameof(SiteSettings)));
// Add services to the container.
+
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
-builder.Services.AddSwaggerGen();
+builder.Services.AddCustomSwagger(siteSetting.BaseUrl);
+builder.Services.AddCustomApiVersioning();
+builder.Services.AddCustomController();
+builder.Services.AddControllers();
+builder.Services.AddCustomResponseCompression();
+builder.Services.AddCustomMvc();
+builder.Services.AddCustomAuthorization();
+builder.Services.AddJwtCustomAuthentication(siteSetting.JwtSettings);
+builder.Services.AddCustomIdentity();
+builder.Services.AddCustomDbContext(configuration);
+builder.Services.AddCarter();
+
+builder.Host.ConfigureContainer(builder =>
+{
+
+ var assembly = typeof(CoreConfig).Assembly;
+ builder
+ .RegisterAssemblyTypes(assembly)
+ .AssignableTo()
+ .AsImplementedInterfaces()
+ .InstancePerLifetimeScope();
+
+ var assemblyB = typeof(InfrastructureConfig).Assembly;
+ builder.RegisterAssemblyTypes(assemblyB)
+ .AssignableTo()
+ .AsImplementedInterfaces()
+ .InstancePerLifetimeScope();
+
+ var assemblyC = typeof(RepositoryConfig).Assembly;
+ builder.RegisterAssemblyTypes(assemblyC)
+ .AssignableTo()
+ .AsImplementedInterfaces()
+ .InstancePerLifetimeScope();
+
+
+ var assemblyD = typeof(Program).Assembly;
+ builder.RegisterAssemblyTypes(assemblyD)
+ .AssignableTo()
+ .AsImplementedInterfaces()
+ .InstancePerLifetimeScope();
+});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
- app.UseSwagger();
- app.UseSwaggerUI();
+ app.UseCustomSwagger(siteSetting.BaseUrl);
+ //app.UseSwagger();
+ //app.UseSwaggerUI();
}
app.UseAuthorization();
+app.UseAuthentication();
+app.UseCors(x => x
+ .SetIsOriginAllowed(origin => true)
+ .AllowAnyMethod()
+ .AllowAnyHeader()
+ .AllowCredentials());
+
+app.UseExceptionHandlerMiddleware();
+
+app.MapCarter();
+app.UseStaticFiles();
+await app.InitialDb();
app.MapControllers();
app.Run();
diff --git a/DocuMed.Api/Services/CurrentUserService.cs b/DocuMed.Api/Services/CurrentUserService.cs
new file mode 100644
index 0000000..7ca8c8e
--- /dev/null
+++ b/DocuMed.Api/Services/CurrentUserService.cs
@@ -0,0 +1,15 @@
+namespace DocuMed.Api.Services;
+
+public class CurrentUserService : ICurrentUserService
+{
+ private readonly IHttpContextAccessor _httpContextAccessor;
+
+ public CurrentUserService(IHttpContextAccessor httpContextAccessor)
+ {
+ _httpContextAccessor = httpContextAccessor;
+ }
+
+ public string? UserId => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.NameIdentifier);
+ public string? RoleName => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Role);
+ public string? UserName => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name);
+}
\ No newline at end of file
diff --git a/DocuMed.Api/WebFramework/Bases/ApiResultFilterAttribute.cs b/DocuMed.Api/WebFramework/Bases/ApiResultFilterAttribute.cs
new file mode 100644
index 0000000..52ae250
--- /dev/null
+++ b/DocuMed.Api/WebFramework/Bases/ApiResultFilterAttribute.cs
@@ -0,0 +1,74 @@
+namespace DocuMed.Api.WebFramework.Bases;
+
+public class ApiResultFactory
+{
+
+}
+public class ApiResultFilterAttribute : ActionFilterAttribute
+{
+ public override void OnResultExecuting(ResultExecutingContext context)
+ {
+ if (context.Result is OkObjectResult okObjectResult)
+ {
+ var apiResult = new ApiResult