add base team classes

pull/83/head
Thibault Duplessis 2012-12-10 18:07:44 +01:00
parent 00da91f76d
commit 69688fcb8b
11 changed files with 146 additions and 11 deletions

View File

@ -50,6 +50,10 @@ final class CoreEnv private (application: Application, val settings: Settings) {
settings = settings,
mongodb = mongodb.apply _)
lazy val team = new lila.team.TeamEnv(
settings = settings,
mongodb = mongodb.apply _)
lazy val lobby = new lila.lobby.LobbyEnv(
app = app,
settings = settings,

View File

@ -123,6 +123,8 @@ final class Settings(config: Config, val IsDev: Boolean) {
val WikiCollectionPage = getString("wiki.collection.page")
val WikiGitUrl = getString("wiki.git_url")
val TeamCollectionTeam = getString("team.collection.team")
val BookmarkCollectionBookmark = getString("bookmark.collection.bookmark")
val CoreCollectionCache = getString("core.collection.cache")

View File

@ -0,0 +1,12 @@
package lila.core
object Text {
def slugify(input: String) = {
import java.text.Normalizer
val nowhitespace = input.replace(" ", "-")
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
slug.toLowerCase
}
}

View File

@ -26,7 +26,7 @@ final class TopicRepo(
}
def nextSlug(categ: Categ, name: String, it: Int = 1): IO[String] = {
val slug = slugify(name) + (it == 1).fold("", "-" + it)
val slug = core.Text.slugify(name) + (it == 1).fold("", "-" + it)
byTree(categ.slug, slug) flatMap {
_.isDefined.fold(
nextSlug(categ, name, it + 1),
@ -34,14 +34,6 @@ final class TopicRepo(
}
}
def slugify(input: String) = {
import java.text.Normalizer
val nowhitespace = input.replace(" ", "-")
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
slug.toLowerCase
}
val all: IO[List[Topic]] = io {
find(DBObject()).toList
}

View File

@ -0,0 +1,22 @@
package lila
package team
import org.joda.time.{ DateTime, Duration }
import org.scala_tools.time.Imports._
import user.User
case class Member(
id: String,
createdAt: DateTime) {
def is(userId: String): Boolean = id == userId
def is(user: User): Boolean = is(user.id)
}
object Member {
def apply(user: User): Member = apply(user.id)
def apply(user: String): Member = new Member(id = user, createdAt = DateTime.now)
}

View File

@ -0,0 +1,38 @@
package lila
package team
import user.User
import org.joda.time.DateTime
import com.novus.salat.annotations.Key
import java.text.Normalizer
case class Team(
@Key("_id") id: String, // also the url slug
name: String,
location: Option[String],
description: String,
members: List[Member],
nbMembers: Int,
createdAt: DateTime,
createdBy: String) {
def slug = id
}
object Team {
def apply(
name: String,
location: Option[String],
description: String,
createdBy: User): Team = new Team(
id = core.Text.slugify(name),
name = name,
location = location,
description = description,
members = Member(createdBy) :: Nil,
nbMembers = 1,
createdAt = DateTime.now,
createdBy = createdBy.id)
}

View File

@ -0,0 +1,8 @@
package lila
package team
import scalaz.effects._
final class TeamApi(repo: TeamRepo) {
}

View File

@ -0,0 +1,17 @@
package lila
package team
import core.Settings
import com.mongodb.casbah.MongoCollection
final class TeamEnv(
settings: Settings,
mongodb: String MongoCollection) {
import settings._
lazy val repo = new TeamRepo(mongodb(TeamCollectionTeam))
lazy val api = new TeamApi(repo = repo)
}

View File

@ -0,0 +1,41 @@
package lila
package team
import com.novus.salat._
import com.novus.salat.dao._
import com.mongodb.casbah.MongoCollection
import com.mongodb.casbah.query.Imports._
import scalaz.effects._
import org.joda.time.DateTime
import org.scala_tools.time.Imports._
import user.User
final class TeamRepo(collection: MongoCollection)
extends SalatDAO[Team, String](collection) {
def byId(id: String): IO[Option[Team]] = io {
findOneById(id)
}
def byUser(user: User): IO[List[Team]] = io {
find(userQuery(user)).sort(sortQuery).toList
}
def saveIO(team: Team): IO[Unit] = io {
update(
selectId(team.id),
_grater asDBObject team,
upsert = true)
}
def removeIO(team: Team): IO[Unit] = io {
remove(selectId(team.id))
}
def userQuery(user: User) = DBObject("members.id" -> user.id)
def selectId(id: String) = DBObject("_id" -> id)
val sortQuery = DBObject("updatedAt" -> -1)
}

View File

@ -1,8 +1,6 @@
package lila
package tournament
import com.mongodb.casbah.query.Imports._
import user.User
case class Player(

1
todo
View File

@ -46,3 +46,4 @@ add fullscreen mode for spectators and load new games in a loop (based on certai
make chess captcha more usable
tournament 404 page
log off = tournament resign
teams