< Summary

Information
Class: Chronicis.Api.Controllers.ArcsController
Assembly: Chronicis.Api
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Api/Controllers/ArcsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 50
Coverable lines: 50
Total lines: 180
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
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%
GetArc()0%620%
CreateArc()0%7280%
UpdateArc()0%4260%
DeleteArc()0%620%
ActivateArc()0%620%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Api/Controllers/ArcsController.cs

#LineLine coverage
 1using Chronicis.Api.Infrastructure;
 2using Chronicis.Api.Services;
 3using Chronicis.Shared.DTOs;
 4using Chronicis.Shared.Extensions;
 5using Microsoft.AspNetCore.Authorization;
 6using Microsoft.AspNetCore.Mvc;
 7
 8namespace Chronicis.Api.Controllers;
 9
 10/// <summary>
 11/// API endpoints for Arc management.
 12/// </summary>
 13[ApiController]
 14[Route("arcs")]
 15[Authorize]
 16public class ArcsController : ControllerBase
 17{
 18    private readonly IArcService _arcService;
 19    private readonly ICurrentUserService _currentUserService;
 20    private readonly ILogger<ArcsController> _logger;
 21
 022    public ArcsController(
 023        IArcService arcService,
 024        ICurrentUserService currentUserService,
 025        ILogger<ArcsController> logger)
 26    {
 027        _arcService = arcService;
 028        _currentUserService = currentUserService;
 029        _logger = logger;
 030    }
 31
 32    /// <summary>
 33    /// GET /api/arcs/{id} - Get a specific arc.
 34    /// </summary>
 35    [HttpGet("{id:guid}")]
 36    public async Task<ActionResult<ArcDto>> GetArc(Guid id)
 37    {
 038        var user = await _currentUserService.GetRequiredUserAsync();
 039        _logger.LogDebug("Getting arc {ArcId} for user {UserId}", id, user.Id);
 40
 041        var arc = await _arcService.GetArcAsync(id, user.Id);
 42
 043        if (arc == null)
 44        {
 045            return NotFound(new { error = "Arc not found or access denied" });
 46        }
 47
 048        return Ok(arc);
 049    }
 50
 51    /// <summary>
 52    /// POST /api/arcs - Create a new arc.
 53    /// </summary>
 54    [HttpPost]
 55    public async Task<ActionResult<ArcDto>> CreateArc([FromBody] ArcCreateDto dto)
 56    {
 057        var user = await _currentUserService.GetRequiredUserAsync();
 58
 059        if (dto == null || string.IsNullOrWhiteSpace(dto.Name))
 60        {
 061            return BadRequest(new { error = "Name is required" });
 62        }
 63
 064        if (dto.CampaignId == Guid.Empty)
 65        {
 066            return BadRequest(new { error = "CampaignId is required" });
 67        }
 68
 069        _logger.LogDebugSanitized("Creating arc '{Name}' in campaign {CampaignId} for user {UserId}",
 070            dto.Name, dto.CampaignId, user.Id);
 71
 072        var arc = await _arcService.CreateArcAsync(dto, user.Id);
 73
 074        if (arc == null)
 75        {
 076            return StatusCode(403, new { error = "Access denied or failed to create arc" });
 77        }
 78
 079        return CreatedAtAction(nameof(GetArc), new { id = arc.Id }, arc);
 080    }
 81
 82    /// <summary>
 83    /// PUT /api/arcs/{id} - Update an arc.
 84    /// </summary>
 85    [HttpPut("{id:guid}")]
 86    public async Task<ActionResult<ArcDto>> UpdateArc(Guid id, [FromBody] ArcUpdateDto dto)
 87    {
 088        var user = await _currentUserService.GetRequiredUserAsync();
 89
 090        if (dto == null || string.IsNullOrWhiteSpace(dto.Name))
 91        {
 092            return BadRequest(new { error = "Name is required" });
 93        }
 94
 095        _logger.LogDebug("Updating arc {ArcId} for user {UserId}", id, user.Id);
 96
 097        var arc = await _arcService.UpdateArcAsync(id, dto, user.Id);
 98
 099        if (arc == null)
 100        {
 0101            return NotFound(new { error = "Arc not found or access denied" });
 102        }
 103
 0104        return Ok(arc);
 0105    }
 106
 107    /// <summary>
 108    /// DELETE /api/arcs/{id} - Delete an arc (only if empty).
 109    /// </summary>
 110    [HttpDelete("{id:guid}")]
 111    public async Task<IActionResult> DeleteArc(Guid id)
 112    {
 0113        var user = await _currentUserService.GetRequiredUserAsync();
 0114        _logger.LogDebug("Deleting arc {ArcId} for user {UserId}", id, user.Id);
 115
 0116        var success = await _arcService.DeleteArcAsync(id, user.Id);
 117
 0118        if (!success)
 119        {
 0120            return BadRequest(new { error = "Arc not found, access denied, or arc is not empty" });
 121        }
 122
 0123        return NoContent();
 0124    }
 125
 126    /// <summary>
 127    /// POST /api/arcs/{id}/activate - Activate an arc for quick session creation.
 128    /// </summary>
 129    [HttpPost("{id:guid}/activate")]
 130    public async Task<IActionResult> ActivateArc(Guid id)
 131    {
 0132        var user = await _currentUserService.GetRequiredUserAsync();
 0133        _logger.LogDebug("Activating arc {ArcId} for user {UserId}", id, user.Id);
 134
 0135        var success = await _arcService.ActivateArcAsync(id, user.Id);
 136
 0137        if (!success)
 138        {
 0139            return BadRequest(new { error = "Unable to activate arc. Arc not found or you don't have permission." });
 140        }
 141
 0142        return NoContent();
 0143    }
 144}
 145
 146/// <summary>
 147/// Campaign-scoped arc endpoints.
 148/// </summary>
 149[ApiController]
 150[Route("campaigns/{campaignId:guid}/arcs")]
 151[Authorize]
 152public class CampaignArcsController : ControllerBase
 153{
 154    private readonly IArcService _arcService;
 155    private readonly ICurrentUserService _currentUserService;
 156    private readonly ILogger<CampaignArcsController> _logger;
 157
 158    public CampaignArcsController(
 159        IArcService arcService,
 160        ICurrentUserService currentUserService,
 161        ILogger<CampaignArcsController> logger)
 162    {
 163        _arcService = arcService;
 164        _currentUserService = currentUserService;
 165        _logger = logger;
 166    }
 167
 168    /// <summary>
 169    /// GET /api/campaigns/{campaignId}/arcs - Get all arcs for a campaign.
 170    /// </summary>
 171    [HttpGet]
 172    public async Task<ActionResult<List<ArcDto>>> GetArcsByCampaign(Guid campaignId)
 173    {
 174        var user = await _currentUserService.GetRequiredUserAsync();
 175        _logger.LogDebug("Getting arcs for campaign {CampaignId} for user {UserId}", campaignId, user.Id);
 176
 177        var arcs = await _arcService.GetArcsByCampaignAsync(campaignId, user.Id);
 178        return Ok(arcs);
 179    }
 180}