<commit_before>﻿using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SFA.DAS.CommitmentsV2.Api.Authorization;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Queries.GetAccountLegalEntity;

namespace SFA.DAS.CommitmentsV2.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AccountLegalEntityController : ControllerBase
    {
        private readonly ILogger<AccountLegalEntityController> _logger;
        private readonly IMediator _mediator;

        public AccountLegalEntityController(
            ILogger<AccountLegalEntityController> logger, 
            IMediator mediator)
        {
            _logger = logger;
            _mediator = mediator;
        }

        [Authorize]
        [HttpGet]
        [Route("{AccountLegalEntityId}")]
        public async Task<IActionResult> GetAccountLegalEntity(long accountLegalEntityId)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var employer = await _mediator.Send(new GetAccountLegalEntityRequest
            {
                AccountLegalEntityId = accountLegalEntityId
            });

            if (employer == null)
            {
                return NotFound();
            }

            return Ok(new AccountLegalEntity
            {
                AccountName = employer.AccountName,
                LegalEntityName = employer.LegalEntityName
            });
        }
    }
}
<commit_msg>Create errorresponse from ModelState<commit_after>﻿using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SFA.DAS.CommitmentsV2.Api.Authorization;
using SFA.DAS.CommitmentsV2.Api.Extensions;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Queries.GetAccountLegalEntity;

namespace SFA.DAS.CommitmentsV2.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AccountLegalEntityController : ControllerBase
    {
        private readonly ILogger<AccountLegalEntityController> _logger;
        private readonly IMediator _mediator;

        public AccountLegalEntityController(
            ILogger<AccountLegalEntityController> logger, 
            IMediator mediator)
        {
            _logger = logger;
            _mediator = mediator;
        }

        [Authorize]
        [HttpGet]
        [Route("{AccountLegalEntityId}")]
        public async Task<IActionResult> GetAccountLegalEntity(long accountLegalEntityId)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState.CreateErrorResponse());
            }

            var employer = await _mediator.Send(new GetAccountLegalEntityRequest
            {
                AccountLegalEntityId = accountLegalEntityId
            });

            if (employer == null)
            {
                return NotFound();
            }

            return Ok(new AccountLegalEntity
            {
                AccountName = employer.AccountName,
                LegalEntityName = employer.LegalEntityName
            });
        }
    }
}

{'fraction_non_alphanumeric': 0.07583508877520313, 'fraction_numerical': 0.002708396027685826, 'mean_word_length': 2.199230028873917, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987142', 'n_tokens_mistral': 891, 'n_tokens_neox': 865, 'n_words': 151}