<commit_before>package ru.org.codingteam.cttalk.controllers.api

import java.util.Date
import javax.inject.Inject

import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.functional.syntax._
import play.api.libs.json._
import play.api.mvc._
import ru.org.codingteam.cttalk.models.{Handle, Message}
import ru.org.codingteam.cttalk.services.{MessagesService, TokensRepository}

import scala.concurrent.Future

/**
 * Created by hgn on 29.10.2015.
 */
class MessageController @Inject()(messagesService: MessagesService, tokensRepository: TokensRepository) extends Controller with JsonRequest with Secure {
  implicit val sendReads = ((JsPath \ "to").read[Handle] and
    (JsPath \ "text").read[String]
    ) tupled

  def send = withAuthCookie("token")(cookie => jsonAsync[(Handle, String)] {
    case (receiver, text) => tokensRepository.get(cookie.value) flatMap {
      case Some(token) => messagesService.send(Message(token.handle, receiver, wasRead = false, new Date, text))
      case None => Future.failed(new RuntimeException)
    } map {_ => Ok}
  })

  def receive = withAuthCookie("token") { cookie => {
    case _ => Future.successful(Ok)
  }
  }<commit_msg>one of the tests was broken in a way it is not supposed to be<commit_after>package ru.org.codingteam.cttalk.controllers.api

import java.util.Date
import javax.inject.Inject

import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.functional.syntax._
import play.api.libs.json._
import play.api.mvc._
import ru.org.codingteam.cttalk.models.Handle._
import ru.org.codingteam.cttalk.models.{Handle, Message}
import ru.org.codingteam.cttalk.services.{MessagesService, TokensRepository}

import scala.concurrent.Future

/**
 * Created by hgn on 29.10.2015.
 */
class MessageController @Inject()(messagesService: MessagesService, tokensRepository: TokensRepository) extends Controller with JsonRequest with Secure {
  implicit val sendReads = ((JsPath \ "to").read[Handle] and
    (JsPath \ "text").read[String]
    ) tupled

  def send = withAuthCookie("token")(cookie => jsonAsync[(Handle, String)] {
    case (receiver, text) => tokensRepository.get(cookie.value) flatMap {
      case Some(token) => messagesService.send(Message(token.handle, receiver, wasRead = false, new Date, text))
      case None => Future.failed(new RuntimeException)
    } map {_ => Ok}
  })

  def receive = withAuthCookie("token") { cookie => {
    case _ => Future.successful(Ok)
  }
  }
{'fraction_non_alphanumeric': 0.12560777957860617, 'fraction_numerical': 0.006482982171799027, 'mean_word_length': 4.523489932885906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3316453', 'n_tokens_mistral': 774, 'n_tokens_neox': 745, 'n_words': 174}