<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ygo.api.Auth;
using ygo.api.Model;
using ygo.application.Commands.AddArchetype;
using ygo.application.Commands.UpdateArchetypeCards;
using ygo.application.Dto;
using ygo.application.Paging;
using ygo.application.Queries.ArchetypeAutosuggest;
using ygo.application.Queries.ArchetypeById;
using ygo.application.Queries.ArchetypeByName;
using ygo.application.Queries.ArchetypeSearch;

namespace ygo.api.Controllers
{
    [Route("api/[controller]")]
    public class ArchetypesController : Controller
    {
        private const string ArchetypeSearchRouteName = "ArchetypeSearch";
        private readonly IMediator _mediator;

        public ArchetypesController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        ///     Archetype by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id:long}", Name = "ArchetypeById")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        public async Task<IActionResult> GetById(long id)
        {
            var result = await _mediator.Send(new ArchetypeByIdQuery {Id = id});

            if (result != null)
                return Ok(result);

            return NotFound();
        }


        /// <summary>
        ///     Archetype by name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet("named")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        public async Task<IActionResult> GetByName([FromQuery] string name = "")
        {
            var result = await _mediator.Send(new ArchetypeByNameQuery {Name = name});

            if (result != null)
                return Ok(result);

            return NotFound();
        }

        /// <summary>
        ///     Archeytpe autosuggest by name
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpGet("names")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        public async Task<IActionResult> AutoSuggests([FromQuery] string filter = "")
        {
            var result = await _mediator.Send(new ArchetypeAutosuggestQuery {Filter = filter});

            if (result != null)
                return Ok(result);

            return NotFound();
        }


        /// <summary>
        ///     Paginated Archetype list
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet(Name = "ArchetypeSearch")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        [ProducesResponseType((int) HttpStatusCode.BadRequest)]
        public async Task<IActionResult> GetArchetypeSearch([FromQuery] ArchetypeSearchQuery query)
        {
            var result = await _mediator.Send(query);

            if (result.IsSuccessful)
            {
                var searchResults = (PagedList<ArchetypeDto>) result.Data;

                Response.Headers.Add("X-Pagination", searchResults.GetHeader().ToJson());

                if (searchResults.List.Any())
                    return Ok(new
                    {
                        Paging = searchResults.GetHeader(),
                        Links = ArchetypeSearchLinks(searchResults, query.SearchTerm),
                        Items = searchResults.List
                    });

                return NotFound();
            }

            return BadRequest(result.Errors);
        }

        /// <summary>
        ///     Add a new Archetype
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Policy = AuthConfig.SuperAdminsPolicy)]
        [ProducesResponseType((int) HttpStatusCode.Created)]
        [ProducesResponseType((int) HttpStatusCode.Conflict)]
        [ProducesResponseType((int) HttpStatusCode.BadRequest)]
        [ProducesResponseType((int) HttpStatusCode.Unauthorized)]
        public async Task<IActionResult> Post([FromBody] AddArchetypeCommand command)
        {
            var existingArchetype = await _mediator.Send(new ArchetypeByIdQuery {Id = command.ArchetypeNumber});
<commit_msg>Remove paging property from response body.<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ygo.api.Auth;
using ygo.api.Model;
using ygo.application.Commands.AddArchetype;
using ygo.application.Commands.UpdateArchetypeCards;
using ygo.application.Dto;
using ygo.application.Paging;
using ygo.application.Queries.ArchetypeAutosuggest;
using ygo.application.Queries.ArchetypeById;
using ygo.application.Queries.ArchetypeByName;
using ygo.application.Queries.ArchetypeSearch;

namespace ygo.api.Controllers
{
    [Route("api/[controller]")]
    public class ArchetypesController : Controller
    {
        private const string ArchetypeSearchRouteName = "ArchetypeSearch";
        private readonly IMediator _mediator;

        public ArchetypesController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        ///     Archetype by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id:long}", Name = "ArchetypeById")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        public async Task<IActionResult> GetById(long id)
        {
            var result = await _mediator.Send(new ArchetypeByIdQuery {Id = id});

            if (result != null)
                return Ok(result);

            return NotFound();
        }


        /// <summary>
        ///     Archetype by name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet("named")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        public async Task<IActionResult> GetByName([FromQuery] string name = "")
        {
            var result = await _mediator.Send(new ArchetypeByNameQuery {Name = name});

            if (result != null)
                return Ok(result);

            return NotFound();
        }

        /// <summary>
        ///     Archeytpe autosuggest by name
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpGet("names")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        public async Task<IActionResult> AutoSuggests([FromQuery] string filter = "")
        {
            var result = await _mediator.Send(new ArchetypeAutosuggestQuery {Filter = filter});

            if (result != null)
                return Ok(result);

            return NotFound();
        }


        /// <summary>
        ///     Paginated Archetype list
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet(Name = "ArchetypeSearch")]
        [ProducesResponseType((int) HttpStatusCode.OK)]
        [ProducesResponseType((int) HttpStatusCode.NotFound)]
        [ProducesResponseType((int) HttpStatusCode.BadRequest)]
        public async Task<IActionResult> GetArchetypeSearch([FromQuery] ArchetypeSearchQuery query)
        {
            var result = await _mediator.Send(query);

            if (result.IsSuccessful)
            {
                var searchResults = (PagedList<ArchetypeDto>) result.Data;

                Response.Headers.Add("X-Pagination", searchResults.GetHeader().ToJson());

                if (searchResults.List.Any())
                    return Ok(new
                    {
                        Links = ArchetypeSearchLinks(searchResults, query.SearchTerm),
                        Items = searchResults.List
                    });

                return NotFound();
            }

            return BadRequest(result.Errors);
        }

        /// <summary>
        ///     Add a new Archetype
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize(Policy = AuthConfig.SuperAdminsPolicy)]
        [ProducesResponseType((int) HttpStatusCode.Created)]
        [ProducesResponseType((int) HttpStatusCode.Conflict)]
        [ProducesResponseType((int) HttpStatusCode.BadRequest)]
        [ProducesResponseType((int) HttpStatusCode.Unauthorized)]
        public async Task<IActionResult> Post([FromBody] AddArchetypeCommand command)
        {
            var existingArchetype = await _mediator.Send(new ArchetypeByIdQuery {Id = command.ArchetypeNumber});

{'fraction_non_alphanumeric': 0.11795260253219349, 'fraction_numerical': 0.0, 'mean_word_length': 2.1879958606416006, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, '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': '4938188', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2483, 'n_words': 479}