* Changed views to have them in the same layout

* Added Authorization
This commit is contained in:
2025-02-28 13:33:01 +01:00
parent aedb5810c2
commit b8fbb789ad
35 changed files with 1605 additions and 1306 deletions

View File

@@ -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();

View File

@@ -1,4 +1,5 @@
using FaKrosnoApi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace FaKrosnoApi.Controllers;