<commit_before>﻿namespace DNG.Web.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;

    using DNG.Data;
    using DNG.Web.Models;

    public class UsersController : BaseApiController
    {
        public UsersController(IDngData data)
            : base(data)
        {
        }

        //[Authorize(Roles="Admin")]
        [HttpGet]
        public IHttpActionResult All()
        {
            var users = this.data
                .Users
                .All()
                .Select(UserViewModel.FromUser);

            return Ok(users);
        }

        [HttpGet]
        [Route("Users/{username}")]
        public IHttpActionResult ByUsername(string username)
        {
            var foundUser = this.GetUserModel(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            return Ok(foundUser);
        }

        [HttpGet]
        [Route("Users/{username}/followers")]
        public IHttpActionResult Followers(string username)
        {
            var foundUser = this.GetUser(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var followers = foundUser.Followers
                .AsQueryable().Select(UserViewModel.FromUser);

            return Ok(followers);
        }

        [HttpGet]
        [Route("Users/{username}/following")]
        public IHttpActionResult Following(string username)
        {
            var foundUser = this.GetUser(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var following = foundUser.Following
                .AsQueryable().Select(UserViewModel.FromUser);

            return Ok(following);
        }

        [HttpGet]
        [Route("Users/{username}/subscriptions")]
        public IHttpActionResult Subscriptions(string username)
        {
            var foundUser = this.GetUser(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var subscriptions = foundUser.Subsciptions
                .AsQueryable().Select(CategoryViewModel.FromCategory);

            return Ok(subscriptions);
        }
    }
}
<commit_msg>User controllers for follow and unfollow<commit_after>﻿namespace DNG.Web.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;

    using DNG.Data;
    using DNG.Web.Models;

    public class UsersController : BaseApiController
    {
        public UsersController(IDngData data)
            : base(data)
        {
        }

        //[Authorize(Roles="Admin")]
        [HttpGet]
        public IHttpActionResult All()
        {
            var users = this.data
                .Users
                .All()
                .Select(UserViewModel.FromUser);

            return Ok(users);
        }

        [HttpGet]
        [Route("Users/{username}")]
        public IHttpActionResult ByUsername(string username)
        {
            var foundUser = this.GetUserModel(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            return Ok(foundUser);
        }

        [HttpGet]
        [Route("Users/{username}/followers")]
        public IHttpActionResult Followers(string username)
        {
            var foundUser = this.GetUser(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var followers = foundUser.Followers
                .AsQueryable().Select(UserViewModel.FromUser);

            return Ok(followers);
        }

        [HttpGet]
        [Route("Users/{username}/following")]
        public IHttpActionResult Following(string username)
        {
            var foundUser = this.GetUser(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var following = foundUser.Following
                .AsQueryable().Select(UserViewModel.FromUser);

            return Ok(following);
        }

        [HttpGet]
        [Route("Users/{username}/subscriptions")]
        public IHttpActionResult Subscriptions(string username)
        {
            var foundUser = this.GetUser(username);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var subscriptions = foundUser.Subsciptions
                .AsQueryable().Select(CategoryViewModel.FromCategory);

            return Ok(subscriptions);
        }

        [HttpPost]
        [Route("Users/{currentUser}/follow/{userToFollow}")]
        public IHttpActionResult Follow(string currentUser, string userToFollow)
        {
            var foundUser = this.GetUser(currentUser);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var foundUserToFollow = this.GetUser(userToFollow);

            if (foundUserToFollow == null)
            {
                return BadRequest("User to follow does not exist - invalid username.");
            }

            foundUser.Following.Add(foundUserToFollow);
            foundUserToFollow.Followers.Add(foundUser);

            return Ok();
        }

        [HttpPut]
        [Route("Users/{currentUser}/unfollow/{userToUnFollow}")]
        public IHttpActionResult UnFollow(string currentUser, string userToUnFollow)
        {
            var foundUser = this.GetUser(currentUser);

            if (foundUser == null)
            {
                return BadRequest("User does not exist - invalid username.");
            }

            var foundUserToUnFollow = this.GetUser(userToUnFollow);

            if (foundUserToUnFollow == null)
            {
                return BadRequest("User to follow does not exist - invalid username.");
            }

            foundUser.Following.Remove(foundUserToUnFollow);
            foundUserToUnFollow.Followers.Remove(foundUser);

            return Ok();
        }
    }
}

{'fraction_non_alphanumeric': 0.09400421813799337, 'fraction_numerical': 0.0, 'mean_word_length': 1.6241106719367588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '135216', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1595, 'n_words': 355}