<commit_before>﻿using System.Web.Http;
using Kheper.Core.Model;
using Kheper.Core.Store;

namespace Kheper.Web.Controllers
{
    [RoutePrefix("api/planningrooms")]
    public class PlanningRoomController : ApiController
    {
        private readonly IPlanningRoomRepository _planningRoomRepository;

        private readonly IVotingSessionRepository _votingSessionRepository;

        private readonly IVoteRepository _voteRepository;

        public PlanningRoomController(IPlanningRoomRepository planningRoomRepository,
            IVotingSessionRepository votingSessionRepository,
            IVoteRepository voteRepository)
        {
            this._planningRoomRepository = planningRoomRepository;
            this._voteRepository = voteRepository;
            this._votingSessionRepository = votingSessionRepository;
        }

        [HttpGet]
        [Route("{roomId}")]
        public PlanningRoom Get(long roomId)
        {
            return this._planningRoomRepository.Query(roomId);
        }

        [HttpPost]
        [Route("{roomId}/join")]
        public PlanningRoom JoinExistingRoom(long roomId, JoinExistingRoomAction parameters)
        {
            var room = this._planningRoomRepository.Query(roomId);
            room.Users.Add(parameters.UserName);
            this._planningRoomRepository.Save(room);
            return room;
        }

        /// <summary>
        /// This WEB Method creates new planning room.
        /// </summary>
        /// <returns>Instance of <see cref="PlanningRoom"/></returns>
        [HttpPost]
        [Route("")]
        public PlanningRoom CreateNewRoom(CreateNewRoomAction parameters)
        {
            var room = new PlanningRoom();
            room.Users.Add(parameters.UserName);
            room = this._planningRoomRepository.Save(room);
            return room;
        }

        [HttpPost]
        [Route("{roomId}")]
        public VotingSession StartNewSession(long roomId, StartNewSessionAction parameters)
        {
            var session = new VotingSession { RoomId = roomId };
            session = this._votingSessionRepository.Save(session);
            return session;
        }

        [HttpPost]
        [Route("{roomId}/votingSessions/{sessionId}")]
        public Vote CastVote(long roomId, long sessoinId, CastVoteAction parameters)
        {
            var vote = new Vote
            {
                PlanningRoomId = roomId,
                VotingSessionId = sessoinId,
                UserName = parameters.UserName,
                Value = parameters.Value
            };
            vote = _voteRepository.Save(vote);
            return vote;
        }

        #region DTO

        public class CreateNewRoomAction
        {
            public string UserName { get; set; }
        }

        public class JoinExistingRoomAction
        {
            public string UserName { get; set; }
        }

        public class StartNewSessionAction
        {
        }

        public class CastVoteAction<commit_msg>Fix routes<commit_after>﻿using System.Web.Http;
using Kheper.Core.Model;
using Kheper.Core.Store;

namespace Kheper.Web.Controllers
{
    [RoutePrefix("api/planningrooms")]
    public class PlanningRoomController : ApiController
    {
        private readonly IPlanningRoomRepository _planningRoomRepository;

        private readonly IVotingSessionRepository _votingSessionRepository;

        private readonly IVoteRepository _voteRepository;

        public PlanningRoomController(IPlanningRoomRepository planningRoomRepository,
            IVotingSessionRepository votingSessionRepository,
            IVoteRepository voteRepository)
        {
            this._planningRoomRepository = planningRoomRepository;
            this._voteRepository = voteRepository;
            this._votingSessionRepository = votingSessionRepository;
        }

        [HttpGet]
        [Route("{roomId}")]
        public PlanningRoom Get(long roomId)
        {
            return this._planningRoomRepository.Query(roomId);
        }

        [HttpPost]
        [Route("{roomId}/join")]
        public PlanningRoom JoinExistingRoom(long roomId, JoinExistingRoomAction parameters)
        {
            var room = this._planningRoomRepository.Query(roomId);
            room.Users.Add(parameters.UserName);
            this._planningRoomRepository.Save(room);
            return room;
        }

        /// <summary>
        /// This WEB Method creates new planning room.
        /// </summary>
        /// <returns>Instance of <see cref="PlanningRoom"/></returns>
        [HttpPost]
        [Route("")]
        public PlanningRoom CreateNewRoom(CreateNewRoomAction parameters)
        {
            var room = new PlanningRoom();
            room.Users.Add(parameters.UserName);
            room = this._planningRoomRepository.Save(room);
            return room;
        }

        [HttpPost]
        [Route("{roomId}/votingsessions")]
        public VotingSession StartNewSession(long roomId, StartNewSessionAction parameters)
        {
            var session = new VotingSession { RoomId = roomId };
            session = this._votingSessionRepository.Save(session);
            return session;
        }

        [HttpPost]
        [Route("{roomId}/votingsessions/{sessionId}/votes")]
        public Vote CastVote(long roomId, long sessoinId, CastVoteAction parameters)
        {
            var vote = new Vote
            {
                PlanningRoomId = roomId,
                VotingSessionId = sessoinId,
                UserName = parameters.UserName,
                Value = parameters.Value
            };
            vote = _voteRepository.Save(vote);
            return vote;
        }

        #region DTO

        public class CreateNewRoomAction
        {
            public string UserName { get; set; }
        }

        public class JoinExistingRoomAction
        {
            public string UserName { get; set; }
        }

        public class StartNewSessionAction
        {
        }

        public class CastVoteAction
{'fraction_non_alphanumeric': 0.07796498183019492, 'fraction_numerical': 0.0, 'mean_word_length': 2.0214570858283434, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2271458', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1467, 'n_words': 314}