<commit_before>package dao

import extensions.BSONFormatsBM._
import models.User
import models.UserFormats._
import play.api.Play.current
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json.Json
import play.modules.reactivemongo.ReactiveMongoPlugin
import reactivemongo.api.indexes.IndexType.Ascending
import reactivemongo.api.indexes.{Index, IndexType}
import reactivemongo.bson.BSONObjectID
import reactivemongo.extensions.json.dao.JsonDao

object UserDao extends JsonDao[User, BSONObjectID](ReactiveMongoPlugin.db, "users") {

  /**
   * Lists users.
   * Fetchs from database
   *
   * @return [[scala.concurrent.Future]] as a [[List]]
   */
  def listUsers = UserDao.findAll()

  /**
   * Finds user for E-Mail.
   *
   * @param email E-Mail attribute for for the [[User]] object.
   * @return [[scala.concurrent.Future]] as a [[Option]]
   */
  def findByEMail(email: String) = {
    UserDao.findOne(Json.obj("email" -> email))
  }

  /**
   * Create user.
   * Insert a [[User]] object.
   *
   * @param user Inserted [[User]] object.
   * @return [[scala.concurrent.Future]] as a [[reactivemongo.core.commands.LastError]]
   */
  def createUser(user: User) = {
    UserDao.insert(user)
  }

  /**
   * Delete the [[User]] object from the database according to id.
   * @param id [[reactivemongo.bson.BSONObjectID]] for the [[User]] object.
   * @return [[scala.concurrent.Future]] as a [[reactivemongo.core.commands.LastError]]
   */
  def deleteUser(id: BSONObjectID) = {
    UserDao.removeById(id)
  }

  /**
   * Drops the collection!
   * @return
   */
  def clean = {
    dropSync()
  }

  override def autoIndexes = Seq(
    Index(Seq("_id" -> Ascending, "email" -> Ascending)),
    Index(Seq("email" -> IndexType.Ascending), unique = true))

}<commit_msg>Fixed #12 User's PushToken is unique in database<commit_after>package dao

import extensions.BSONFormatsBM._
import models.User
import models.UserFormats._
import play.api.Play.current
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json.Json
import play.modules.reactivemongo.ReactiveMongoPlugin
import reactivemongo.api.indexes.IndexType.Ascending
import reactivemongo.api.indexes.{Index, IndexType}
import reactivemongo.bson.BSONObjectID
import reactivemongo.extensions.json.dao.JsonDao

object UserDao extends JsonDao[User, BSONObjectID](ReactiveMongoPlugin.db, "users") {

  /**
   * Lists users.
   * Fetchs from database
   *
   * @return [[scala.concurrent.Future]] as a [[List]]
   */
  def listUsers = UserDao.findAll()

  /**
   * Finds user for E-Mail.
   *
   * @param email E-Mail attribute for for the [[User]] object.
   * @return [[scala.concurrent.Future]] as a [[Option]]
   */
  def findByEMail(email: String) = {
    UserDao.findOne(Json.obj("email" -> email))
  }

  /**
   * Create user.
   * Insert a [[User]] object.
   *
   * @param user Inserted [[User]] object.
   * @return [[scala.concurrent.Future]] as a [[reactivemongo.core.commands.LastError]]
   */
  def createUser(user: User) = {
    UserDao.insert(user)
  }

  /**
   * Delete the [[User]] object from the database according to id.
   * @param id [[reactivemongo.bson.BSONObjectID]] for the [[User]] object.
   * @return [[scala.concurrent.Future]] as a [[reactivemongo.core.commands.LastError]]
   */
  def deleteUser(id: BSONObjectID) = {
    UserDao.removeById(id)
  }

  /**
   * Drops the collection!
   * @return
   */
  def clean = {
    dropSync()
  }

  override def autoIndexes = Seq(
    Index(Seq("_id" -> Ascending, "email" -> Ascending)),
    Index(Seq("email" -> IndexType.Ascending), unique = true),
    Index(Seq("pushToken" -> IndexType.Ascending), unique = true, sparse = true))

}
{'fraction_non_alphanumeric': 0.1412142284033164, 'fraction_numerical': 0.0005349023803155924, 'mean_word_length': 3.622991347342398, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1163686', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1237, 'n_words': 277}