< Summary

Information
Class: LGDXRobotCloud.API.Areas.Automation.Controllers.FlowsController
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Automation/Controllers/FlowsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 39
Coverable lines: 39
Total lines: 96
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetFlows()0%620%
SearchFlows()100%210%
GetFlow()100%210%
CreateFlow()100%210%
UpdateFlow()100%210%
TestDeleteFlow()100%210%
DeleteFlow()0%620%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Areas/Automation/Controllers/FlowsController.cs

#LineLine coverage
 1using LGDXRobotCloud.API.Authorisation;
 2using LGDXRobotCloud.API.Configurations;
 3using LGDXRobotCloud.API.Services.Automation;
 4using LGDXRobotCloud.Data.Models.Business.Automation;
 5using LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 6using LGDXRobotCloud.Data.Models.DTOs.V1.Responses;
 7using Microsoft.AspNetCore.Authentication.JwtBearer;
 8using Microsoft.AspNetCore.Authorization;
 9using Microsoft.AspNetCore.Mvc;
 10using Microsoft.Extensions.Options;
 11using System.Text.Json;
 12
 13namespace LGDXRobotCloud.API.Areas.Automation.Controllers;
 14
 15[ApiController]
 16[Area("Automation")]
 17[Route("[area]/[controller]")]
 18[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 19[ValidateLgdxUserAccess]
 020public sealed class FlowsController(
 021    IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration,
 022    IFlowService flowService
 023  ) : ControllerBase
 24{
 025  private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value;
 026  private readonly IFlowService _flowService = flowService;
 27
 28  [HttpGet("")]
 29  [ProducesResponseType(typeof(IEnumerable<FlowListDto>), StatusCodes.Status200OK)]
 30  public async Task<ActionResult<IEnumerable<FlowListDto>>> GetFlows(string? name, int pageNumber = 1, int pageSize = 10
 031  {
 032    pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : 
 033    var (flows, PaginationHelper) = await _flowService.GetFlowsAsync(name, pageNumber, pageSize);
 034    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper));
 035    return Ok(flows.ToDto());
 036  }
 37
 38  [HttpGet("Search")]
 39  [ProducesResponseType(typeof(IEnumerable<FlowSearchDto>), StatusCodes.Status200OK)]
 40  public async Task<ActionResult<IEnumerable<FlowSearchDto>>> SearchFlows(string? name)
 041  {
 042    var flows = await _flowService.SearchFlowsAsync(name);
 043    return Ok(flows.ToDto());
 044  }
 45
 46  [HttpGet("{id}", Name = "GetFlow")]
 47  [ProducesResponseType(typeof(FlowDto), StatusCodes.Status200OK)]
 48  [ProducesResponseType(StatusCodes.Status404NotFound)]
 49  public async Task<ActionResult<FlowDto>> GetFlow(int id)
 050  {
 051    var flow = await _flowService.GetFlowAsync(id);
 052    return Ok(flow.ToDto());
 053  }
 54
 55  [HttpPost("")]
 56  [ProducesResponseType(typeof(FlowDto), StatusCodes.Status201Created)]
 57  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 58  public async Task<ActionResult> CreateFlow(FlowCreateDto flowCreateDto)
 059  {
 060    var flow = await _flowService.CreateFlowAsync(flowCreateDto.ToBusinessModel());
 061    return CreatedAtAction(nameof(GetFlow), new { id = flow.Id }, flow.ToDto());
 062  }
 63
 64  [HttpPut("{id}")]
 65  [ProducesResponseType(StatusCodes.Status204NoContent)]
 66  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 67  [ProducesResponseType(StatusCodes.Status404NotFound)]
 68  public async Task<ActionResult> UpdateFlow(int id, FlowUpdateDto flowUpdateDto)
 069  {
 070    await _flowService.UpdateFlowAsync(id, flowUpdateDto.ToBusinessModel());
 071    return NoContent();
 072  }
 73
 74  [HttpPost("{id}/TestDelete")]
 75  [ProducesResponseType(StatusCodes.Status200OK)]
 76  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 77  public async Task<ActionResult> TestDeleteFlow(int id)
 078  {
 079    await _flowService.TestDeleteFlowAsync(id);
 080    return Ok();
 081  }
 82
 83  [HttpDelete("{id}")]
 84  [ProducesResponseType(StatusCodes.Status204NoContent)]
 85  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 86  [ProducesResponseType(StatusCodes.Status404NotFound)]
 87  public async Task<ActionResult> DeleteFlow(int id)
 088  {
 089    await _flowService.TestDeleteFlowAsync(id);
 090    if(!await _flowService.DeleteFlowAsync(id))
 091    {
 092      return NotFound();
 93    }
 094    return NoContent();
 095  }
 96}