Summary

Class:ProjectX.PublicApi.Actions.Confirm.ConfirmController
Assembly:ProjectX.PublicApi
File(s):C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Actions\Confirm\ConfirmController.cs
Covered lines:27
Uncovered lines:0
Coverable lines:27
Total lines:72
Line coverage:100%
Branch coverage:100%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
Post()42100100

File(s)

C:\private\projects\projectx\backend\src\ProjectX.PublicApi\Actions\Confirm\ConfirmController.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using Microsoft.AspNetCore.Mvc;
 4using Microsoft.Extensions.Logging;
 5using ProjectX.Entities;
 6using ProjectX.Exceptions;
 7using ProjectX.PublicApi.Filters;
 8using ProjectX.Services;
 9
 10namespace ProjectX.PublicApi.Actions.Confirm
 11{
 12    [Route("/confirm")]
 13    public class ConfirmController : Controller
 14    {
 15        private readonly ILogger<ConfirmController> _logger;
 16        private readonly AuthService _authService;
 17
 318        public ConfirmController(
 319            ILogger<ConfirmController> logger,
 320            AuthService authService)
 21        {
 322            this._logger = logger;
 323            this._authService = authService;
 324        }
 25
 26        /// <summary>
 27        /// Confirms the signin process, user need to use code from received
 28        /// SMS
 29        /// </summary>
 30        /// <param name="input"></param>
 31        /// <returns></returns>
 32        [HttpPost]
 33        [ValidateModel]
 34        public async Task<IActionResult> Post(
 35            [FromBody]ConfirmInputModel input)
 36        {
 337            this._logger.LogTrace("Start confirm request");
 38
 339             User user = null;
 40
 41            try
 42            {
 343                user = await this._authService
 344                   .ConfirmUserAsync(input.UserId, input.Code);
 145            }
 146            catch (EntityNotFoundException)
 47            {
 148                this._logger.LogTrace(
 149                    $"End signin request. User not found {input.UserId}");
 50
 151                return new BadRequestResult();
 52            }
 153            catch (CodeNotMatchException)
 54            {
 155                this._logger.LogTrace(
 156                    "End signin request. Code does not match");
 57
 158                return new BadRequestResult();
 59            }
 60
 161            var result = new ConfirmModel
 162            {
 163                Hash = user.Hash
 164            };
 65
 166            this._logger.LogTrace(
 167                $"End confirm request. User confirmed {user.Id}");
 68
 169            return new ObjectResult(result);
 370        }
 71    }
 72}