<commit_before>﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using System;
using System.Threading.Tasks;
using Web.Controllers;

namespace Web.Features.Api.Documents
{
    [Authorize]
    [Route("api/[controller]")]
    public class DocumentsController : BaseController
    {
        private readonly IMediator _mediator;

        public DocumentsController(IMediator mediator)
        {
            _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
        }

        [HttpGet]
        public async Task<IActionResult> Index(Index.Query query)
        {
            var results = await _mediator.Send(query)
                .ConfigureAwait(false);

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

            return Ok(results);
        }

        [HttpGet("{id:int}")]
        public async Task<IActionResult> Details(Details.Query query)
        {
            var result = await _mediator.Send(query).ConfigureAwait(false);

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

            return Ok(result);
        }

        [HttpPost]
        public async Task<IActionResult> Create(Create.Command command)
        {
            var result = await _mediator.Send(command).ConfigureAwait(false);

            return CreatedAtAction(nameof(Documents.Details)
                , new RouteValueDictionary(new Details.Query { Id = result.DocumentId }), null);
        }

        [HttpPut("{id:int}")]
        public async Task<IActionResult> Edit(Edit.Command command)
        {
            var result = await _mediator.Send(command).ConfigureAwait(false);

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

            return await Details(new Details.Query { Id = result.DocumentId })
                .ConfigureAwait(false);
        }

        [HttpGet("{id:int}/thumbnail")]
        public async Task<IActionResult> Thumbnail(Thumbnail.Query query)
        {
            var model = await _mediator.Send(query)
                .ConfigureAwait(false);

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

            return File(model.FileContents, model.ContentType);
        }

        [HttpGet("{id:int}/view")]
        public async Task<IActionResult> View(View.Query query)
        {
            var model = await _mediator.Send(query)
                .ConfigureAwait(false);

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

            return File(model.FileContents, model.ContentType);
        }
    }
}<commit_msg>Created a document returns the document<commit_after>﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using System;
using System.Threading.Tasks;
using Web.Controllers;

namespace Web.Features.Api.Documents
{
    [Authorize]
    [Route("api/[controller]")]
    public class DocumentsController : BaseController
    {
        private readonly IMediator _mediator;

        public DocumentsController(IMediator mediator)
        {
            _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
        }

        [HttpGet]
        public async Task<IActionResult> Index(Index.Query query)
        {
            var results = await _mediator
                .Send(query)
                .ConfigureAwait(false);

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

            return Ok(results);
        }

        [HttpGet("{id:int}")]
        public async Task<IActionResult> Details(Details.Query query)
        {
            var result = await _mediator
                .Send(query)
                .ConfigureAwait(false);

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

            return Ok(result);
        }

        [HttpPost]
        public async Task<IActionResult> Create(Create.Command command)
        {
            var result = await _mediator
                .Send(command)
                .ConfigureAwait(false);

            var document = await _mediator
                .Send(
                    new Details.Query
                    {
                        Id = result.DocumentId
                    }
                )
                .ConfigureAwait(false);

            return CreatedAtAction(
                nameof(Documents.Details)
                , new RouteValueDictionary(
                    new Details.Query
                    {
                        Id = result.DocumentId
                    }
                )
                , document);
        }

        [HttpPut("{id:int}")]
        public async Task<IActionResult> Edit(Edit.Command command)
        {
            var result = await _mediator
                .Send(command)
                .ConfigureAwait(false);

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

            return await Details(
                    new Details.Query
                    {
                        Id = result.DocumentId
                    }
                )
                .ConfigureAwait(false);
        }

        [HttpGet("{id:int}/thumbnail")]
        public async Task<IActionResult> Thumbnail(Thumbnail.Query query)
        {
            var model = await _mediator
                .Send(query)
                .ConfigureAwait(false);

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

            return File(model.FileContents, model.ContentType);
        }

        [HttpGet("{id:int}/view")]
        public async Task<IActionResult> View(View.Query query)
        {
            var model = await _mediator
                .Send(query)
                .ConfigureAwait(false);

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

            return File(model.FileContents, model.ContentType);
        }
    }
}
{'fraction_non_alphanumeric': 0.09026320038753431, 'fraction_numerical': 0.0, 'mean_word_length': 1.42426614481409, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3867001', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1518, 'n_words': 321}