* Changed views to have them in the same layout
* Added Authorization
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Diagnostics;
|
||||
using FaKrosnoApi.Models;
|
||||
using Hangfire;
|
||||
using Hangfire.Storage;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OrdersManagementDataModel.Dtos;
|
||||
using OrdersManagementDataModel.Services;
|
||||
@@ -10,7 +11,10 @@ namespace FaKrosnoApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager recurringJobManager, ITaskSchedulerService service) : Controller
|
||||
public class HangfireJobsController(
|
||||
JobStorage jobStorage,
|
||||
IRecurringJobManager recurringJobManager,
|
||||
ITaskSchedulerService service) : Controller
|
||||
{
|
||||
[HttpGet("GetJobsToRun")]
|
||||
public async Task<ActionResult<IEnumerable<JobModel>>> GetJobsToRun()
|
||||
@@ -25,7 +29,7 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
foreach (var recurringJob in recurringJobs)
|
||||
{
|
||||
TaskSchedulerDto? taskScheduler = taskSchedulers?.FirstOrDefault(ts => ts.Name == recurringJob.Id);
|
||||
|
||||
|
||||
if (taskScheduler != null)
|
||||
{
|
||||
jobsToRun.Add(new JobModel(recurringJob.Id, recurringJob.Cron, taskScheduler.Path,
|
||||
@@ -36,8 +40,8 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
|
||||
return Ok(jobsToRun);
|
||||
}
|
||||
|
||||
[HttpPost("RunJobs")]
|
||||
|
||||
[HttpPost("run")]
|
||||
public async Task<IActionResult> RunJobs()
|
||||
{
|
||||
var jobsToRun = (await GetJobsToRun()).Value?.ToList();
|
||||
@@ -58,8 +62,8 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
|
||||
return Ok("Zadania zostały zaplanowane do uruchamiania zgodnie z ich CRON.");
|
||||
}
|
||||
|
||||
[HttpPost("AddTask")]
|
||||
|
||||
[HttpPost("add")]
|
||||
public async Task<IActionResult> AddTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
{
|
||||
var taskScheduler = new OrdersManagementDataModel.Entities.TaskScheduler
|
||||
@@ -83,9 +87,11 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
return Ok("Zadanie zostało dodane.");
|
||||
}
|
||||
|
||||
[HttpPost("DeleteTask")]
|
||||
[HttpPost("delete")]
|
||||
public async Task<IActionResult> DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto)
|
||||
{
|
||||
var taskSchedulerByTaskName = await service.GetTaskSchedulerByTaskName(taskSchedulerDto.Name);
|
||||
Console.WriteLine(taskSchedulerByTaskName.RowPointer);
|
||||
int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer);
|
||||
|
||||
if (result == 0)
|
||||
@@ -98,21 +104,35 @@ public class HangfireJobsController(JobStorage jobStorage, IRecurringJobManager
|
||||
return Ok("Zadanie zostało usunięte.");
|
||||
}
|
||||
|
||||
[HttpGet("GetTasks")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<TaskSchedulerDto>>> GetTasks()
|
||||
{
|
||||
var tasks = await service.GetTaskSchedulers();
|
||||
|
||||
|
||||
foreach (TaskSchedulerDto taskSchedulerDto in tasks)
|
||||
{
|
||||
var job = GetJob(taskSchedulerDto.Name);
|
||||
taskSchedulerDto.LastExecution = job?.LastExecution;
|
||||
taskSchedulerDto.NextExecution = job?.NextExecution;
|
||||
}
|
||||
|
||||
|
||||
return Ok(tasks);
|
||||
}
|
||||
|
||||
[HttpGet("by-name")]
|
||||
public async Task<ActionResult<TaskSchedulerDto>> GetTaskSchedulerByTaskName([FromQuery] string name)
|
||||
{
|
||||
var taskSchedulerDto = await service.GetTaskSchedulerByTaskName(name);
|
||||
|
||||
if (taskSchedulerDto == null) return NotFound();
|
||||
|
||||
var job = GetJob(taskSchedulerDto.Name);
|
||||
taskSchedulerDto.LastExecution = job?.LastExecution;
|
||||
taskSchedulerDto.NextExecution = job?.NextExecution;
|
||||
|
||||
return Ok(taskSchedulerDto);
|
||||
}
|
||||
|
||||
private RecurringJobDto? GetJob(string jobId)
|
||||
{
|
||||
using IStorageConnection? connection = jobStorage.GetConnection();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using FaKrosnoApi.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FaKrosnoApi.Controllers;
|
||||
|
||||
@@ -51,13 +51,11 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
// Konfiguracja NSwag z obsługą Bearer Token
|
||||
builder.Services.AddOpenApiDocument(config =>
|
||||
{
|
||||
config.Title = "FaKrosnoApi";
|
||||
config.Version = "v1";
|
||||
|
||||
// Dodaj definicję zabezpieczeń Bearer Token
|
||||
config.AddSecurity("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "Authorization",
|
||||
@@ -68,23 +66,22 @@ builder.Services.AddOpenApiDocument(config =>
|
||||
Description = "Wprowadź token JWT w formacie: Bearer {token}"
|
||||
});
|
||||
|
||||
// Zastosuj zabezpieczenia globalnie
|
||||
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
|
||||
});
|
||||
|
||||
// builder.Services.AddHangfire(config => config
|
||||
// .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
// .UseSimpleAssemblyNameTypeSerializer()
|
||||
// .UseRecommendedSerializerSettings()
|
||||
// .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
// {
|
||||
// CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
// SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
// QueuePollInterval = TimeSpan.Zero,
|
||||
// UseRecommendedIsolationLevel = true,
|
||||
// DisableGlobalLocks = true
|
||||
// }));
|
||||
// builder.Services.AddHangfireServer();
|
||||
builder.Services.AddHangfire(config => config
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
{
|
||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
QueuePollInterval = TimeSpan.Zero,
|
||||
UseRecommendedIsolationLevel = true,
|
||||
DisableGlobalLocks = true
|
||||
}));
|
||||
builder.Services.AddHangfireServer();
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
||||
typeof(OrdersManagementMappingProfile));
|
||||
@@ -116,6 +113,6 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
// app.UseHangfireDashboard();
|
||||
app.UseHangfireDashboard();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosno;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true",
|
||||
"SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PROD_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true",
|
||||
"FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosnotest;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true",
|
||||
"SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PRODTEST_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true",
|
||||
"OrdersManagementConnection": "Server=192.168.0.7;Database=OrdersManagement;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true"
|
||||
},
|
||||
"Logging": {
|
||||
|
||||
Reference in New Issue
Block a user