<commit_before>﻿using CQRSExample.Model.MaterialNumber;
using CQRSExample.Model.Plant;
using CQRSExample.Model.WorkCenter;
using CQRSExample.WebAPI.Models.MaterialNumber;
using CQRSExample.WebAPI.Models.Plant;
using CQRSExample.WebAPI.Models.WorkCenter;
using MediatR;
using Swashbuckle.Swagger.Annotations;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CQRSExample.WebAPI.Controllers
{
    [RoutePrefix("plants")]
    public class PlantsController : BaseWebApiController
    {
        public PlantsController(IMediator mediator) : base(mediator)
        {
        }

        [Route("")]
        [HttpGet]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(IEnumerable<PlantDetails>), Description = "Query completed")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public IHttpActionResult QueryPlants()
        {
            throw new NotImplementedException();
        }

        [Route("")]
        [HttpPost]
        [SwaggerResponse(HttpStatusCode.Created, Type = typeof(PlantDetails), Description = "New entry created")]
        [SwaggerResponse(HttpStatusCode.BadRequest, Description = "Wrong format/content of request body")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public IHttpActionResult Create([FromBody]PlantFormModel model)
        {
            throw new NotImplementedException();
        }

        [HttpGet]
        [Route("{id}")]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(PlantDetails), Description = "Entry found")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public IHttpActionResult GetPlant(string id)
        {
            throw new NotImplementedException();
        }

        [HttpDelete]
        [Route("{id}")]
        [SwaggerResponse(HttpStatusCode.NoContent, Description = "Entry deleted")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public HttpResponseMessage Delete(string id)
        {
            throw new NotImplementedException();
        }

        [HttpPut]
        [Route("{id}")]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(PlantDetails), Description = "Entry updated")]
        [SwaggerResponse(HttpStatusCode.BadRequest, Description = "Wrong format/content of request body")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public IHttpActionResult UpdatePlant(string id, [FromBody]PlantFormModel model)
        {
            throw new NotImplementedException();
        }

        [HttpGet]
        [Route("{plantId}/work-centers")]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(IEnumerable<WorkCenterDetails>), Description = "Query completed")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public IHttpActionResult QueryPlantWorkCenters(string plantId)
        {
            throw new NotImplementedException();
        }

        [HttpPost]
        [Route("{plantId}/work-centers")]
        [SwaggerResponse(HttpStatusCode.Created, Type = typeof(WorkCenterDetails), Description = "Entry created")]
        [SwaggerResponse(HttpStatusCode.BadRequest, Description = "Wrong format/content of request body")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]<commit_msg>feature(webapi/plants): added implementations  for plant model CRUD operations<commit_after>﻿using CQRSExample.Model.MaterialNumber;
using CQRSExample.Model.Plant;
using CQRSExample.Model.WorkCenter;
using CQRSExample.WebAPI.Models.MaterialNumber;
using CQRSExample.WebAPI.Models.Plant;
using CQRSExample.WebAPI.Models.WorkCenter;
using MediatR;
using Swashbuckle.Swagger.Annotations;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

namespace CQRSExample.WebAPI.Controllers
{
    [RoutePrefix("plants")]
    public class PlantsController : BaseWebApiController
    {
        public PlantsController(IMediator mediator) : base(mediator)
        {
        }

        [Route("")]
        [HttpGet]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(IEnumerable<PlantDetails>), Description = "Query completed")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public async Task<IHttpActionResult> QueryPlants()
        {
            var result = await _mediator.Send(new Domain.Plants.List.Query());
            return Ok(result);
        }

        [Route("")]
        [HttpPost]
        [SwaggerResponse(HttpStatusCode.Created, Type = typeof(PlantDetails), Description = "New entry created")]
        [SwaggerResponse(HttpStatusCode.BadRequest, Description = "Wrong format/content of request body")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public async Task<IHttpActionResult> Create([FromBody]PlantFormModel model)
        {
            if (!ModelState.IsValid) return BadRequest(ModelState);
            await _mediator.Send(new Domain.Plants.Create.Command(model));
            var result = await _mediator.Send(new Domain.Plants.Details.Query(model.Id));
            return Created(new Uri(Request.RequestUri, model.Id), result);
        }

        [HttpGet]
        [Route("{id}")]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(PlantDetails), Description = "Entry found")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public async Task<IHttpActionResult> GetPlant(string id)
        {
            var result = await _mediator.Send(new Domain.Plants.Details.Query(id));
            return Ok(result);
        }

        [HttpDelete]
        [Route("{id}")]
        [SwaggerResponse(HttpStatusCode.NoContent, Description = "Entry deleted")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public async Task<HttpResponseMessage> Delete(string id)
        {
            await _mediator.Send(new Domain.Plants.Delete.Command(id));
            return Request.CreateResponse(HttpStatusCode.NoContent);
        }

        [HttpPut]
        [Route("{id}")]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(PlantDetails), Description = "Entry updated")]
        [SwaggerResponse(HttpStatusCode.BadRequest, Description = "Wrong format/content of request body")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public async Task<IHttpActionResult> UpdatePlant(string id, [FromBody]PlantFormModel model)
        {
            if (!ModelState.IsValid) return BadRequest(ModelState);
            await _mediator.Send(new Domain.Plants.Update.Command(id, model));
            var result = await _mediator.Send(new Domain.Plants.Details.Query(model.Id));
            return Ok(result);
        }

        [HttpGet]
        [Route("{plantId}/work-centers")]
        [SwaggerResponse(HttpStatusCode.OK, Type = typeof(IEnumerable<WorkCenterDetails>), Description = "Query completed")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
        public IHttpActionResult QueryPlantWorkCenters(string plantId)
        {
            throw new NotImplementedException();
        }

        [HttpPost]
        [Route("{plantId}/work-centers")]
        [SwaggerResponse(HttpStatusCode.Created, Type = typeof(WorkCenterDetails), Description = "Entry created")]
        [SwaggerResponse(HttpStatusCode.BadRequest, Description = "Wrong format/content of request body")]
        [SwaggerResponse(HttpStatusCode.NotFound, Description = "No matching entry for the given Id")]
        [SwaggerResponse(HttpStatusCode.InternalServerError)]
{'fraction_non_alphanumeric': 0.10157721280602637, 'fraction_numerical': 0.0, 'mean_word_length': 3.469752761704366, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '928875', 'n_tokens_mistral': 2222, 'n_tokens_neox': 2238, 'n_words': 465}