diff --git a/api/src/Kurs.Platform.Application/CustomEndpoints/CustomEndpointAppService.cs b/api/src/Kurs.Platform.Application/CustomEndpoints/CustomEndpointAppService.cs index 208cd881..3e52ec43 100644 --- a/api/src/Kurs.Platform.Application/CustomEndpoints/CustomEndpointAppService.cs +++ b/api/src/Kurs.Platform.Application/CustomEndpoints/CustomEndpointAppService.cs @@ -59,11 +59,15 @@ public class CustomEndpointAppService : PlatformAppService try { - // Request.Path = /api/app/public-api/yxcdfn/8 - var path = httpContextAccessor.HttpContext.Request.Path.ToString() - .Replace("/api/app/public-api", "") + // Request.Path = /api/app/custom-endpoint/yxcdfn/8 + var rawPath = httpContextAccessor.HttpContext.Request.Path.ToString(); + var decodedPath = Uri.UnescapeDataString(rawPath); // URL decode işlemi + + var path = decodedPath + .Replace("/api/app/custom-endpoint", "", StringComparison.OrdinalIgnoreCase) .EnsureStartsWith('/') .EnsureEndsWith('/'); + Logger.LogInformation("Custom Endpoint çağrısı. Kullanıcı:{user} Path:[{method}]{path}", CurrentUser.UserName, "GET", path); var api = await repo.FirstOrDefaultAsync(a => path.StartsWith(a.Url) && a.Method == method); if (api is null) @@ -216,7 +220,7 @@ username=system%40sozsoft.com &scope=offline_access%20Platform Custom Endpoint Seed: -select * from PLanguage WHERE IsEnabled = @IsEnabled AND CultureName = @CultureName +SELECT * FROM PLanguage WHERE IsEnabled = @IsEnabled AND CultureName = @CultureName INSERT INTO [dbo].[Orders] ([CustomerName] ,[ProductName] diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformDataSeeder.cs b/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformDataSeeder.cs index d425fb2b..ec2286fb 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformDataSeeder.cs +++ b/api/src/Kurs.Platform.DbMigrator/Seeds/PlatformDataSeeder.cs @@ -55,7 +55,8 @@ public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency private readonly IRepository _blogPostsRepository; private readonly IRepository _forumCategoryRepository; private readonly IRepository _aiBotRepository; - private readonly IRepository _RouteRepository; + private readonly IRepository _routeRepository; + private readonly IRepository _customEndpointRepository; public PlatformDataSeeder( IRepository languages, @@ -86,7 +87,8 @@ public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency IRepository blogPostsRepository, IRepository forumCategoryRepository, IRepository aiBotRepository, - IRepository RouteRepository + IRepository RouteRepository, + IRepository CustomEndpointRepository ) { _languages = languages; @@ -117,7 +119,8 @@ public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency _blogPostsRepository = blogPostsRepository; _forumCategoryRepository = forumCategoryRepository; _aiBotRepository = aiBotRepository; - _RouteRepository = RouteRepository; + _routeRepository = RouteRepository; + _customEndpointRepository = CustomEndpointRepository; } private static IConfigurationRoot BuildConfiguration() @@ -639,11 +642,11 @@ public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency foreach (var item in items.Routes) { - var exists = await _RouteRepository.AnyAsync(x => x.Key == item.Key); + var exists = await _routeRepository.AnyAsync(x => x.Key == item.Key); if (!exists) { - await _RouteRepository.InsertAsync(new Route( + await _routeRepository.InsertAsync(new Route( item.Key, item.Path, item.ComponentPath, @@ -652,5 +655,24 @@ public class PlatformDataSeeder : IDataSeedContributor, ITransientDependency )); } } + + foreach (var item in items.CustomEndpoints) + { + var exists = await _customEndpointRepository.AnyAsync(x => x.Name == item.Name); + + if (!exists) + { + await _customEndpointRepository.InsertAsync(new CustomEndpoint( + item.Name, + item.Description, + item.Url, + item.Method, + item.DataSourceCode, + item.Sql, + JsonSerializer.Serialize(item.ParametersJson), + JsonSerializer.Serialize(item.PermissionsJson) + )); + } + } } } diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json b/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json index a38f2f31..25c0b720 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json +++ b/api/src/Kurs.Platform.DbMigrator/Seeds/SeederData.json @@ -21698,5 +21698,34 @@ "routeType": "protected", "authority": [] } + ], + "CustomEndpoints": [ + { + "Name": "Langugage", + "Description": "https://localhost:44344/api/app/custom-endpoint/dil/en", + "Url": "/dil/", + "Method": "GET", + "DataSourceCode": "Default", + "Sql": "SELECT * FROM PLanguage WHERE IsEnabled = @IsEnabled AND CultureName = @CultureName", + "ParametersJson": [ + { + "Type": "P", + "Name": "CultureName", + "DefaultValue": "ar", + "Path": "/dil/:CultureName/" + }, + { + "Type": "S", + "Name": "IsEnabled", + "DefaultValue": "true" + } + ], + "PermissionsJson": [ + { + "ResourceType": "User", + "ResourceId": "system@sozsoft.com" + } + ] + } ] } \ No newline at end of file diff --git a/api/src/Kurs.Platform.DbMigrator/Seeds/SeederDto.cs b/api/src/Kurs.Platform.DbMigrator/Seeds/SeederDto.cs index 3716ba4e..ed709e23 100644 --- a/api/src/Kurs.Platform.DbMigrator/Seeds/SeederDto.cs +++ b/api/src/Kurs.Platform.DbMigrator/Seeds/SeederDto.cs @@ -38,6 +38,7 @@ public class SeederDto public List ForumCategories { get; set; } public List AiBots { get; set; } public List Routes { get; set; } + public List CustomEndpoints { get; set; } } public class ChartsSeedDto @@ -254,3 +255,16 @@ public class RouteSeedDto public string RouteType { get; set; } public string[] Authority { get; set; } } + +public class CustomEndpointSeedDto +{ + public string Name { get; set; } + public string Description { get; set; } + public string Url { get; set; } + public string Method { get; set; } + public string DataSourceCode { get; set; } + public string Sql { get; set; } + public List ParametersJson { get; set; } + public List PermissionsJson { get; set; } +} + diff --git a/api/src/Kurs.Platform.Domain/Entities/CustomEndpoint.cs b/api/src/Kurs.Platform.Domain/Entities/CustomEndpoint.cs index a5fd5dd3..78c7a83a 100644 --- a/api/src/Kurs.Platform.Domain/Entities/CustomEndpoint.cs +++ b/api/src/Kurs.Platform.Domain/Entities/CustomEndpoint.cs @@ -55,6 +55,18 @@ public class CustomEndpoint : FullAuditedEntity, IMultiTenant PermissionsJson = JsonSerializer.Serialize(value); } } + + public CustomEndpoint(string name, string description, string url, string method, string dataSourceCode, string sql, string parametersJson, string permissionsJson) + { + Name = name; + Description = description; + Url = url; + Method = method; + DataSourceCode = dataSourceCode; + Sql = sql; + ParametersJson = parametersJson; + PermissionsJson = permissionsJson; + } } public class CustomEndpointParameter