< 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: 98
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 LGDXRobotCloud.Utilities.Constants;
 8using Microsoft.AspNetCore.Authentication.JwtBearer;
 9using Microsoft.AspNetCore.Authorization;
 10using Microsoft.AspNetCore.Mvc;
 11using Microsoft.Extensions.Options;
 12using System.Text.Json;
 13
 14namespace LGDXRobotCloud.API.Areas.Automation.Controllers;
 15
 16[ApiController]
 17[Area("Automation")]
 18[Route("[area]/[controller]")]
 19[Authorize(AuthenticationSchemes = LgdxRobotCloudAuthenticationSchemes.ApiKeyOrCertificationScheme)]
 20[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
 21[ValidateLgdxUserAccess]
 022public sealed class FlowsController(
 023    IOptionsSnapshot<LgdxRobotCloudConfiguration> lgdxRobotCloudConfiguration,
 024    IFlowService flowService
 025  ) : ControllerBase
 26{
 027  private readonly LgdxRobotCloudConfiguration _lgdxRobotCloudConfiguration = lgdxRobotCloudConfiguration.Value;
 028  private readonly IFlowService _flowService = flowService;
 29
 30  [HttpGet("")]
 31  [ProducesResponseType(typeof(IEnumerable<FlowListDto>), StatusCodes.Status200OK)]
 32  public async Task<ActionResult<IEnumerable<FlowListDto>>> GetFlows(string? name, int pageNumber = 1, int pageSize = 10
 033  {
 034    pageSize = (pageSize > _lgdxRobotCloudConfiguration.ApiMaxPageSize) ? _lgdxRobotCloudConfiguration.ApiMaxPageSize : 
 035    var (flows, PaginationHelper) = await _flowService.GetFlowsAsync(name, pageNumber, pageSize);
 036    Response.Headers.Append("X-Pagination", JsonSerializer.Serialize(PaginationHelper));
 037    return Ok(flows.ToDto());
 038  }
 39
 40  [HttpGet("Search")]
 41  [ProducesResponseType(typeof(IEnumerable<FlowSearchDto>), StatusCodes.Status200OK)]
 42  public async Task<ActionResult<IEnumerable<FlowSearchDto>>> SearchFlows(string? name)
 043  {
 044    var flows = await _flowService.SearchFlowsAsync(name);
 045    return Ok(flows.ToDto());
 046  }
 47
 48  [HttpGet("{id}", Name = "GetFlow")]
 49  [ProducesResponseType(typeof(FlowDto), StatusCodes.Status200OK)]
 50  [ProducesResponseType(StatusCodes.Status404NotFound)]
 51  public async Task<ActionResult<FlowDto>> GetFlow(int id)
 052  {
 053    var flow = await _flowService.GetFlowAsync(id);
 054    return Ok(flow.ToDto());
 055  }
 56
 57  [HttpPost("")]
 58  [ProducesResponseType(typeof(FlowDto), StatusCodes.Status201Created)]
 59  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 60  public async Task<ActionResult> CreateFlow(FlowCreateDto flowCreateDto)
 061  {
 062    var flow = await _flowService.CreateFlowAsync(flowCreateDto.ToBusinessModel());
 063    return CreatedAtAction(nameof(GetFlow), new { id = flow.Id }, flow.ToDto());
 064  }
 65
 66  [HttpPut("{id}")]
 67  [ProducesResponseType(StatusCodes.Status204NoContent)]
 68  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 69  [ProducesResponseType(StatusCodes.Status404NotFound)]
 70  public async Task<ActionResult> UpdateFlow(int id, FlowUpdateDto flowUpdateDto)
 071  {
 072    await _flowService.UpdateFlowAsync(id, flowUpdateDto.ToBusinessModel());
 073    return NoContent();
 074  }
 75
 76  [HttpPost("{id}/TestDelete")]
 77  [ProducesResponseType(StatusCodes.Status200OK)]
 78  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 79  public async Task<ActionResult> TestDeleteFlow(int id)
 080  {
 081    await _flowService.TestDeleteFlowAsync(id);
 082    return Ok();
 083  }
 84
 85  [HttpDelete("{id}")]
 86  [ProducesResponseType(StatusCodes.Status204NoContent)]
 87  [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
 88  [ProducesResponseType(StatusCodes.Status404NotFound)]
 89  public async Task<ActionResult> DeleteFlow(int id)
 090  {
 091    await _flowService.TestDeleteFlowAsync(id);
 092    if(!await _flowService.DeleteFlowAsync(id))
 093    {
 094      return NotFound();
 95    }
 096    return NoContent();
 097  }
 98}