using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Domain.Workflows;
using Managing.Domain.Workflows.Synthetics;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Managing.Api.Controllers
{
///
/// Controller for managing workflows, including creating, retrieving, and deleting workflows.
/// Requires authorization for access.
///
[Authorize]
public class WorkflowController : BaseController
{
private readonly IWorkflowService _workflowService;
///
/// Initializes a new instance of the class.
///
/// Service for managing workflows.
/// Service for user-related operations.
public WorkflowController(IWorkflowService WorkflowService, IUserService userService) : base(userService)
{
_workflowService = WorkflowService;
}
///
/// Creates a new workflow or updates an existing one based on the provided workflow request.
///
/// The workflow request containing the details of the workflow to be created or updated.
/// The created or updated workflow.
[HttpPost]
public async Task> PostWorkflow([ModelBinder]SyntheticWorkflow workflowRequest)
{
return Ok(await _workflowService.InsertOrUpdateWorkflow(workflowRequest));
}
///
/// Retrieves all workflows.
///
/// A list of all workflows.
[HttpGet]
public ActionResult> GetWorkflows()
{
return Ok(_workflowService.GetWorkflows());
}
///
/// Retrieves all available flows.
///
/// A list of all available flows.
[HttpGet]
[Route("flows")]
public async Task>> GetAvailableFlows()
{
return Ok(await _workflowService.GetAvailableFlows());
}
///
/// Deletes a workflow by name.
///
/// The name of the workflow to delete.
/// An ActionResult indicating the outcome of the operation.
[HttpDelete]
public ActionResult DeleteWorkflow(string name)
{
return Ok(_workflowService.DeleteWorkflow(name));
}
}
}