<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Anabi.Domain.Person.Commands;
using Anabi.Features.Person.Models;
using Anabi.Middleware;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Anabi.Features.Person
{
    [Route("api/[controller]")]
    public class PersonController : Controller
    {
        private readonly IMediator mediator;

        public PersonController(IMediator _mediator)
        {
            mediator = _mediator;
        }
        //// GET: api/<controller>
        //[HttpGet]
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        // GET api/<controller>/5
        //[HttpGet("{id}")]
        //public string Get(int id)
        //{
        //    return "value";
        //}

        // GET: api/identifiers
        /// <summary>
        /// Returns identifiers in the database
        /// </summary>
        /// <remarks>
        /// <para>
        /// Returns identifiers in the database filtered for person type (person or company)
        /// </para>
        /// </remarks>
        /// <response code="200">Array of Identifiers</response>
        /// <response code="400">No identifiers found!</response>
        /// <param name="isForPerson"></param>
        [ProducesResponseType(typeof(List<Models.Identifier>), StatusCodes.Status200OK)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status400BadRequest)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status500InternalServerError)]
        [HttpGet("identifiers")]
        public async Task<IActionResult> GetIdentifiers(bool isForPerson)
        {

            var models = await mediator.Send(new GetIdentifier() { IsForPerson = isForPerson });
            return Ok(models);

        }


        //POST api/<controller>
        /// <summary>
        /// Creates a new defendant
        /// </summary>
        /// <remarks>
        /// <para>
        /// Creates a new defendant by adding a new Person record and a new AssetDefendants record
        /// </para>
        /// </remarks>
        /// <response code="201">Id of the new defendant</response>
        /// <response code="400">Validation errors</response>
        /// <param name="addPerson">Details for new defendant</param>
        [ProducesResponseType(typeof(int), StatusCodes.Status201Created)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status400BadRequest)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status500InternalServerError)]
        [HttpPost("adddefendant")]
        public async Task<IActionResult> AddDefendant([FromBody]AddPerson addPerson)
        {

            var personId = await mediator.Send(addPerson);
            return Created("api/defendant", personId);

        }

        //// PUT api/<controller>/5
        //[HttpPut("{id}")]
        //public void Put(int id, [FromBody]string value)
        //{
        //}<commit_msg>ANABI-117 added validation exception messages<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Anabi.Domain.Person.Commands;
using Anabi.Features.Person.Models;
using Anabi.Middleware;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Anabi.Features.Person
{
    [Route("api/[controller]")]
    public class PersonController : Controller
    {
        private readonly IMediator mediator;

        public PersonController(IMediator _mediator)
        {
            mediator = _mediator;
        }
        //// GET: api/<controller>
        //[HttpGet]
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        // GET api/<controller>/5
        //[HttpGet("{id}")]
        //public string Get(int id)
        //{
        //    return "value";
        //}

        // GET: api/identifiers
        /// <summary>
        /// Returns identifiers in the database
        /// </summary>
        /// <remarks>
        /// <para>
        /// Returns identifiers in the database filtered for person type (person or company)
        /// </para>
        /// </remarks>
        /// <response code="200">Array of Identifiers</response>
        /// <response code="400">No identifiers found!</response>
        /// <param name="isForPerson"></param>
        [ProducesResponseType(typeof(List<Models.Identifier>), StatusCodes.Status200OK)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status400BadRequest)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status500InternalServerError)]
        [HttpGet("identifiers")]
        public async Task<IActionResult> GetIdentifiers(bool isForPerson)
        {

            var models = await mediator.Send(new GetIdentifier() { IsForPerson = isForPerson });
            return Ok(models);

        }


        //POST api/<controller>
        /// <summary>
        /// Creates a new defendant
        /// </summary>
        /// <remarks>
        /// <para>
        /// Creates a new defendant by adding a new Person record and a new AssetDefendants record
        /// 
        /// Validation errors:
        /// 
        ///IDNUMBER_MAX_LENGTH_6;
        ///IDSERIE_MAX_LENGTH_2;
        ///IDENTIFICATION_MAX_LENGTH_20;
        ///PERSONNAME_MAX_LENGTH_200;
        ///FIRSTNAME_MAX_LENGTH_50;
        ///NATIONALITY_MAX_LENGTH_20;
        ///IDENTIFICATION_CANNOT_BE_EMPTY;
        ///PERSONNAME_CANNOT_BE_EMPTY;
        ///PERSONIDENTIFICATION_ALREADY_EXISTS;
        /// </para>
        /// </remarks>
        /// <response code="201">Id of the new defendant</response>
        /// <response code="400">Validation errors</response>
        /// <param name="addPerson">Details for new defendant</param>
        [ProducesResponseType(typeof(int), StatusCodes.Status201Created)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status400BadRequest)]
        [ProducesResponseType(typeof(AnabiExceptionResponse), StatusCodes.Status500InternalServerError)]
        [HttpPost("adddefendant")]
        public async Task<IActionResult> AddDefendant([FromBody]AddPerson addPerson)
        {

            var personId = await mediator.Send(addPerson);
            return Created("api/defendant", personId);

        }

        //// PUT api/<controller>/5
        //[HttpPut("{id}")]
        //public void Put(int id, [FromBody]string value)
        //{
        //}
{'fraction_non_alphanumeric': 0.12835387962291517, 'fraction_numerical': 0.013633067440174038, 'mean_word_length': 2.2932187201528174, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 2, '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': '3617909', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1852, 'n_words': 401}