<commit_before>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DDD.Light.Realtor.Models;
using DDD.Light.Repo.Contracts;

namespace DDD.Light.Realtor.Controllers
{
    public class ListingsController : ApiController
    {
        private readonly IRepository<Listing> _listingRepository;

        public ListingsController(IRepository<Listing> listingRepository)
        {
            _listingRepository = listingRepository;
        }

        // GET api/listings
        public IEnumerable<Listing> Get()
        {
            return _listingRepository.GetAll();
        }

        // GET api/listings/ecf4dbf5-b8b2-4529-84bc-4117cf106227
        public Listing Get(Guid id)
        {
            return _listingRepository.GetById(id);
        }

        // POST api/listings
        public HttpResponseMessage Post(Listing listing)
        {
            listing.Id = Guid.NewGuid();

            try
            {
                _listingRepository.Save(listing);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
            return Request.CreateResponse(HttpStatusCode.Created, listing);
        }

        // PUT api/listings/5
        public HttpResponseMessage Put(Listing listing)
        {
            if (listing.Id == null)
                return Request.CreateResponse(HttpStatusCode.BadRequest, "Id is missing. Use POST or provide Id.");
            try
            {
                _listingRepository.Save(listing);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
            return Request.CreateResponse(HttpStatusCode.OK, listing);
        }

        // DELETE api/listings/5
        public HttpResponseMessage Delete(Guid id)
        {
            try
            {
                _listingRepository.Delete(id);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
            return Request.CreateResponse(HttpStatusCode.NoContent);
        }
    }
}
<commit_msg>added patch verb<commit_after>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DDD.Light.Realtor.Models;
using DDD.Light.Repo.Contracts;

namespace DDD.Light.Realtor.Controllers
{
    public class ListingsController : ApiController
    {
        private readonly IRepository<Listing> _listingRepository;

        public ListingsController(IRepository<Listing> listingRepository)
        {
            _listingRepository = listingRepository;
        }

        // GET api/listings
        public IEnumerable<Listing> Get()
        {
            return _listingRepository.GetAll();
        }

        // GET api/listings/ecf4dbf5-b8b2-4529-84bc-4117cf106227
        public Listing Get(Guid id)
        {
            return _listingRepository.GetById(id);
        }

        // POST api/listings
        public HttpResponseMessage Post([FromBody]Listing listing)
        {
            listing.Id = Guid.NewGuid();

            try
            {
                _listingRepository.Save(listing);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
            return Request.CreateResponse(HttpStatusCode.Created, listing);
        }

        // PUT api/listings/ecf4dbf5-b8b2-4529-84bc-4117cf106227
        public HttpResponseMessage Put(Guid id, [FromBody]Listing listing)
        {
            try
            {
                listing.Id = id;
                _listingRepository.Save(listing);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
            return Request.CreateResponse(HttpStatusCode.OK, listing);
        }

        // DELETE api/listings/ecf4dbf5-b8b2-4529-84bc-4117cf106227
        public HttpResponseMessage Delete(Guid id)
        {
            try
            {
                _listingRepository.Delete(id);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
            return Request.CreateResponse(HttpStatusCode.NoContent);
        }

        [AcceptVerbs("PATCH")]
        public HttpResponseMessage Patch(Guid id, [FromBody]string street)
        {
            var listing = _listingRepository.GetById(id);
            try
            {                
                listing.Address.Street = street;
                _listingRepository.Save(listing);
                return Request.CreateResponse(HttpStatusCode.OK, listing);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }            
        }
    }
}

{'fraction_non_alphanumeric': 0.07915208090237262, 'fraction_numerical': 0.015947102294826914, 'mean_word_length': 1.6758584807492196, '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': '4224033', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1300, 'n_words': 234}